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. Solar Powered Soil Moisture Sensor

Solar Powered Soil Moisture Sensor

Scheduled Pinned Locked Moved My Project
79 Posts 19 Posters 37.8k Views 35 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.
  • mrwombleM Offline
    mrwombleM Offline
    mrwomble
    wrote on last edited by
    #58

    Hi all, I was so impressed by this thread that I decided to build my own. I must have spent maybe £6 or so - I really pushed the boat out. :smiley:

    It's been running successfully for a few weeks now, so I thought I'd share my code and a few pics. I upgraded the original code to v2.0. I've kept the update frequency high and it's running just fine, but we'll see how it goes in winter with less sun.

    Pics!
    0_1477923890152_IMG_20161016_151754 (Small).jpg
    Here you can see the boost converter and the Arduino pro mini.

    0_1477923898665_IMG_20161016_154217 (Small).jpg
    Here you can see the finished product in its natural environment. The RF radio sits in the plastic area, as I figured the metal collar at the top (where the arduino + battery sits) would have blocked/reduced the RF transmission.

    Code to follow.

    1 Reply Last reply
    1
    • mrwombleM Offline
      mrwombleM Offline
      mrwomble
      wrote on last edited by
      #59

      I meant to mention that the wires coming out of the bottom are the wires that go to the soil moisture probes.

      Here's the code in case anyone else would like it:

      // Updated to v2.0 of Mysensors
      
      // Enable debug prints
      #define MY_DEBUG
      #define MY_RADIO_NRF24
      
      #include <MySensors.h>
      #include <SPI.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 10000 // Sleep time between reads (in milliseconds), was 10000
      #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 default BOD settings
      const int SENSOR_ANALOG_PINS[] = {A4, A5}; // 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;   //removed for v2.0
      MyMessage msg(CHILD_ID_MOISTURE, V_HUM);
      MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE);
      long oldvoltage = 0;
      byte direction = 0;
      int oldMoistureLevel = -1;
      float batteryPcnt;
      float batteryVolt;
      int LED = 5;
      
      void setup()
      {
        pinMode(LED, OUTPUT);
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        delay(200);
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        
        //  gw.begin(); //Removed for v2.0
        for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) {
          pinMode(SENSOR_ANALOG_PINS[i], OUTPUT);
          digitalWrite(SENSOR_ANALOG_PINS[i], LOW);
        }
      }
      
      void presentation(){  //created for v2.0
        sendSketchInfo("Plant moisture w solar", "1.0");
        present(CHILD_ID_MOISTURE, S_HUM);
        delay(250);
        present(CHILD_ID_BATTERY, S_MULTIMETER);
      }
      
      
      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(msg.set((moistureLevel + oldMoistureLevel) / 2.0 / 10.23, 1));
        oldMoistureLevel = moistureLevel;
       
        int sensorValue = analogRead(A0);
        Serial.print("--Sensor value:");Serial.println(sensorValue);
        float voltage=sensorValue*(3.3/1023);
        Serial.print("--Voltage:");Serial.println(voltage);
        batteryPcnt = (sensorValue - 248) * 0.72;
        Serial.print("--Battery %:");Serial.println(batteryPcnt);
        batteryVolt = voltage;
        sendBatteryLevel(batteryPcnt);
        resend((voltage_msg.set(batteryVolt, 3)), 10);
        //send(voltage_msg.set(batteryVolt), 3);
      
        //flash led to indicate send
        digitalWrite(LED, HIGH);
        delay(200);
        digitalWrite(LED, LOW);
        
        sleep(SLEEP_TIME);
      }
      
      void resend(MyMessage &msg, int repeats)
      {
        int repeat = 1;
        int repeatdelay = 0;
        boolean sendOK = false;
      
        send(msg);
      /*
        while ((sendOK == false) and (repeat < repeats)) {
          if (send(msg)) {
            sendOK = true;
          } else {
            sendOK = false;
            Serial.print("Error ");
            Serial.println(repeat);
            repeatdelay += 500;
          } repeat++; delay(repeatdelay);
        }*/
      }
      
      
      int readMoisture() {
        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
        return moistureLevel;
      }
      
      

      My thanks to flopp for the cool idea and to everyone else on the thread for the contributions.

      1 Reply Last reply
      3
      • NeverDieN Offline
        NeverDieN Offline
        NeverDie
        Hero Member
        wrote on last edited by NeverDie
        #60

        Interesting project. To what degree, if any, has corrosion been a problem after you switched to soldered connections? Obviously the operating environment (near the ground outdoors) can be intrinsically humid.

        Also, can someone please post a larger photo of how the sensor is attached at the base? The area of interest on the photo provided is miniscule, and it's too grainy if I try to enlarge it to a better size:
        alt text

        NeverDieN F 2 Replies Last reply
        0
        • NeverDieN NeverDie

          Interesting project. To what degree, if any, has corrosion been a problem after you switched to soldered connections? Obviously the operating environment (near the ground outdoors) can be intrinsically humid.

          Also, can someone please post a larger photo of how the sensor is attached at the base? The area of interest on the photo provided is miniscule, and it's too grainy if I try to enlarge it to a better size:
          alt text

          NeverDieN Offline
          NeverDieN Offline
          NeverDie
          Hero Member
          wrote on last edited by
          #61

          By the way, I notice this guy has a rather interesting soil moisture sensor that appears to go beyond measuring mere electrical conductance: https://www.tindie.com/products/Power_Modules/fdr-100mhz-plant-soil-sensor-mineral-transparency/

          mrwombleM 1 Reply Last reply
          0
          • ? Guest
            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by
            #62

            @flopp Can you please include the pictures in your posting as the "tinypic.com" is rather intrusive, thanks...

            1 Reply Last reply
            0
            • NeverDieN NeverDie

              Interesting project. To what degree, if any, has corrosion been a problem after you switched to soldered connections? Obviously the operating environment (near the ground outdoors) can be intrinsically humid.

              Also, can someone please post a larger photo of how the sensor is attached at the base? The area of interest on the photo provided is miniscule, and it's too grainy if I try to enlarge it to a better size:
              alt text

              F Offline
              F Offline
              flopp
              wrote on last edited by flopp
              #63

              @NeverDie said:

              Interesting project. To what degree, if any, has corrosion been a problem after you switched to soldered connections? Obviously the operating environment (near the ground outdoors) can be intrinsically humid.

              I have not checked how the sensor look like now, but I have only run it for 6 months. I have always used soldered connections.

              Also, can someone please post a larger photo of how the sensor is attached at the base?

              1_1479545970922_20160606_131714652_iOS.jpg 0_1479545970922_20160606_131710115_iOS.jpg

              NeverDieN 1 Reply Last reply
              2
              • ? Guest
                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by
                #64

                @flopp Just copy the area's of intrest with a "snipping tool" (screen print) and copy in the post. Or, use one of the less intrusive services of the big cloud names...

                1 Reply Last reply
                0
                • NeverDieN NeverDie

                  By the way, I notice this guy has a rather interesting soil moisture sensor that appears to go beyond measuring mere electrical conductance: https://www.tindie.com/products/Power_Modules/fdr-100mhz-plant-soil-sensor-mineral-transparency/

                  mrwombleM Offline
                  mrwombleM Offline
                  mrwomble
                  wrote on last edited by
                  #65

                  @NeverDie
                  Interesting, but would make the project a little pricey.

                  1 Reply Last reply
                  0
                  • F flopp

                    @NeverDie said:

                    Interesting project. To what degree, if any, has corrosion been a problem after you switched to soldered connections? Obviously the operating environment (near the ground outdoors) can be intrinsically humid.

                    I have not checked how the sensor look like now, but I have only run it for 6 months. I have always used soldered connections.

                    Also, can someone please post a larger photo of how the sensor is attached at the base?

                    1_1479545970922_20160606_131714652_iOS.jpg 0_1479545970922_20160606_131710115_iOS.jpg

                    NeverDieN Offline
                    NeverDieN Offline
                    NeverDie
                    Hero Member
                    wrote on last edited by NeverDie
                    #66

                    @flopp
                    Perfect! Thanks a bunch. I like it. Very clever.

                    I think you were wise to cover the insulated wire with the silicon. Despite the appearance of being waterproof, I've noticed that regular wire insulation isn't waterproof/vaporproof, and regular wires used outdoors don't survive well (especially "copper" wires from China, which tend to have a high iron content and thus literally rust their way to failure). I don't know that silicon is sufficient, but if it isn't it might at least slow down the degradation process. It takes some effort to put these things together, so plainly you want them to last as long as possible.

                    Nice work!

                    Nca78N 1 Reply Last reply
                    0
                    • NeverDieN NeverDie

                      @flopp
                      Perfect! Thanks a bunch. I like it. Very clever.

                      I think you were wise to cover the insulated wire with the silicon. Despite the appearance of being waterproof, I've noticed that regular wire insulation isn't waterproof/vaporproof, and regular wires used outdoors don't survive well (especially "copper" wires from China, which tend to have a high iron content and thus literally rust their way to failure). I don't know that silicon is sufficient, but if it isn't it might at least slow down the degradation process. It takes some effort to put these things together, so plainly you want them to last as long as possible.

                      Nice work!

                      Nca78N Offline
                      Nca78N Offline
                      Nca78
                      Hardware Contributor
                      wrote on last edited by Nca78
                      #67

                      @NeverDie said:
                      I don't know that silicon is sufficient, but if it isn't it might at least slow down the degradation process.

                      Silicon is water proof, but not vapor proof. Else, it would not cure ;)

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

                        I have put glue on top of the soldering

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

                          WARNING!!!
                          I opened one of my items which didn't worked since many weeks ago.
                          I putted it on a table and should just open the stuff when I saw some brown water coming out from the pole.
                          My first guess was that it was water mixed with mud but the smell was strange. It can be that the battery has leaked.

                          If you will build this item please seal the battery to 100%. I just put the battery in the pole but unfortunately water came in and what I think destroyed the battery!

                          Be careful

                          1 Reply Last reply
                          2
                          • F Offline
                            F Offline
                            flopp
                            wrote on last edited by flopp
                            #70

                            Just wanna update you all how the battery has been since start.
                            No restart since 1st September.
                            A few days ago we moved the plant indoor and I forgot to take out the sensor, I moved the sensor outdoor the day after

                            0_1481267772602_chart.png

                            1 Reply Last reply
                            1
                            • HuczasH Offline
                              HuczasH Offline
                              Huczas
                              wrote on last edited by
                              #71

                              @flopp is your code should work with new version of gateway 2.1.1?
                              Just maked using this tutorial my gateway https://www.mysensors.org/build/raspberry and I'm getting nothing in debug...

                              pi@raspberrypi:~/MySensors $ sudo ./bin/mysgw -d
                              mysgw: Starting gateway...
                              mysgw: Protocol version - 2.1.1
                              mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
                              mysgw: TSM:INIT
                              mysgw: TSF:WUR:MS=0
                              mysgw: !TSM:INIT:TSP FAIL
                              mysgw: TSM:FAIL:CNT=1
                              mysgw: TSM:FAIL:PDT
                              mysgw: TSM:FAIL:RE-INIT
                              

                              In node I used your newest code for gw2.0 - is this because version mismatch or something different in my setup?
                              Could you update your code to work with new version?

                              F 1 Reply Last reply
                              0
                              • HuczasH Huczas

                                @flopp is your code should work with new version of gateway 2.1.1?
                                Just maked using this tutorial my gateway https://www.mysensors.org/build/raspberry and I'm getting nothing in debug...

                                pi@raspberrypi:~/MySensors $ sudo ./bin/mysgw -d
                                mysgw: Starting gateway...
                                mysgw: Protocol version - 2.1.1
                                mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
                                mysgw: TSM:INIT
                                mysgw: TSF:WUR:MS=0
                                mysgw: !TSM:INIT:TSP FAIL
                                mysgw: TSM:FAIL:CNT=1
                                mysgw: TSM:FAIL:PDT
                                mysgw: TSM:FAIL:RE-INIT
                                

                                In node I used your newest code for gw2.0 - is this because version mismatch or something different in my setup?
                                Could you update your code to work with new version?

                                F Offline
                                F Offline
                                flopp
                                wrote on last edited by
                                #72

                                @Huczas
                                I don't use 2.1, yet. I only use 1.5.1.
                                I don't have any knowledge of 2.x, so I cannot update the code, sorry

                                HuczasH 1 Reply Last reply
                                0
                                • F flopp

                                  @Huczas
                                  I don't use 2.1, yet. I only use 1.5.1.
                                  I don't have any knowledge of 2.x, so I cannot update the code, sorry

                                  HuczasH Offline
                                  HuczasH Offline
                                  Huczas
                                  wrote on last edited by
                                  #73

                                  @flopp just release that @mrwomble was posting that updated code sorry. @mrwomble can you help?

                                  1 Reply Last reply
                                  0
                                  • H Offline
                                    H Offline
                                    hiddenuser
                                    wrote on last edited by
                                    #74

                                    Hello All,
                                    Wondering if any one of the successful implenters would be able to share their soil moisture graphs,both for a day and over months..

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      dmonty
                                      wrote on last edited by
                                      #75

                                      To solve the battery discharge memory issue, could a second battery be added with logic to alternate between batteries and fully discharge one at a time?

                                      1 Reply Last reply
                                      0
                                      • gohanG Offline
                                        gohanG Offline
                                        gohan
                                        Mod
                                        wrote on last edited by
                                        #76

                                        Charge memory is a thing of the past, lithium batteries don't have it (if I understood what you meant).

                                        NeverDieN 1 Reply Last reply
                                        0
                                        • gohanG gohan

                                          Charge memory is a thing of the past, lithium batteries don't have it (if I understood what you meant).

                                          NeverDieN Offline
                                          NeverDieN Offline
                                          NeverDie
                                          Hero Member
                                          wrote on last edited by NeverDie
                                          #77

                                          @gohan said in Solar Powered Soil Moisture Sensor:

                                          Charge memory is a thing of the past, lithium batteries don't have it (if I understood what you meant).

                                          Except that, if I'm not mistaken, he's presently re-using the NiCd's that came with the original solar garden light.

                                          [Edit: correction: I think maybe (?) he switched to Nimh. I didn't think those had a memory problem. Do they? ]

                                          [Edit2: Maybe he'll "upgrade" to a supercap. :) A soil moisture meter would be a good application for one. ]

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


                                          13

                                          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