You can read this and other amazing tutorials on ElectroPeak's official website
In this tutorial, you will learn how to use a soil moisture sensor. Practical examples are also provided to help you master the code.
What You Will Learn:- How soil moisture sensors work
- How to use soil moisture sensor with Arduino
The soil moisture sensor consists of two probes that measure the volume of water in the soil. The two probes allow the electric current to pass through the soil and, according to its resistance, measures the moisture level of the soil.
When there is more water, the soil conducts more electricity, which means that the resistance will be less. So the moisture level will be higher. Dry soil reduces conductivity. So, when there is less water, the soil conducts less electricity, which means it has more resistance. So the moisture level will be lower.
There are different types of soil moisture sensor on the market, but their working principal are all similar; so if your sensor is different from the one you see in this tutorial, don’t worry! All of these sensors have at least three pins: VCC, GND, and AO. The AO pin changes according to the amount of moisture in the soil and increases as there is more water in the soil. Some models have an additional base called DO. If the moisture amount is less than the permissible amount (which can be changed by the potentiometer on the sensor) the DO pin will be “1”, otherwise will remain”0″.
Interfacing Soil Moisture Sensor and ArduinoIn this tutorial, we have used the Waveshare Soil Moisture Sensor. It has a detection length of 38mm and a working voltage of 2V-5V. It has a Fork-like design, which makes it easy to insert into the soil. The analog output voltage boosts along with the soil moisture level increases.
CircuitUsing this sensor is quite easy. You connect the AO pin to any analog pin. If your sensor has a DO pin, you can connect it to any digital pin.
/*
Soil Moisture Sensor
modified on 21 Feb 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#define SensorPin A0
float sensorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i <= 100; i++)
{
sensorValue = sensorValue + analogRead(SensorPin);
delay(1);
}
sensorValue = sensorValue/100.0;
Serial.println(sensorValue);
delay(30);
}
For each soil moisture measurement, we took an average of 100 sensor data to make the data more stable and accurate.
Please note that after 10-20 months, the sensor may get oxidized in the soil and lose its accuracy. Therefore you should replace it every year. Since it has a low price and easy setup, it worths the annual replacement.
Related Projects
Comments