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 Arduino
Arduino 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 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); // 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
Servo motor Interfacing and Control using Arduino
In this article, we will learn how to interface and control servo motors using Arduino Uno R3. 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 t
3 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
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
How to Use Proximity Sensor in Android?
Proximity Sensor is one of the sensors present in mobile devices which we use almost every day. This sensor is present in the top section of your phone. The sensor is used to detect the presence of any object in the proximity of the phone. This sensor is used in many calling apps when the user keeps
3 min read
Ultrasonic Sensor Vs IR Sensor
Arduino is a microcontroller that requires sensors to sense the surroundings to process and react to it. Ultrasonic Sensor is an electronic device that measures the distance between the transmitter and the obstetrical using ultrasonic sound waves. It converts the sound reflected sound into an electr
6 min read
Arduino - Water Detector / Sensor
Sensors are widely used for detecting different quantities like the presence of light, level of water, etc. One such example of a sensor is the water sensor which uses various principles of physics to detect the presence of water. This sensor is known for detecting different water levels with accura
8 min read
Create a Real Time Currency Converter app using Flask | Python
Prerequisite: installation of PythonWhat is Flask in Python ? Flask is a popular and lightweight Python web framework, meaning it is a third-party Python library used for developing web applications. Project Setup : create a new directory and name it 'CURRENCY-CONVERTER'. mkdir CURRENCY-CONVERTER
8 min read
Arduino - Ultrasonic Sensor
Sensors are widely used for detecting devices by approximating their distance from the source. One such example of a sensor is the HC-SR04 ultrasonic sensor which uses the SONAR technique for the sensing purpose. The main feature of this sensor is to mimic the nature of bats and therefore predict th
7 min read
Test Cases For Signup Page Using C Language
Prerequisite: Structure in C In this article, we are going to check on how to check test cases for the signup page using C language. The signup page is where we enter data to create our account on any of the websites or applications. A test case is a document that contains various sets of data, cond
6 min read