Almost all of you have at least a plant, or a garden and how many times did you forget to wet them.
With this sensor you can observe when the soil is dry, or with a buzzer or a LED arduino can “tell” you this situation.
This sensor is very easy to connect to arduino. It can be connected throught the analog pin or digital pin as you can see in the picture below(right).
It has 4 pins
VCC-to 5V arduino
GND-to GND arduino
D0-any digital pin on arduino(we choose D2)
A0-any analog pin on arduino(we choose A0)
In the image below you can see it connected to digital pin 2:
As function principle are two electrodes isolated one from another and when between them is some material(soil) a small current flows from one to another depending the level of humidity.
Let’s see how it work. First connect VCC and GND.
Through the D0 pin, the sensor give 5 volts(HIGH) when it is no humidity and 0(zero) volts at some relative humidity. Why relative?? Because a threshold value can be adjust with the potentiometer. So adjust a value at a specific level of moisture you want and, until the sensor reach that level the D0 has 5 volts, when it reach it drop to zero.
Through the A0 pin, the arduino reads values between 0 an 1023(0 an 5 volts), depending the level of humidity . These level can be read in serial monitor and shown on display.
Best part of these sensor is that it work with only one wire(analog or digital). If you connect it to arduino through the digital pin you can connect 20 sensors(analog pins from arduino can work as digital pins ). With anlog pins only six.
The best part if you connect it with a display is that you can see what plant need water and wet it, or you can make a automatic distribution sistems with valves to wet them automaticaly.
We have used a 20×4 LCD display which is connected to arduino like in this tutorial.
The program with analog pin and serial monitor is below or can be downloaded from here:
int sensorPin = A0; // select the input pin for sensor
int ledPin = 13; // select the pin for the LED or pump or valve
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);// to see the values in the serial monitor
pinMode(ledPin, OUTPUT);// declare the ledPin as an OUTPUT
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);// display the values in serial monitor
if (sensorValue>=600){// soil is dry
digitalWrite(ledPin, HIGH);// you can connect here through a relay a pump or a
//electric valve, or a buzzer
}
else{// if soil is humid the led or pump or valve is off
digitalWrite(ledPin, LOW);
}
}
The program for analog pin and a 20×4 LCD display can be downloaded from here:
The program with digital pin is below or can be downloaded from here:
int sensorPin =2; // select the input pin for sensor
int ledPin = 13; // select the pin for the LED or pump or valve
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT);// declare the ledPin as an OUTPUT
pinMode(sensorPin, INPUT);// declare the sensorPin as an INPUT
}
void loop() {
// read the value from the sensor:
sensorValue = digitalRead(sensorPin);
if (sensorValue==HIGH){// soil is dry
digitalWrite(ledPin, HIGH);// you can connect here through a relay a pump or a
//electric valve, or a buzzer etc
}
else{// if soil is humid the led or pump or valve is off
digitalWrite(ledPin, LOW);
}
}
Please let us in the comment zone any suggestions that you think will improve the article!
If you like the article click the follow button from social media to stay in touch with us!
A small video with the sensor and the 20×4 LCD display is:


