Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Office plant monitoring

Office plant monitoring

Scheduled Pinned Locked Moved My Project
223 Posts 39 Posters 131.7k Views 42 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LastSamurai
    Hardware Contributor
    wrote on last edited by
    #104

    @mfalkvidd So after running my sensor for 3 days with the "fork" connected I had a pretty big loss of voltage. So (as you suggested) I ran it for ~2 days without the fork connected (just the pro mini + radio) and the loss has gone down to ~0 (it keeps alternating between 2806 and 2799mV).
    So its obviously the fork itself that is the problem. I connected it directly to A0 and A1 and my code is above.
    Any idea where the error might be? I will try some other cables later because thats the only idea I have...

    @LastSamurai said:

    @mfalkvidd That sounds great! Are you using a pro mini too?
    I am using a 3V pro mini with power led and regulator removed and the nrf + sensor (on A0 and A1) connected and in about 1 day it dropped from 2945mV to 2907mV. Its running of of 2aa batteries and its on a breadboard for now (for testing).
    I am using your (slightly modified) code from above. Any idea why my power usage is so much higher?

    Here is my code:

    /*
    Based on https://github.com/mfalkvidd/arduino-plantmoisture
    
    This sketch uses the soilmoisture "forks" only that are found on ebay. They are connected between 2 analog pins where one gets pulled low and the other one measures.
    The pins are switched every time to avoid corrosion. Between readings the sensos sleeps to preserve batterylife.
    
    21.06.2016 V1.0 Base sketch
    */
    
    #include <SPI.h>
    #include <MySensor.h>
    
    #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
    
    #define CHILD_ID_MOISTURE 0
    #define CHILD_ID_BATTERY 1
    #define SLEEP_TIME 1800000 // Sleep time between reads (in milliseconds) - 30 minutes
    #define THRESHOLD 1.1 // Only make a new reading with reverse polarity if the change is larger than 10%.
    #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading
    #define BATTERY_FULL 3143 // 2xAA usually give 3.143V when full
    #define BATTERY_ZERO 1900 // 2.34V limit for 328p at 8MHz. 1.9V, limit for nrf24l01 without step-up. 2.8V limit for Atmega328 with default BOD settings.
    const int SENSOR_ANALOG_PINS[] = {A0, A1}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups.
    
    MySensor gw;
    MyMessage msg(CHILD_ID_MOISTURE, V_HUM);
    MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE);
    long oldvoltage = 0;
    byte direction = 0;
    int oldMoistureLevel = -1;
    
    void setup()
    {
      gw.begin();
    
      gw.sendSketchInfo("Plant moisture w bat", "1.0 21062016");
    
      gw.present(CHILD_ID_MOISTURE, S_HUM);
      delay(250);
      gw.present(CHILD_ID_BATTERY, S_CUSTOM);
    
      Serial.println("Setting up pins...");  
      // init sensor pins
      pinMode(SENSOR_ANALOG_PINS[0], OUTPUT);
      pinMode(SENSOR_ANALOG_PINS[1], OUTPUT);
      digitalWrite(SENSOR_ANALOG_PINS[0], LOW);
      digitalWrite(SENSOR_ANALOG_PINS[1], LOW);
    }
    
    void loop()
    {
      int moistureLevel = readMoisture();
    
      // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors
      // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information
      if (oldMoistureLevel == -1) { // First reading, save current value as old
        oldMoistureLevel = moistureLevel;
      }
      if (moistureLevel > (oldMoistureLevel * THRESHOLD) || moistureLevel < (oldMoistureLevel / THRESHOLD)) {
        // The change was large, so it was probably not caused by the difference in internal pull-ups.
        // Measure again, this time with reversed polarity.
        moistureLevel = readMoisture();
      }
    
      // send value and reset level
      gw.send(msg.set((moistureLevel + oldMoistureLevel) / 2.0 / 10.23, 1));
      oldMoistureLevel = moistureLevel;
    
    
      long voltage = readVcc();
    
      if (oldvoltage != voltage) { // Only send battery information if voltage has changed, to conserve battery.
        gw.send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts. Set wants volts and how many decimals (3 in our case)
        gw.sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO)));
        oldvoltage = voltage;
      }
    
      // sleep to conserve energy
      gw.sleep(SLEEP_TIME);
    }
    
    /*
      Reads the current moisture level from the sensor.
      Alternates the polarity to reduce corrosion
    */
    int readMoisture() {
      pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor by activating the internal pullup
      analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging
      gw.sleep(STABILIZATION_TIME);
    
      int sensorRead = analogRead(SENSOR_ANALOG_PINS[direction]);
      int moistureLevel = (1023 - sensorRead); // take the actual reading
    
      Serial.print("Sensor read: ");
      Serial.println(sensorRead);
      Serial.print("Moisture level: ");  
      Serial.println(moistureLevel);  
    
      // Turn off the sensor to conserve battery and minimize corrosion
      pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT);
      digitalWrite(SENSOR_ANALOG_PINS[direction], LOW);
    
      direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion
      return moistureLevel;
    }
    
    long readVcc() {
      // From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
      // Read 1.1V reference against AVcc
      // set the reference to Vcc and the measurement to the internal 1.1V reference
    #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
      ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
      ADMUX = _BV(MUX5) | _BV(MUX0);
    #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
      ADMUX = _BV(MUX3) | _BV(MUX2);
    #else
      ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    #endif
    
      delay(2); // Wait for Vref to settle
      ADCSRA |= _BV(ADSC); // Start conversion
      while (bit_is_set(ADCSRA, ADSC)); // measuring
    
      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
      uint8_t high = ADCH; // unlocks both
    
      long result = (high << 8) | low;
    
      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
      return result; // Vcc in millivolts
    }
    
    1 Reply Last reply
    0
    • mfalkviddM mfalkvidd

      @Fat-Fly replace

      const int SENSOR_ANALOG_PINS[] = { 0 };
      

      with

      const int SENSOR_ANALOG_PINS[] = { A0 };
      

      Connect like this, except use D8 instead of A1 (the connection displayed is for a newer version of the sketch, which supports alternating polarity)

      Fat FlyF Offline
      Fat FlyF Offline
      Fat Fly
      wrote on last edited by
      #105

      I correct this and try again after work. Yesterday i do not find time.

      @mfalkvidd said:

      @Fat-Fly replace

      const int SENSOR_ANALOG_PINS[] = { 0 };
      

      with

      const int SENSOR_ANALOG_PINS[] = { A0 };
      

      Connect like this, except use D8 instead of A1 (the connection displayed is for a newer version of the sketch, which supports alternating polarity)

      1 Reply Last reply
      0
      • Fat FlyF Offline
        Fat FlyF Offline
        Fat Fly
        wrote on last edited by
        #106

        @mfalkvidd : Maybe change sleeping time to 60 min and STABILIZATION_TIME 1000 to 500 ms or smaller ? This place is pure lost energy. Why not to try without stablization time ?

        mfalkviddM 1 Reply Last reply
        0
        • Fat FlyF Fat Fly

          @mfalkvidd : Maybe change sleeping time to 60 min and STABILIZATION_TIME 1000 to 500 ms or smaller ? This place is pure lost energy. Why not to try without stablization time ?

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #107

          @Fat-Fly with the current solution it looks like I will get many years of battery life. Why make the solution worse without any gain?

          Without stabilization time you will get very unreliable results. I suggest you try and see what happens. Compare readings with and without stabilization times.

          1 Reply Last reply
          0
          • Fat FlyF Offline
            Fat FlyF Offline
            Fat Fly
            wrote on last edited by
            #108

            I in home and try this at the moment.

            1 Reply Last reply
            0
            • Fat FlyF Offline
              Fat FlyF Offline
              Fat Fly
              wrote on last edited by
              #109

              I upload sketch from here and pro mini not connect to gateway. GW from this pro mini away maybe 50 cm.

              1 Reply Last reply
              0
              • Fat FlyF Offline
                Fat FlyF Offline
                Fat Fly
                wrote on last edited by
                #110

                end: 0-0-1-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.3
                send: 0-0-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:1
                sensor started, id=0, parent=1, distance=2
                send: 0-0-1-0 s=255,c=3,t=11,pt=0,l=21,sg=0,st=fail:Plants moisture w bat
                send: 0-0-1-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.2
                send: 0-0-1-0 s=0,c=0,t=23,pt=0,l=0,sg=0,st=fail:
                find parent

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  flopp
                  wrote on last edited by flopp
                  #111

                  sensor started, id=0, parent=1, distance=2

                  You have no connection to GW since ID=0.

                  Looks you have a Repeater node since distance=2?

                  1 Reply Last reply
                  0
                  • Fat FlyF Offline
                    Fat FlyF Offline
                    Fat Fly
                    wrote on last edited by
                    #112

                    I deleted all my libaries catalog and unpack mysensors 1.4. Previous was 1.5. Too many options what i do not understand. After work i try again and to let you know from results.

                    1 Reply Last reply
                    0
                    • Fat FlyF Offline
                      Fat FlyF Offline
                      Fat Fly
                      wrote on last edited by Fat Fly
                      #113

                      2016-07-04 14:58:10.793 MySensors: Gateway Ready...
                      2016-07-04 14:58:10.869 MySensors: Gateway Version: 1.4.2
                      This domoticz log

                      This from Arduino ide
                      sensor started, id 0
                      send: 0-0-1-0 s=255,c=0,t=17,pt=0,l=5,st=fail:1.4.2
                      send: 0-0-1-0 s=255,c=3,t=6,pt=1,l=1,st=fail:1
                      send: 0-0-1-0 s=255,c=3,t=11,pt=0,l=8,st=fail:Humidity
                      send: 0-0-1-0 s=255,c=3,t=12,pt=0,l=3,st=fail:1.0
                      send: 0-0-1-0 s=0,c=0,t=7,pt=0,l=0,st=fail:
                      send: 0-0-1-0 s=1,c=0,t=6,pt=0,l=0,st=fail:
                      send: 0-0-1-0 s=1,c=1,t=0,pt=7,l=5,st=fail:80.2
                      send: 0-0-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
                      T: 80.24
                      send: 0-0-1-0 s=0,c=1,t=1,pt=7,l=5,st=fail:38.7
                      H: 38.70
                      send: 0-0-1-0 s=0,c=1,t=1,pt=7,l=5,st=fail:38.5
                      H: 38.50
                      send: 0-0-1-0 s=0,c=1,t=1,pt=7,l=5,st=fail:37.8
                      H: 37.80
                      send: 0-0-1-0 s=1,c=1,t=0,pt=7,l=5,st=fail:80.1
                      T: 80.06

                      This is not moisture sketch. I try with different sketches.

                      Maybe need change nrf? I try.2016-07-04 15:42:12.816 MySensors: Gateway Ready...
                      2016-07-04 15:42:12.891 MySensors: Gateway Version: 1.5.3

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        LastSamurai
                        Hardware Contributor
                        wrote on last edited by LastSamurai
                        #114

                        Version 1.5 should work if you do it right. It does for me.
                        In your case the sensor can't seem to get any connection to your gateway.
                        You should try adding a capacitor to the radio, check your power supply and change the nrf module. These are the reasons for most errors imo (especially the power supply)

                        There are extra Threads/Topics to finding an error with your setup here in the forum. I think this doesn't really belong to this thread anymore.

                        1 Reply Last reply
                        0
                        • Fat FlyF Offline
                          Fat FlyF Offline
                          Fat Fly
                          wrote on last edited by
                          #115

                          Okay. I search

                          L 1 Reply Last reply
                          0
                          • Fat FlyF Fat Fly

                            Okay. I search

                            L Offline
                            L Offline
                            LastSamurai
                            Hardware Contributor
                            wrote on last edited by
                            #116

                            @Fat-Fly said:

                            Okay. I search

                            This might help.

                            1 Reply Last reply
                            0
                            • Fat FlyF Offline
                              Fat FlyF Offline
                              Fat Fly
                              wrote on last edited by Fat Fly
                              #117

                              Today morning i can say : working. I bought arduinos 3,3v 10 pcs from Aliexpress. Yesterday i change this to 5V pro mini and this sensor get work. I take picture from this Arduino. Maybe 5volts not 3,3. Voltage stabilizer on the arduino is S201 ?
                              0_1467781824908_13607043_10210198205936111_585322452755227500_n.jpg
                              I'll change this china moisture fork with something stainless steel

                              1 Reply Last reply
                              0
                              • Fat FlyF Offline
                                Fat FlyF Offline
                                Fat Fly
                                wrote on last edited by Fat Fly
                                #118

                                One question. This sketch measure moisture every 60000 ms, 10 min.It is possible to measure every 30 min ? Battery power lost is minimal.
                                If this fork in water domoticz reported 88% of moisture. How to change value?

                                1 Reply Last reply
                                0
                                • Fat FlyF Fat Fly

                                  This post is deleted!

                                  F Offline
                                  F Offline
                                  Fay Candiliari
                                  wrote on last edited by
                                  #119

                                  @Fat-Fly Hi there! This is Fay from codebender.cc Thank you for using codebender! I just wanted to let you know that the sketch you are using here has been deleted and so it is not available for users to view it. Let me know if you have any question!
                                  Cheers!
                                  Fay

                                  1 Reply Last reply
                                  0
                                  • Fat FlyF Offline
                                    Fat FlyF Offline
                                    Fat Fly
                                    wrote on last edited by
                                    #120

                                    @Fay Candiliari good morning.
                                    I copied this scketch to my comp and delete all mysensors libraries and install development. After this all in ok.

                                    1 Reply Last reply
                                    0
                                    • clivecC Offline
                                      clivecC Offline
                                      clivec
                                      wrote on last edited by
                                      #121

                                      Thought I would throw this in the pot
                                      Why not change the sensor Probe ?? no credit to me , just was googleing as you do,
                                      Home made sensors I think less prone to corrosion
                                      here's the link

                                      http://www.cheapvegetablegardener.com/how-to-make-cheap-soil-moisture-sensor-2/

                                      Had some seeds from very tasty tomatoes last year ,have planted and this year growing like tiffids !!
                                      Getting quite big so have move from kitchen to Greenhouse ASP really
                                      Will try with this type of sensor

                                      mfalkviddM 1 Reply Last reply
                                      1
                                      • clivecC clivec

                                        Thought I would throw this in the pot
                                        Why not change the sensor Probe ?? no credit to me , just was googleing as you do,
                                        Home made sensors I think less prone to corrosion
                                        here's the link

                                        http://www.cheapvegetablegardener.com/how-to-make-cheap-soil-moisture-sensor-2/

                                        Had some seeds from very tasty tomatoes last year ,have planted and this year growing like tiffids !!
                                        Getting quite big so have move from kitchen to Greenhouse ASP really
                                        Will try with this type of sensor

                                        mfalkviddM Offline
                                        mfalkviddM Offline
                                        mfalkvidd
                                        Mod
                                        wrote on last edited by
                                        #122

                                        @mutantx nice idea, thanks for sharing!

                                        1 Reply Last reply
                                        0
                                        • Fat FlyF Offline
                                          Fat FlyF Offline
                                          Fat Fly
                                          wrote on last edited by Fat Fly
                                          #123

                                          I build moisture sensors from stainless wire. If this in pot at a depth of 1 inch domoticz reported 83% of moistre level.Real plant was dry and needed watering. I put moisture level on the soil

                                          0_1468159204580_IMG_4526.JPG

                                          and sensor reported moisture level 43%. I test and put moisture sensor to the soil at depth 1 inch

                                          0_1468159222643_IMG_4527.JPG

                                          Sensor reported moisture level 96%.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          17

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular