Soil Moisture measurement using Arduino and Soil Moisture Sensor
Last Updated :
30 Apr, 2024
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 ArduinoArduino code for Analog Reading (output in the serial monitor):
C++
void setup()
{
// Set the serial monitor baudrate to 9600
Serial.begin(9600);
}
void loop()
{
// Variable to store ADC value ( 0 to 1023 )
int level;
// analogRead function returns the integer 10 bit integer (0 to 1023)
level = analogRead(0);
// Print text in serial monitor
Serial.println("Analog value:");
// Print analog value in serial monitor
Serial.println(level);
}
Simulation Output Tinkercad:
Soil Moisture sensor analog readingAnalog 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 CircuitLevel 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); // Set the serial monitor baudrate to 9600
pinMode(13, OUTPUT); // Output LED Level 1
pinMode(12, OUTPUT); // Output LED Level 2
pinMode(11, OUTPUT); // Output LED Level 3
pinMode(10, OUTPUT); // Output LED Level 4
pinMode(9, OUTPUT); // Output LED Level 5
}
void loop()
{
// Variable to store ADC value ( 0 to 1023 )
int level;
// analogRead function returns the integer 10 bit integer (0 to 1023)
level = analogRead(0);
// Print text in serial monitor
Serial.println("Analog value:");
// Print output voltage in serial monitor
Serial.println(level);
// Turn off All LEDs
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
// output of sensor varies from 0 to 4.28 Volts,
// It's equivalent ADC value is 0 to 877 ( (4.28/5)*1024 = 877 )
// Splitting 877 into 5 level => 175, 350, 525, 700, 877
// Based on the ADC output, LED indicates the level (1 to 5).
if (level < 175) {
// LEVEL 1 LED
digitalWrite(13, HIGH);
}
else if (level < 350) {
// LEVEL 2 LED
digitalWrite(12, HIGH);
}
else if (level < 525) {
// LEVEL 3 LED
digitalWrite(11, HIGH);
}
else if (level < 700) {
// LEVEL 4 LED
digitalWrite(10, HIGH);
}
else if (level < 876) {
// LEVEL 5 LED
digitalWrite(9, HIGH);
}
}
Output:
Applications:
- Agricultural and Horticultural research purposes.
- Climate research
- Irrigation planning
Similar Reads
Distance measurement using Ultrasonic sensor and Arduino In This Article, We will learn how to measure the distance using an Ultrasonic sensor & Arduino. Arduino:It is an open-source electronics platform. It consists ATmega328 8-bit Microcontroller. It can be able to read inputs from different sensors & we can send instructions to the microcontrol
7 min read
Crop Recommendation System using TensorFlow In this tutorial, we will make a recommendation system that will take in the different environmental attributes such as the nitrogen, phosphorous, potassium content in the soil, temperature, etc., and predict what is the best crop that the user can plant so that it survives in the given climatic con
8 min read
Smart SunLight detection using Arduino In our daily technological advancements we should utilize the renewable sources like sun ,wind, water etc. Particularly for the solar energy the operations and applications are huge. For the applications of solar energy we should monitor and optimize the solar powered systems using these types of em
8 min read
Force Sensitive Resistor ( FSR ) with Arduino In this article, we will learn about Force sensors and the measurement of force sensors using 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 microcontrol
3 min read
How to make Motion Detection System using Arduino? Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards can read digital & analog inputs from the sensors and The PIR sensor is a special type of sensor which is usually used for security purposes. It detects the objects by reading the Infrared r
2 min read
Smart Collision Detector using Arduino Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards can read digital & analog inputs from the sensors and the HR SC-04 Ultrasonic sensor uses sonar to find the distance between objects. It can measure distances ranging from 2cm to 400cm with
4 min read