Office plant monitoring



  • Greenhouse

    I want to monitor soil moisture and switch on irrigation valves and pump. Windows open arduino but why not mysensors+domoticz. I can't and not want every morning go to open greenhouse windows. let this make computer 🙂

    Kastmistest nr. 007. Paprikad. – 02:04
    — Ants Kosmos



  • This post is deleted!

  • Mod

    @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)


  • Hardware Contributor

    @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
    }
    


  • 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)



  • @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 ?


  • Mod

    @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.



  • I in home and try this at the moment.



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



  • 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



  • 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?



  • 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.



  • 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


  • Hardware Contributor

    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.



  • Okay. I search


  • Hardware Contributor

    @Fat-Fly said:

    Okay. I search

    This might help.



  • 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



  • 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?



  • @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



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



  • 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


  • Mod

    @mutantx nice idea, thanks for sharing!



  • 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%.



  • Hello,

    After several weeks I finally succeed to create a dedicated PCB ! It was started yesterday evening and works fine.

    Some pictures:
    0_1469782265724_Photo 1.jpg
    0_1469782279459_Photo 2.jpg
    0_1469782286758_Photo 3.jpg

    Measure is reported each two hours. So I expect more than two years on a CR2032 (using @GertSanders firmware).

    I can off course provide any information as PCB.

    Thanks @mfalkvidd for the idea and the code. The project is now WAF 😉

    David.



  • Great. Nothing to say. But i need build this. 10 pcs first time. 🙂 I live in farm or how to right say in english. With rubber boots from the land ?



  • Is it possible to purchase it somewhere? 🙂



  • Why not mastered it self ?



  • Yesterday my sensor reported moisture 80% but soil was very wet. Thoughts.


  • Mod

    @Fat-Fly that is normal. Did you expect something else? If so, what did you expect?



  • @Fat-Fly
    I have sensors that report 25-35% and they are still not dry.
    I water for 10-20 min and they report 40%, sometimes 45%. But I know that when they report 25% it starts to be time to water.


  • Mod

    @flopp the level reported will depend on the following things (maybe more):

    • the pullup resistor - varies between different arduinos
    • the soil composition - varies between different pots
    • the temperature - varies throughout the day

    That means it is impossible to compare readings from two different Arduinos in the same pot and it is impossible to compare readings from different pots using the same Arduino.



  • @mfalkvidd
    Thanks



  • From temp varies moisture level and from fertilizer too. At the bottom of the bucket was more. Yesterday i install moisture sensor to the greenhouse. Level was 60-70%. This is normal if i check with finger. :). Today i try drive relays and water pump.
    0_1470039173699_34c652b1-4f64-42a6-9ffd-f41f8e3964ca.jpg



  • This sort of sensor is not good, because the electrolyticeffect.
    You always should use soil sensors, which are based on the capacitive effect.

    Like this one:
    https://forum.mysensors.org/topic/4474/capacitive-soilsensor-for-measurement-the-humidity-of-flowers

    Best regards,
    NetRap



  • My sensors is not good yes. I do not understand what is soil moisture % really. 😞 My pepper was overwatering. Very wet and moisture was 80% only.


  • Mod

    @NetRap there are downsides but "no good" is incorrect. I have used these sensors successfully for almost a year.



  • The problem is, that your design is based on conductivity.
    This means, that the electrodes will be destroyed over time
    and the produced metal salts are in your flower,garden,...

    I don't will have metal salts in my tomatoes !!! 😉


  • Mod

    @NetRap I doubt that one second of 3V electric power every hour (0.03% duty cycle) will produce measurable amount of salt but yes, for food production capacitive measurements are probably better. The topic of this thread is "office plant monitoring" though and I hope you don't have to live off your office plants 🙂


  • Hardware Contributor

    "Metal salts" doesn't sound very dangerous unless you're more specific. I prefer some NaCl on my tomatoes.

    How about some gold- or silver plated electrodes if you're of the worrying kind?



  • I want to try electrodes from stainless steel.



  • Normaly when you use eletricity and water, you need to sacrify something. For an example, when you cool a boat engine with water, you normaly use zinkanodes. I guess this is also the same when we want to messure humidity for an plant.
    So, if you should use copper anodes for messuring, you could paint them with a zink color.
    What it effects the resistance, I don't know.



  • Maybe in scketch needed change measure time? Maybe need use function round ?


  • Hardware Contributor

    @mfalkvidd Short question concerning battery life: I am using a custom board with an atmega328 and an nrf powered directly by a coin cell. When measuring temp/hum with something like an SHT21 the voltage drops are minimal (less than 100mV in more than a month). Using your sketch from post 25 here and connecting the fork to pins A1 and 2 (changed that in the sketch) I get a much higher power consumption. Any ideas why?
    I guess the measuring takes too long or something? It also reports lots of 1% changes to my domoticz server... which is kind of strange. Shouldn't the threshold take care of that? Perhaps I have to use a higher value here...


  • Mod

    @LastSamurai are you using the same sketch on both nodes?

    The sketch in post 25 sends the moisture value every 10 minutes. There are no thresholds and no comparison to previous value.

    Do the 1% changes look like a square wave? If so, the reason is probably that the pullup resistors differ from pin to min, even on the same atmega. A newer version of the sketch takes care of that, but I am still using the old version in my oldest node.

    As we discussed around post 79, my node is dropping very slowly. It is currently at 3.117 V after approximately 9 months on the same 2xAA. The node started at 3.187V so that is a drop of 70mV, less than 10mV per month.



  • Good morning people.
    Can somebody help add to this moisture sensing sketch relay ?



  • So does this work with 2.0?


  • Mod

    @cattoo yes if it is converted.



  • What needs to be added/edited so its converted?


  • Mod

    @cattoo that is described in the instructions I linked to 🙂



  • Its driving me crazy! Could you not convert this mfalkvidd! Its better to have your sketch on the front instead of that one there is there now.


  • Mod

    @cattoo I won't convert it in the near future. I have too many projects that are more fun and more useful. My current setup works great, upgrading everything to 2.0 would mean a lot of work and no gain.



  • After my other failed attempt I needed to try this.
    I have a 5V Mini using A4 and A5 and a fork YL-69 and I get these result:

    Direction: 1
    Moist: 171
    Direction: 0
    Moist: 23
    Direction: 1
    Moist: 172
    Direction: 0
    Moist: 0
    Direction: 1
    Moist: 164
    Direction: 0
    Moist: 0
    Direction: 1
    Moist: 156
    Direction: 0
    Moist: 0
    Direction: 1
    Moist: 144
    Direction: 0
    Moist: 0

    This is not the percentage value , its this value I print: moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction]));

    Any Ideas?


  • Mod

    @Martin-Tellblom could you describe what an YL-69 is?

    How much time do you let the measurement settle after switching directions?
    Which of the code versions are you using? There have been many revisions in this thread and they all work slightly different.



  • @mfalkvidd said:

    me do you le

    My "Fork" is stamped with YL-69. Looks exacly like the XD-28
    It's your code from post 25 so I suppose 1000 (#define STABILIZATION_TIME 1000 )


  • Mod

    @Martin-Tellblom Thanks. You did throw away the middle chip and only use the fork, right? (as described in post 41)



  • @mfalkvidd : Yes I did, and I have tried using A2&A3 and its the same


  • Mod

    @Martin-Tellblom can you try another Arduino?



  • @mfalkvidd
    Have tried both a 3.3V and a 5V both behave the same.
    I check every 30 seconds now and after about 10 minutes the result is 0 on both directions.
    I restart the arduino and then one direction shows a value and the other 0.
    There is proberbly something with my forks 🙂

    Did I mention that I upgraded the sketch to 2.0? Could that be a problem?


  • Mod

    There is proberbly something with my forks 🙂

    They are (or at least should be) completely passive, so there is nothing that should be able to go wrong.

    Could you post a photo of your connections?

    If you disconnect the fork from the Arduino and measure the resistance between the two connectors using a multimeter (in both directions), what resistance do you get?

    Did I mention that I upgraded the sketch to 2.0? Could that be a problem?

    Not if you did it right 🙂 I have no experience with 2.0 unfortunately.



  • @mfalkvidd

    I at the office right now, measure them when I home



  • @mfalkvidd said:

    should be) completely passive, so there is nothing that should be able to go wrong.

    Could you post a photo of your connections?

    Here is my setup. Using the Easy/Newbie board that @sundberg84 created with a 5V arduino mini pro 16Mhz. Using A4 and A5 to the sensor
    alt text

    Regarding the resistance when its out of the soil there is no connection at all. If I put it in the soil there a strange thing happening .
    The resistance start around 10K and then slowly increase (no matter if I switch the direction) the longer I test the higher value.
    If I switch the direction the resistance start from whre it just was and keep rising . If I let the senor pause for a while (5 minutes or so) it's back to around 10K.

    Maybe I test it to often? Don't let the moisture get back to the soil?


  • Mod

    Stange. The setup looks good. The soil in my plants doesn't behave like that.



  • It seems like @sundberg84 nailed it 🙂
    The battey metering I use with his PCB is this:

    #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
    #else
      analogReference(INTERNAL);
    #endif
    

    And that reflect on all analog channels and break the function..
    After I removed the battery sensing code it work great



  • You should check out this side (Use Google Side Translator):
    https://github.com/Zentris/erdfeuchtemessung/wiki

    Theres also the sensor from here:
    Giesomat


  • Mod

    So my Bonsai tree humidity node just celebrated 1 year on battery! 🎉 💝
    During the last year, the gateway has received 76,164 updates on humidity level (and an additional 13,996 updates on voltage level).

    The battery level has gone from 3.187V to 3.108V, which means an average drop of 0.0066V per month. Assuming I let it go down to 2.34V (limit for 8MHz according to the datasheet) and that the voltage drop is linear, I should get (3.187-2.34)/0.0066 = 128 months = ~10.7 years. There are several error sources in this calculation, but it looks like battery life will be quite good.

    Here are the voltage and humidity graphs for the last year
    0_1478891116569_chart.png
    0_1478891124165_humidity_bonsai.png



  • @mfalkvidd that is really awesome!

    Did you set any Brown Out Fuses?
    From what I gather the arduino pro mini will stop working at 2.8V and you have to set other fuses for it to reach the lower voltages.

    I did a quick test with one flowerpot and from what I see my power consumption will be around 0.2V per year. It's more than double of what you're getting. But still low enough as changing 2 AA over 1-2 years is OK in my book if I'm not changing the fuses 🙂

    EDIT: Actually, calculating with your numbers of updates I get around 0.6V consumption per year for my setup and that is far from your low power consumption.
    I think I will have to go through this thread once more to try to find why the difference is so big and what you have done. I see 2 potential culprits. One is the arduino mini pro (china clone without power LED and voltage regulator) or maybe it could be my mysensors 2.0 version vs your 1.6.


  • Mod

    @Nicklas-Starkel if I remember correctly I disabled bod completely.



  • @mfalkvidd, @Nicklas-Starkel
    similar problem here. I have a bare ATMega 328P, running @ 8 MHz internal oszillator. no LED, bod disabled, (if enabled, the ADC is running also during sleep, so this means additional power consumption), nothing else connected that could draw additional power.
    I use mfalkvidd's sketch (BTW, thanks a lot for it !), but converted to mysensors 2.0. I see a voltage drop way higher than mfalkvidd, although I don't use a china clone ;-).
    So it seems, that the higher power consumption may be due to mysensors V2 ? I cannot imagine a reason for that, because why should relatively low level functions like power save routines be different in 2.0 ?
    Perhaps hek can comment ?



  • @mfalkvidd
    I think that in a previous post you mentioned that you are using mysensors V1.6, right ? Where did you get it from ? On the mysensors pages I only found references and links to V1.4 and V1,5, not V1.6. I would like to try to remove V2.0 from my system and switch to V1.6 - no idea if this will work ...
    I would like to use a setup as close as possible to yours to track down the problem. Your very low power consumption is really amazing and I would like to come as close as possibe to int in my case. I have a 'clone' of your hardware setup described in openhardware.io - minus the LED. So in my case, power consumption should be even lower than yours 😉


  • Hero Member

    @joshmosh I think that version 1.5.4 or 1.5.3 was called 1.6 while it was under development but no version 1.6 was ever released.



  • @korttoma
    OK, thanks for the hint. I will try if I can get this version work with the Arduino version I am using.



  • @korttoma
    OK, after some fiddling I was able to exchange mysensors V2.0 with V1.5.4 and to compile mfalkvidd's sketch. I will adapt it now to my hardware (removing references to LED etc) and give it a twirl. Please be patient, since I need to run it at least a coupl eof days to see if there is a difference in power consumption.
    Very interesting stuff 🙂



  • @joshmosh , actually there is so many variables that it is impossible to check and the term "milage may vary" is spot on.
    All batteries are not the same.
    Temperature.
    Arduino.
    Time between readings (some batteries prefer small current over time and some handle bursts better).
    etc

    I've set to report moisture every 30 seconds and obviously the voltage report from an arduino is not 100%. And with that said, it is probably not 100% consistent neither as it could differ between readings as well.
    The only real way to tell is know starting point via multimeter and then check after a month what has happened.
    For me, doing a check, I've come down to 0.08V per 76000 readings.
    I did the estimation based on about 8500 readings and extrapolated it to 76000 reports based on @mfalkvidd information.

    For me, this is enough and I'm sure my sensor will survive for a long time and can now program it to take more reasonable moisture readings. Example, 1reading/h for the plots that dries the fastest (in direct sunlight) and less when they are in the shade.
    In the spring the balcony will have several sensors with automatic watering 🙂



  • @Nicklas-Starkel
    After some reading and thinking, I came to a very similar conclusion. There are tons of parameter which will influence the mesurement.
    I am planning to use four or five moisture probes distributed at various places in my garden for irrigation automatisation. I guess my lawn will not suffer if I start watering at a reading of 41 % instead of 44 % 😉
    During the upcoming winter months there is enough time to gather empirical data about the behaviour of my probes.
    Anyway, it's a fun project ...



  • Well I have some issues with battery-power.
    When ill use the Usb cable to power the sensor up, everything is working fine. But when ill use 2x1,5V battery´s it does not show up in domoticz. Im not sure if I have connected the battery correct. Its on the VIN and GND and nothing more. Is it correct?


  • Mod

    @cattoo which Arduino are you using? I'm asking because the Pro Mini doesn't have any pin called VIN.



  • @mfalkvidd
    Its a Arduino Nano (clone)



  • Why not using this sensor?
    Giesomat

    It didn't cost much and work like an angel.

    And if the frequency is to high, or you need a other logic level, you can use this one:
    frequency divider and level shifter

    Don't have any troubles with this.
    I only count the pulses. That all.


  • Mod

    @NetRap You have already stated the same 3 times earlier in this thread. It looks like spam/advertising. What's your point?


  • Mod

    @cattoo VIN on the Nano is used when powering with higher than 5V.
    The Nano is not suitable for battery power. I recommend that you use a Pro Mini instead. See https://www.mysensors.org/build/battery



  • I don't want to spam.
    The point is, that the conducting based sensors are poison.
    The electrolytic processes destroy the sensor and giving ions into the
    earth !!!

    Look at this site:
    All Technologies
    There are compared all possible technology's.
    Giesomat wins.



  • @mfalkvidd said:
    Ah okey, well then ill use them with proper power and buy new pro mini´s instead. Tack 🙂



  • Hello,

    Is there a sketch for mysensors 2.0
    I get error on the Mysensor gw;

    Ton



  • Just to give a feedback on power consumption: I have switched back to mysensors V 1.5.4. This was roughly one month ago. I take meadurements every two hours. Battery voltage hasn't changed a bit since then. So my guess is, that - for whatever reason - mysensors V 2.0 seems to produce a more power hungry code.
    Whatever ...
    I am happy now and will stick with V 1.5.4
    I am



  • @joshmosh I use MySensors V2 and took a sample every 30 seconds over a few days simulating almost 28000 transmits.
    I've come down to have roughly 0.08V decrease for all these transmits which is very close to what @mfalkvidd has.

    @TON-RIJNAARD , here is my sketch! I think I use signing as well, so if you don't use it just remove 🙂

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    //The node ID
    #define MY_NODE_ID 7 //250 is test 
    // Enable and select radio type attached and also set parent ID
    #define MY_RADIO_NRF24
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    //Signing, make sure the arduino is prepped for signing before!
    #define MY_SIGNING_SOFT
    #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
    #define MY_SIGNING_REQUEST_SIGNATURES
    #include <SPI.h>
    #include <MySensors.h>
    
    #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
    #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
    
    #define CHILD_ID_MOISTURE 0
    #define CHILD_ID_BATTERY 1
    #define SLEEP_TIME 1800000 // Sleep time between reads (in milliseconds)
    #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading
    #define BATTERY_FULL 3000 // 3,000 millivolts for 2xAA
    #define BATTERY_ZERO 2800 // 1,900 millivolts (1.9V, limit for nrf24l01 without step-up. 2.8V limit for Atmega328 without BOD disabled))
    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.
    
    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()
    {
      sendSketchInfo("Plant moisture w bat", "1.5");
    
      present(CHILD_ID_MOISTURE, S_HUM);
      delay(250);
      present(CHILD_ID_BATTERY, S_CUSTOM);
      for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) {
        pinMode(SENSOR_ANALOG_PINS[i], OUTPUT);
        digitalWrite(SENSOR_ANALOG_PINS[i], LOW);
      }
    }
    
    void loop()
    {
      pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor
      analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging
      sleep(STABILIZATION_TIME);
      int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction]));
    
      // 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
      // Always send moisture information so the controller sees that the node is alive
    
      // 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 value
        oldMoistureLevel = moistureLevel;
      }
      send(msg.set((moistureLevel + oldMoistureLevel +  0.5) / 2 / 10.23, 1));
      oldMoistureLevel = moistureLevel;
      long voltage = readVcc();
      if (oldvoltage != voltage) { // Only send battery information if voltage has changed, to conserve battery.
        send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts. Set wants volts and how many decimals (3 in our case)
        sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO)));
        oldvoltage = voltage;
      }
      sleep(SLEEP_TIME);
    }
    
    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
    }```


  • @Nicklas-Starkel
    Strange ...
    But since I am not missing / using any of the advanced features offered by V 2.0, I don't see a problem (at least for now) to stick with V 1.5.4
    In any case it is amazing what you can do with low power battery poweroperated sensors.



  • Hi,
    in last MySensors lib version 2.1.0, I see a new sensor type : S_MOISTURE
    It's more logicial to use this new type instead of S_HUM ?

    and so use V_LEVEL instead of V_HUM ?

    Thanks for respons



  • If I use more than one sensor for this. It still will only monitor one plant right? Or can I say monitor 3-4 plants with one node?



  • I have an arduino pro mini, connected to 2-3 flowers using A0+A1, A2+A3, A4+A5.. unfortunately, I'm seeing some weird effects between the plants.. if I water one plant, another can change a bunch at the same time (or not, depending on stuff).. Also if I disconnect one flower, another flower can get way different values too..

    I haven't figured out yet if I'm getting a capacitor effect in the flowers, sending back power through the output signals or what's happening..
    0_1483967302526_flower.png

    Here I added water to the "green" flower, then the values for the gray one dropped. The gray one was physically untouched while watering.

    Code is based on mfalkvidd, with all Ax being set to output=0 and then input+pullup for one while reading..


  • Mod

    @Stric interesting (and strange) effect. I wonder what causes it. Maybe the wait time beween turning on the pin and doing the measurement is too short so the level doesn't settle completely?



  • @Tetnobic i tried this and Ended up with a soil sensor that didn't display % but something called cb?

    But yeah it works.



  • I made a node with 1 fork and it works great!

    Any tips on how i can use more than one fork to monitor say 3-4 plants?



  • @mfalkvidd I'm going to do some tests with changing the sampling time and sleep time, but I'm not so hopeful since the effect is seen hours/days after an "unrelated" change.. I got stuck yesterday playing with ESPEasy, but I'll get back to debugging this..



  • @meanmrgreen See my post a few up, I'm seeing some weird effects when connecting to more than one plant..



  • @Stric

    Does reverse polarity really help with corrosion then? Maybe it has something to do with that.



  • Small problem with my plant sensor. Used only the fork and the reverse polarity.

    But the sensor is reporting around 80-70% all the time, alltho the plant is pretty dry.

    When i remove the sensor from pot it shows 0% ?

    Can you calibrate the fork somehow?


  • Mod

    @meanmrgreen I calibrate by putting my finger in the soil. When the soil is too dry I note the current value and set a notification to trigger next time it reaches that level.



  • @mfalkvidd

    Ok 🙂
    But Its normal just to lower by a few percent in a few days time?



  • I'm going to try do this with the slim node and a cr2032 battery. Which cap do you recommend using to help battery?


  • Mod

    @meanmrgreen said:

    But Its normal just to lower by a few percent in a few days time?

    It depends on the soil type, the plant, the temperature, if the plant gets direct sunlight and probably some more factors.


Log in to reply
 

Suggested Topics

  • 8
  • 7
  • 44
  • 2
  • 5
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts