Soil Moisture measurement using Arduino and Soil Moisture Sensor
In This Article, We will learn how to measure the moisture (water content) in soil using the Moisture sensor & Arduino.
Arduino is an open-source electronics platform. It consists ATmega328P 8-bit Microcontroller. It can be able to read inputs from different sensors & we can send instructions to the microcontroller in the Arduino. It provides Arduino IDE to write code & connect the hardware devices like Arduino boards & sensors.
Soil Moisture sensor:
A soil moisture sensor is used to measure the amount of moisture (Water content) present in the soil. Water monitoring is very important for a few crops. A soil moisture sensor is used to automate the process of monitoring moisture levels in the soil.
Working:
It works based on the conductivity of electricity through moisture in the soil. We know that pure water does not conduct electricity, as well as solid salt in the soil, does not conduct electricity, But they together can conduct electricity. Moisture in the soil having salt content helps to conduct electricity. But it is restricted to conduct a limited amount of electricity based on the amount of water content present in water (Resistance). This resistance helps to sense the amount of water content approximately. If the water content is high, the resistance between probes is low. If the water content is less, the resistance between the two probes is high.
Components Required:
- Soil moisture sensor
- Arduino Uno R3
- 5 x LEDs (Used for Level Indication purposes only)
- 100 Ohm resistor
- Jumper wires
Setup:
- Connect the VCC pin of the sensor to the 5V pin of the Arduino.
- Connect the GND pin of the sensor to the GND pin of the Arduino.
- Connect the SIG (signal) pin of the sensor to the A0 (Analog) pin of Arduino.
- Navigate to Tools in Arduino software and select board and port.
- Verify and compile the code, then upload the code to the Arduino Uno R3 board.
- Monitor the output in the Serial monitor (Set the baud rate as 9600). To open Serial monitor Tools>Serial Monitor or (Ctrl+Shift+M).
Circuit diagram:
Soil Moisture Sensor with Arduino
Arduino code for Analog Reading (output in the serial monitor):
C++
void setup()
{
Serial.begin(9600);
}
void loop()
{
int level;
level = analogRead(0);
Serial.println( "Analog value:" );
Serial.println(level);
}
|
Simulation Output Tinkercad:
Soil Moisture sensor analog reading
Analog value range:
ADC value varies based on the voltage level 0 to 1023.
Arduino UNO R3 can measure the voltage level of 0V to 5V.
for Analog input 0V output will be 0,
for Analog input 5V output will be 1023.
Analog to Digital conversion:
Analog Read output = (Input Voltage / Maximum Voltage ) * 1024
Note: Arduino Uno supports 10-bit ADC, Which means the resolution of the output is 2^10 = 1024.
We can notice that the sensor reading output goes up to a maximum of Analog value: 876.
Here we are applying 5 Volts to the VCC pin of the sensor, For 5 Volts, we are getting a maximum of 4.28 Volts Approximately in the SIG pin (output pin).
Its equivalent ADC value is 876.
Calculation: ( 4.28 / 5 ) * 1024 = 876
So the output varies from 0 to 876.
Note: This range may change based on the hardware manufacturer. Analyze before using the limits.
Demonstrating Moisture level using LEDs
From the Analysis, We got that the output range is 0 to 876. To monitor the moisture level through LED, Use Arduino Digital IO pins to connect the LEDs. Here we are going to use 5 levels. So we need 5 LEDs.
Setup:
- Connect +ve terminal of 1st LED Digital 13 PIN ( Level 1).
- Connect +ve terminal of 2nd LED Digital 12 PIN ( Level 2).
- Connect +ve terminal of 3rd LED Digital 11 PIN ( Level 3).
- Connect +ve terminal of 4th LED Digital 10 PIN ( Level 4).
- Connect +ve terminal of 5th LED Digital 9 PIN ( Level 5).
- Connect -ve terminal of all the LEDs to the GND pin with a Resistance of 100 Ohm.
Circuit Diagram:
Soil Moisture Level Indicator Circuit
Level Indication:
Level |
Analog Value Range |
1 |
0 – 175 |
2 |
175 – 350 |
3 |
350 – 525 |
4 |
525 – 700 |
5 |
700 – 876 |
Arduino code for moisture level Indication using LEDs:
C++
void setup()
{
Serial.begin(
9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
int level;
level = analogRead(0);
Serial.println( "Analog value:" );
Serial.println(level);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
if (level < 175) {
digitalWrite(13, HIGH);
}
else if (level < 350) {
digitalWrite(12, HIGH);
}
else if (level < 525) {
digitalWrite(11, HIGH);
}
else if (level < 700) {
digitalWrite(10, HIGH);
}
else if (level < 876) {
digitalWrite(9, HIGH);
}
}
|
Output:
Soil moisture Level Indicator
Applications:
- Agricultural and Horticultural research purposes.
- Climate research
- Irrigation planning
Last Updated :
02 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...