Advertisement

Arduino Soil Moisture Sensor Module

AS-1

If you are designing your own intelligent “Graden Computer” with an optional digital plant moisture sensor/water pump controller that lights an LED to alert the user when it is time to water a potted plant, and/or turn on a water pump to quench the thirst, here is an Arduino Primer for you. No doubt, an Arduino can convert your favorite pots into self-watering planters, keeping your plants from drying out and reducing the time you spend watering. Self-watering system is ideal for people frequently on vacation, and takes the guesswork out of watering. Plants draw up moisture as they need it!

Hardware

The hardware is consists of an Arduino microcontroller (here an Arduino Uno R3) and a pre-wired soil moisture sensor module. The soil moisture sensor module , built around the LM393 comparator, gives an active-low (L) level output when the soil is dry (determined by a pre-setted threshold value). This digital output (wet soil → L / dry soil → H) is routed to one I/O terminal (D2) of the Arduino microcontroller. Based on this input (at D2) arduino gives an active-high (H) output through D13 when soil is dry, and an active-low (L) output when soil is wet.

table

soil moisture sensor module

(soil moisture sensor module)

Software

The little “demo” code does just the same as other regular programs. The code controls the LED connected to pin D13 in connection with the input level on Pin D2. D13 output can also be used to enable/disable a water pump/similar controller circuitry.

#define IND_OP 13
#define SEN_IN 2
void setup() {
   pinMode(IND_OP, OUTPUT);
  pinMode(SEN_IN, INPUT);
}
void loop() {
  if(digitalRead(SEN_IN) == HIGH){
    digitalWrite(IND_OP, HIGH);
  } else {
    digitalWrite(IND_OP, LOW);
    delay(1000);
  }
}

Hook Up Note

The +5V supply line (VCC) of the module is linked to the 5V line of the Arduino. GND of the module is the common (0V) connection. The digital signal output to be detected (usually marked as DO in the module) is applied to D2 input of the Arduino. Analog output (marked as AO) from the module is not used here. Sensor-head of the module contains two probes in a small metal pcb. When the sensor-head is inserted in wet soil, mositure bridges the probes through a low-resistance path (when soil is dry, resistance between the probes is also high). A potentiometer is included in the module for adjusting the soil wet/dry detection sensitivity according to actual requirements.

AS-3

Analog Link

It is also possible to read the amount of moisture present in the soil (for judging whether the soil is wet or dry) by linking the analog output (AO) of the module, to one analog input (A0) of the Arduino. Here is the test code that indicates the soil wet/dry conditions using just two LEDs (green & red).

int GLED= 13; // Wet Indicator at Digital PIN D13
int RLED= 12; // Dry Indicator at Digital PIN D12
int SENSE= 0; // Soil Sensor input at Analog PIN A0
int value= 0;
void setup() {
   Serial.begin(9600);
   pinMode(GLED, OUTPUT);
   pinMode(RLED, OUTPUT);
   Serial.println("SOIL MOISTURE SENSOR");
   Serial.println("-----------------------------");
}
void loop() {
   value= analogRead(SENSE);
   value= value/10;
   Serial.println(value);
   if(value<50)
   {
      digitalWrite(GLED, HIGH);
   }
   else
   {
      digitalWrite(RLED,HIGH);
   }
   delay(1000);
   digitalWrite(GLED,LOW);
   digitalWrite(RLED, LOW);
}

Zero – Arduino Try Out

From the circuit diagram of the module, it is clear that, apart from the module only a few external components are needed to build a relay-driver circuit. Yes, there is a chance to realize one simple non-arduino project of a forgetful plant waterer! If you are looking for this option, digital output of the module must be linked to the little circuit shown below, and use an external 5VDC power supply.

AS-4

If higher current loads are to be driven a PNP transistor can be added to the module’s digital output. Here the addition of 2N3906 transistor controls an electro-magnetic relay (RL1) for driving high-current/high voltage loads like water pump motors through its N/C contacts (when soil is wet, relay remains in energized state).

soil moisture sensor experiment

((soil moisture sensor experiment @ author’s lab))

11 Comments

Join the conversation!

Error! Please fill all fields.
  • Hihihi

    Hi, I was just wondering where the battery gets connected to when not using the arduino.

    • onipetre

      Well, you have VCC and GND, so you get your +5V and connect it to VCC, and you get your 0V ( gnd ) and connect it to GND.
      If you have a battery + goes to VCC, – goes to GND
      9V battery must go to a step-down regulator first, so you get something like this

      battery+[9V] -> regulatorVCC -> VCC[5V]
      battery- -> regulatorGND -> GND

  • Shruti sakhare

    Plz give its circuit diagram

  • KRISHNAMOORTHY

    SIR/THANKS FOR YOUR IMMEDIATE REPLY.MY O.S. IS WINDOWS 7.I WILL KEEP IN TOUCH.WITH REGARDS/KRISHNAMOORTHY.

  • KRISHNAMOORTHY

    SIR/I AM A RETIRED ENGINEER/PROFESSOR IN ELECTRONICS FROM CHENNAI.I REGULARLY FOLLOW YOUR ARTICLES.THEY ARE EXELLANT.I RECENTLY DOWNLOADED
    ARDUINO1.6.5.IT DOES NOT OPEN WHEN I TRY TO OPEN.THE ERROR MESSAGE IS
    “YOUR COPY OF THE IDE IS IN A SUB-FOLDER WITHIN THE SKETCH-BOOK.YOU MOVE IT TO SOME OTHER FOLDER.”BY MISTAKE THIS HAS HAPPENED.I REQUEST YOUR HELP IN THIS REGARD.I ALSO REQUEST YOUR E-MAIL ID/AND YOUR PERSONAL MOBILE NUMBER IF POSSIBLE.MY MOBILE NUMBER IS 09940071267.YOU CAN MESSAGE THE SAME/SEND TO MY MAIL ID.WITH REGARDS/KRISHNAMOORTHY.

    • T.K.Hareendran

      @Krishna Moorthy:

      Thanks for your keen interest in my articles.

      Since I’ve no rich experience with Arduino1.6.5 IDE, it takes some time to offer a solution for you. Please stay tuned. I will post related notes here as soon as possible (which operating system you’re using in your computer?).

      Feel free to contact me through Facebook (@tkhareendran), or via email: designlab.technode@gmail.com

  • adrian

    just did this project with the kids worked great. we used a sensor that we bought of ebay and although it is not exactly the same it worked as described. Thank you

  • Howard

    I don’t understand why a build of materials is never included. Where do you get the moisture sensor module?

    • T.K.Hareendran

      Prototype was tested with a soil moisture sensor module,bought from eBay. Will try to add the BOM, starting from next submission!

  • T.K.Hareendran

    In the second paragraph,under the hardware section, please read the line “The soil moisture sensor module , built around the LM393 comparator, gives an active-low (L) level output when the soil is dry (determined by a pre-setted threshold value)”

    as

    “The soil moisture sensor module , built around the LM393 comparator, gives an active-low (L) level output when the soil is wet (determined by a pre-setted threshold value).

    Sorry for the typo!

Looking for the latest from TI?