Description
Soil Moisture Sensor is a popular device in Smart Farm projects or automatic watering systems. It works with Arduino easily, is cheap, and is suitable for learning and experimenting.
Soil Moisture Sensor
Soil moisture sensor is a sensor that detects the moisture level in the soil by measuring the conductivity between the probe legs (similar to measuring the resistance of soil).
Sensors often come with a conversion module that provides both analog and digital pins.
Soil Moisture Sensor Specifications
list
|
details
|
Supply voltage
|
3.3V – 5V
|
Current used
|
About 10mA
|
Output signal
|
Analog (A0) and Digital (D0)
|
Detection range
|
General soil moisture levels
|
structure
|
2 probe legs (ground plug), signal converter board has a threshold adjustment potentiometer
|
The Digital Output will give a HIGH or LOW value according to the threshold we set.
Using with Arduino
Wiring:
Soil Sensor Pin
|
Arduino Pin
|
VCC
|
5V
|
GND
|
GND
|
A0 (Analog)
|
A0
|
D0 (Digital)
|
D2 (if used)
|
Analog code example:
------------------------------------------------------------------------------
int sensorPin = A0;
void setup() { Serial.begin(9600); }
void loop() { int value = analogRead(sensorPin); Serial.print("Soil moisture : "); Serial.println(value);
delay(1000); }
----------------------------------------------------------------------------------------------
The value returned by analogRead() will be between 0–1023.
High value = dry soil
Low value = moist soil
Digital code example:
----------------------------------------------------------------------
int sensorDigital = 2;
void setup() { pinMode(sensorDigital, INPUT); Serial.begin(9600); }
void loop() { int value = digitalRead(sensorDigital);
if (value == LOW) { Serial.println("Moist soil"); } else { Serial.println("Dry soil"); }
delay(1000); }
Additional tips:
-
Do not leave the sensor plugged into the ground for a long time (rust may occur).
-
Use the relay together with a water pump or electric valve to automatically water plants.
-
If you want more accuracy, try using a capacitive soil moisture sensor instead of the regular one (it is more durable and does not rust).