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. Announcements
  3. πŸ’¬ Soil Moisture Sensor

πŸ’¬ Soil Moisture Sensor

Scheduled Pinned Locked Moved Announcements
99 Posts 33 Posters 31.6k Views 32 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.
  • alowhumA alowhum

    Has anyone had a look at the "Chirp" sensor? It's a great little open hardware project that can be bought on Aliexpress for $4 - $6.

    alt text

    • It monitors the waterlevel and light level.
    • When soil moisture is low, it will chirp to let you know it needs water.
    • It can be read out via i2c!
    mfalkviddM Online
    mfalkviddM Online
    mfalkvidd
    Mod
    wrote on last edited by mfalkvidd
    #28

    @alowhum yes, the chirp sensor has been discussed a few times.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dakipro
      wrote on last edited by
      #29

      Here is the water leakage sensor I was mentioning few posts above, using thin ribbon cable as a sensor.
      https://forum.mysensors.org/topic/7736/water-leakage-sensor-using-thin-ribbon-cable-testing-reliability
      Time will tell if it is usable at all before it corrodes completely.
      Thanks @RobKuipers for the code, works like a charm!

      C: OpenHAB2 with node-red on linux laptop
      GW: Arduino Nano - W5100 Ethernet, Nrf24l01+ 2,4Ghz mqtt
      GW: Arduino Mega, RFLink 433Mhz

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lshield
        wrote on last edited by
        #30

        This is a really simple question but I'm new to the whole thing. How would I use the water level sensor which is shown in the shopping guide? I understand that it's analog but I'm not completely sure how I'd write the sketch. Thanks!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          manutremo
          wrote on last edited by
          #31

          Just to summarize since the thread is becoming a bit confusing.

          The sensor shown in the example and the shopping guide is no more than a device that measures the resistance between the two pins of the fork. That is done by the boards, which includes an analog output and a digital output.

          Should you just need to know when moisture is over or below a certain degree, just connect the digital output to a digital pin in the Arduino. Then use the potentiometer in the board to decide the switching point. In a battery powered node, this could be connected to an interrupt pin so the node sleeps and is only waken up when the moisture falls under the predetermined level to send an alert to the controller. But if you want to know track how moisture evolves, you may connect the analog output of the board to an analog pin in the arduino, which will provide a numerical value. Then the sensor needs to be calibrated; there are several forms but one involves measuring the output when the fork is submerged in water (which would be 100% moisture) and then when it's in air (that would be 0%). You can then map this scale to a moisture scale, typically a cb scale.

          The negative side of using that board is that the current always flows in the same direction through the fork. The same occurs with another similar type of sensor like the sparkfun here. This will lead in some time to corrosion of the fork, even if it's one of the latest nickeled ones. Reports in the internet vary from weeks to months, but in any case the form will corrode and as a result the measurement will drift slowly.

          The alternating polarization strategy tries to overcome this problem. To do so, the board is removed and only the fork is used. Instead of connecting it to Vcc and GND, the two terminals are connected so that the fork is actually one of the resistors in a voltage divider. The other resistor is usually a 10k resistor. In this setup, one of the digital pins is connected to one leg of the resistor, the other resistor leg is connected to one side of the fork, and the other side of the fork is connected to the other digital pin on the Arduino. Another wire needs then to be connected between the connection between the resistor and the fork, to an analog pin of the Arduino, which will read a value that will be proportional to the resistance of the fork, therefore to the moisture level. Then, by switching the pins from INPUT to OUTPUT, and from HIGH to LOW, you can have the current flow in one direction or the opposite one, which significantly delays the corrosion. In my case, the forks still look like new after months of use. Corrosion speed will still obviously depend by time between readings, reading time, soil type and other factors. I've never experimented with this sensor but with a rain sensor I could see corrosion symptoms after some minutes of continuous readings. This sensor also needs to be calibrated in a similar way as the former one. This setup makes the sketch a bit more complex but there are multiple examples here and in the internet.

          There are also variations on the measurement strategy within this approach. For example, you may just take a reading in one direction, another reading in the other direction, convert them to moisture level, and average them. Other people take several readings and average them all. I realized that if the reading is repeated, the value increases with each reading until it stabilizes at a certain value, so I decided to have the sketch iterate until two consecutive readings get the same result. The measuring time also needs to be asessed; in my investigation, the shorter the time, the less battery consumption, but at some point around 5ms the readings started to be unreliable. On the other hand, the longer the measurement the more realiable, but the span of the measurements in analog pin where closer and closer which led to loss of accuracy, and of course higher battery consumption. I decided 10ms was a good balance but others' milage may vary.

          Finally, there are other completely types of moisture sensor that measure the soil dielectric constant instead of its resistance. They are said to be more reliable, and additionally they do not suffer from corrosion since they do not need to be conductive, hence they are covered by a layer of non-metal material (probably epoxy?). This makes them more durable but also more expensive. I have no experience with those.

          I hope this contributes to clarify this topic a little bit. This thread contains additional information on the same topic.

          1 Reply Last reply
          3
          • M Offline
            M Offline
            Maxime
            wrote on last edited by
            #32

            I guess I'm not the only one seeking for the correct diagram. It can be found here: http://vanderleevineyard.com/1/post/2012/08/-the-vinduino-project-3-make-a-low-cost-soil-moisture-sensor-reader.html
            alt text

            1 Reply Last reply
            0
            • M Offline
              M Offline
              manutremo
              wrote on last edited by
              #33

              Now that I managed to get my grips on Fritzing, I thought I could share a quick diagram of my own device which I tried to describe above.

              alt text

              Note that the capacitor between the middle point of the voltage divider and GND is just recommended, and its value is orientative.

              Not showing battery, radio, reset button, etc., just the soil moisture sensor part.

              I've seen other versions using transistors to switch the sensor current, and other variations; I think this is the simplest version of an alternating current sensor and it works very well.

              dbemowskD 1 Reply Last reply
              0
              • M manutremo

                Now that I managed to get my grips on Fritzing, I thought I could share a quick diagram of my own device which I tried to describe above.

                alt text

                Note that the capacitor between the middle point of the voltage divider and GND is just recommended, and its value is orientative.

                Not showing battery, radio, reset button, etc., just the soil moisture sensor part.

                I've seen other versions using transistors to switch the sensor current, and other variations; I think this is the simplest version of an alternating current sensor and it works very well.

                dbemowskD Offline
                dbemowskD Offline
                dbemowsk
                wrote on last edited by
                #34

                @manutremo You may want to put a jumper in on the top power bus that you connect the 100nf capacitor to. It is not clear, at least to me, if that is to VCC or GND. On a true breadboard you would have to do that.

                Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                M 1 Reply Last reply
                0
                • dbemowskD dbemowsk

                  @manutremo You may want to put a jumper in on the top power bus that you connect the 100nf capacitor to. It is not clear, at least to me, if that is to VCC or GND. On a true breadboard you would have to do that.

                  M Offline
                  M Offline
                  manutremo
                  wrote on last edited by
                  #35

                  @dbemowsk the convention in these breadboards is that the blue rail is Gnd. You may either connect the two sides or use a Mb102 module to feed both sides at the same time. You may also choose other options.

                  The capture is not showing the power feed part since it's clear enough and because what it is mainly trying to describe is the moisture measurement part which is the part seemingly causing confusion and the origin of the thread.

                  dbemowskD 1 Reply Last reply
                  0
                  • M manutremo

                    @dbemowsk the convention in these breadboards is that the blue rail is Gnd. You may either connect the two sides or use a Mb102 module to feed both sides at the same time. You may also choose other options.

                    The capture is not showing the power feed part since it's clear enough and because what it is mainly trying to describe is the moisture measurement part which is the part seemingly causing confusion and the origin of the thread.

                    dbemowskD Offline
                    dbemowskD Offline
                    dbemowsk
                    wrote on last edited by
                    #36

                    @manutremo said in πŸ’¬ Soil Moisture Sensor:

                    @dbemowsk the convention in these breadboards is that the blue rail is Gnd.

                    I get that, but if someone were to build that as you have diagrammed with a standard breadboard, it would not work.

                    @manutremo said in πŸ’¬ Soil Moisture Sensor:

                    You may either connect the two sides or use a Mb102 module to feed both sides at the same time. You may also choose other options.

                    You, me and other people in here may understand that, but a newbie most likely wouldn't. When I made the comment, I was assuming that that is what you meant, but had to be sure for the newbies.

                    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                    M 1 Reply Last reply
                    0
                    • dbemowskD dbemowsk

                      @manutremo said in πŸ’¬ Soil Moisture Sensor:

                      @dbemowsk the convention in these breadboards is that the blue rail is Gnd.

                      I get that, but if someone were to build that as you have diagrammed with a standard breadboard, it would not work.

                      @manutremo said in πŸ’¬ Soil Moisture Sensor:

                      You may either connect the two sides or use a Mb102 module to feed both sides at the same time. You may also choose other options.

                      You, me and other people in here may understand that, but a newbie most likely wouldn't. When I made the comment, I was assuming that that is what you meant, but had to be sure for the newbies.

                      M Offline
                      M Offline
                      manutremo
                      wrote on last edited by
                      #37

                      My posting clearly states:

                      the capacitor between the middle point of the voltage divider and GND

                      @dbemowsk said in πŸ’¬ Soil Moisture Sensor:
                      It is not clear, at least to me, if that is to VCC or GND.

                      There's only one cap in the diagram so it should be quite clear.

                      @dbemowsk
                      if someone were to build that as you have diagrammed with a standard breadboard, it would not work.

                      I tend to think it wouldn't work with the jumper either if built as diagrammed, since the power source would still be missing.

                      Don't you think that jumper could possibly lead newbies to confusion into thinking that the power supply needs to be done in a certain way? Or would it be better to avoid overloading the diagram with information irrelevant to the concept being illustrated and just focus on the important part? Certainly a personal decision. I might be wrong but I chose "less is more".

                      Even newbies getting into electronics understand that diagrams may not always show all the components specially when they are focused and intended to illustrate a specific part of the circuit. even newbies into electronics understand that a power source is always necessary even though it may not appear in the diagram. Almost anyone using a breadboard knows what those rails are, what do the colors mean and that the way to pΓ²wer them is mostly irrelevant as long as they get the proper voltage and current. And for the newbies and the few that may not , the community here will be happy to clarify.

                      I appreciate your contribution but still fail to see why the diagram is confusing and I still think it responds to its original purpose. Feel free to improve it at your convenience.

                      1 Reply Last reply
                      0
                      • UL7AAjrU Offline
                        UL7AAjrU Offline
                        UL7AAjr
                        wrote on last edited by
                        #38

                        Try to never try resistive sensors. It is reaaly wrong way. I try to bult few resistive. No way.
                        I try to buld some inductive. Yes, it's possible, but lot of analog parts, difficult to calibrate. No way too.
                        Capacitive senors is most reliable and has a simple digital schematics.

                        Good luck you on your way)

                        PS: here is my own sensor http://vegimatics.com/products/current/
                        want do discuss - wellcome)

                        raptorjrR 1 Reply Last reply
                        1
                        • UL7AAjrU UL7AAjr

                          Try to never try resistive sensors. It is reaaly wrong way. I try to bult few resistive. No way.
                          I try to buld some inductive. Yes, it's possible, but lot of analog parts, difficult to calibrate. No way too.
                          Capacitive senors is most reliable and has a simple digital schematics.

                          Good luck you on your way)

                          PS: here is my own sensor http://vegimatics.com/products/current/
                          want do discuss - wellcome)

                          raptorjrR Offline
                          raptorjrR Offline
                          raptorjr
                          wrote on last edited by
                          #39

                          @ul7aajr The link isn’t working for me.

                          NeverDieN 1 Reply Last reply
                          0
                          • raptorjrR raptorjr

                            @ul7aajr The link isn’t working for me.

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

                            @raptorjr Worked for me.

                            raptorjrR 1 Reply Last reply
                            0
                            • NeverDieN NeverDie

                              @raptorjr Worked for me.

                              raptorjrR Offline
                              raptorjrR Offline
                              raptorjr
                              wrote on last edited by
                              #41

                              @neverdie Yes. Works today. Yesterday I got a 404 error.

                              1 Reply Last reply
                              0
                              • alowhumA Offline
                                alowhumA Offline
                                alowhum
                                Plugin Developer
                                wrote on last edited by
                                #42

                                @ul7aajr said in πŸ’¬ Soil Moisture Sensor:

                                Try to never try resistive sensors. It is reaaly wrong way. I try to bult few resistive. No way.
                                I try to buld some inductive. Yes, it's possible, but lot of analog parts, difficult to calibrate. No way too.
                                Capacitive senors is most reliable and has a simple digital schematics.

                                Good luck you on your way)

                                PS: here is my own sensor http://vegimatics.com/products/current/
                                want do discuss - wellcome)

                                I'm currently building a sensor that uses the Chirp devices. I want to chain them together. You can get them for 4 dollars each.

                                NeverDieN UL7AAjrU 2 Replies Last reply
                                0
                                • alowhumA alowhum

                                  @ul7aajr said in πŸ’¬ Soil Moisture Sensor:

                                  Try to never try resistive sensors. It is reaaly wrong way. I try to bult few resistive. No way.
                                  I try to buld some inductive. Yes, it's possible, but lot of analog parts, difficult to calibrate. No way too.
                                  Capacitive senors is most reliable and has a simple digital schematics.

                                  Good luck you on your way)

                                  PS: here is my own sensor http://vegimatics.com/products/current/
                                  want do discuss - wellcome)

                                  I'm currently building a sensor that uses the Chirp devices. I want to chain them together. You can get them for 4 dollars each.

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

                                  @alowhum What do you mean by "chain them together"?

                                  alowhumA 1 Reply Last reply
                                  0
                                  • NeverDieN NeverDie

                                    @alowhum What do you mean by "chain them together"?

                                    alowhumA Offline
                                    alowhumA Offline
                                    alowhum
                                    Plugin Developer
                                    wrote on last edited by
                                    #44

                                    @neverdie They support I2C. So in theory you can connect a whole bunch to a pin. I'm trying to figure out if I can detect all of them and then automatically give each a unique ID.

                                    dbemowskD 1 Reply Last reply
                                    0
                                    • alowhumA alowhum

                                      @neverdie They support I2C. So in theory you can connect a whole bunch to a pin. I'm trying to figure out if I can detect all of them and then automatically give each a unique ID.

                                      dbemowskD Offline
                                      dbemowskD Offline
                                      dbemowsk
                                      wrote on last edited by
                                      #45

                                      @alowhum I amm not sure how easy it is to change the I2C address on devices like this.

                                      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                      alowhumA 1 Reply Last reply
                                      0
                                      • dbemowskD dbemowsk

                                        @alowhum I amm not sure how easy it is to change the I2C address on devices like this.

                                        alowhumA Offline
                                        alowhumA Offline
                                        alowhum
                                        Plugin Developer
                                        wrote on last edited by alowhum
                                        #46

                                        @dbemowsk Changing the Chirp's I2C address is very easy actually.

                                        #include <I2CSoilMoistureSensor.h>
                                        #include <Wire.h>
                                        
                                        I2CSoilMoistureSensor sensor(0x20);
                                        
                                        // connect the reset pin (5) of the Chirp to a pin on your Arduino. It will create a small reset signal. This tells the chirp it should not be a stand-alone ensor, but an I2C connected one. If it receives I1C data shortyl after a reset (few seconds), then it will understand.
                                        int resetPin = 4;
                                        
                                        void setup() {
                                          pinMode(resetPin, OUTPUT); 
                                          delay(1000);
                                          digitalWrite(resetPin, HIGH);       // sets the digital pin 13 on
                                          delay(100);                  // waits for a second
                                          digitalWrite(resetPin, LOW);        // sets the digital pin 13 off
                                          delay(1000);
                                          Wire.begin();
                                          Serial.begin(9600);
                                        
                                          sensor.begin(); // reset sensor
                                          delay(1000); // give some time to boot up
                                          Serial.print("I2C Soil Moisture Sensor Address: ");
                                          Serial.println(sensor.getAddress(),HEX);
                                          Serial.print("Sensor Firmware version: ");
                                          Serial.println(sensor.getVersion(),HEX);
                                          Serial.println();
                                        
                                          Serial.print("Change address to 0x21 ...");
                                          if (sensor.setAddress(0x21,true)) // set Sensor Address to 0x21 and reset
                                            Serial.println("... DONE");
                                          else
                                            Serial.println("... ERROR");
                                          Serial.println();
                                        }
                                        
                                        /*loop scans I2C bus and displays foud addresses*/
                                        void loop() {
                                          byte error, address;
                                          int nDevices;
                                        
                                          Serial.println("Scanning...");
                                        
                                          nDevices = 0;
                                          for(address = 1; address < 127; address++ ) {
                                            // The i2c_scanner uses the return value of
                                            // the Write.endTransmisstion to see if
                                            // a device did acknowledge to the address.
                                            Wire.beginTransmission(address);
                                            error = Wire.endTransmission();
                                        
                                            if (error == 0) {
                                              Serial.print("I2C device found at address 0x");
                                              if (address<16)
                                                Serial.print("0");
                                              Serial.print(address,HEX);
                                              Serial.println("  !");
                                        
                                              nDevices++;
                                            }
                                            else if (error==4) {
                                              Serial.print("Unknow error at address 0x");
                                              if (address<16)
                                                Serial.print("0");
                                              Serial.println(address,HEX);
                                            }
                                          }
                                          if (nDevices == 0)
                                            Serial.println("No I2C devices found\n");
                                          else
                                            Serial.println("done\n");
                                        
                                          delay(3000);           // wait 5 seconds for next scan
                                        }
                                        

                                        The default address is 0x20. So my idea is to just keep scanning, and if I find a 0x20 Chirp, then I change its I2C address to 0x21 and higher. Repeat as necessary until all 0x20 devices are gone.

                                        The only thing I'm not sure about is if this is possible. If I can pick them off one by one this way.

                                        dbemowskD 1 Reply Last reply
                                        0
                                        • alowhumA alowhum

                                          @dbemowsk Changing the Chirp's I2C address is very easy actually.

                                          #include <I2CSoilMoistureSensor.h>
                                          #include <Wire.h>
                                          
                                          I2CSoilMoistureSensor sensor(0x20);
                                          
                                          // connect the reset pin (5) of the Chirp to a pin on your Arduino. It will create a small reset signal. This tells the chirp it should not be a stand-alone ensor, but an I2C connected one. If it receives I1C data shortyl after a reset (few seconds), then it will understand.
                                          int resetPin = 4;
                                          
                                          void setup() {
                                            pinMode(resetPin, OUTPUT); 
                                            delay(1000);
                                            digitalWrite(resetPin, HIGH);       // sets the digital pin 13 on
                                            delay(100);                  // waits for a second
                                            digitalWrite(resetPin, LOW);        // sets the digital pin 13 off
                                            delay(1000);
                                            Wire.begin();
                                            Serial.begin(9600);
                                          
                                            sensor.begin(); // reset sensor
                                            delay(1000); // give some time to boot up
                                            Serial.print("I2C Soil Moisture Sensor Address: ");
                                            Serial.println(sensor.getAddress(),HEX);
                                            Serial.print("Sensor Firmware version: ");
                                            Serial.println(sensor.getVersion(),HEX);
                                            Serial.println();
                                          
                                            Serial.print("Change address to 0x21 ...");
                                            if (sensor.setAddress(0x21,true)) // set Sensor Address to 0x21 and reset
                                              Serial.println("... DONE");
                                            else
                                              Serial.println("... ERROR");
                                            Serial.println();
                                          }
                                          
                                          /*loop scans I2C bus and displays foud addresses*/
                                          void loop() {
                                            byte error, address;
                                            int nDevices;
                                          
                                            Serial.println("Scanning...");
                                          
                                            nDevices = 0;
                                            for(address = 1; address < 127; address++ ) {
                                              // The i2c_scanner uses the return value of
                                              // the Write.endTransmisstion to see if
                                              // a device did acknowledge to the address.
                                              Wire.beginTransmission(address);
                                              error = Wire.endTransmission();
                                          
                                              if (error == 0) {
                                                Serial.print("I2C device found at address 0x");
                                                if (address<16)
                                                  Serial.print("0");
                                                Serial.print(address,HEX);
                                                Serial.println("  !");
                                          
                                                nDevices++;
                                              }
                                              else if (error==4) {
                                                Serial.print("Unknow error at address 0x");
                                                if (address<16)
                                                  Serial.print("0");
                                                Serial.println(address,HEX);
                                              }
                                            }
                                            if (nDevices == 0)
                                              Serial.println("No I2C devices found\n");
                                            else
                                              Serial.println("done\n");
                                          
                                            delay(3000);           // wait 5 seconds for next scan
                                          }
                                          

                                          The default address is 0x20. So my idea is to just keep scanning, and if I find a 0x20 Chirp, then I change its I2C address to 0x21 and higher. Repeat as necessary until all 0x20 devices are gone.

                                          The only thing I'm not sure about is if this is possible. If I can pick them off one by one this way.

                                          dbemowskD Offline
                                          dbemowskD Offline
                                          dbemowsk
                                          wrote on last edited by
                                          #47

                                          @alowhum That is nice. Some I2C devices have it hard coded and do not allow this from my understanding.

                                          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

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


                                          12

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 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