Smart Gardening: How to Interface a Soil Moisture Sensor with Arduino
From smart homes to smart cities, our world is getting a massive upgrade in intelligence. But why stop at your doorstep? Your plants deserve some brainpower too! Whether you are looking to build an automated agricultural system or just trying to keep your favorite backyard fern alive, a smart irrigation system is the way to go.
At the heart of any smart garden lies its backbone: the Soil Moisture Sensor. This handy component measures how dry or wet the soil is, ensuring your plants get the exact amount of water they need.
In this guide, we will break down how a soil moisture sensor works and provide a step-by-step tutorial on interfacing it with an Arduino using both analog and digital modes.
Hardware Breakdown
A typical soil moisture sensor setup consists of two main parts:
1. The Probe
This component features two fork-shaped, exposed conductors that are dipped directly into the soil. It acts as a variable resistor whose value changes based on the water content in the soil.

2. The LM393 Driver Module
The probe connects to this small electronic board, which interfaces directly with your Arduino. It features:
-
An Analog Output (A0) to give you real-time, granular moisture levels.
-
A Digital Output (D0) that triggers when a specific moisture threshold is met.
-
A Built-in Potentiometer (the small blue dial) to manually adjust that digital threshold.

Technical specification:
- Operating voltage: 3.3v- 5v
- Operating current: <20 mA
- Interfacing type: Analog/ Digital
- Operating temperature: 10-40˚C
- Output value: In humid soil- (900-700), In water – (700 -300)
How It Works
The working of the soil moisture sensor is quite simple. The soil moisture sensor consists of two probes that are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value. When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
Interfacing of Arduino
The soil sensor comes with both analog and digital output pins, which means we can obtain output in both forms (analog/digital). So it can be interfaced in a two way with Arduino.
Let us see analog one first
Calibration:
For getting the accurate result I first recommend you to calibrate the sensor value with the help of potentiometer, Different types of soil can affect the sensor, so your sensor may be more or less sensitive depending on the type of soil you use.
What is LM393?
The LM193-N series consists of two independent precision voltage comparators with an offset voltage specification as low as 2.0 mV max for two comparators which were designed specifically to operate from a single power supply over a wide range of voltages. These comparators also have a unique characteristic in that the input common-mode voltage range includes ground, even though operated from a single power supply voltage.
Application areas include limit comparators, simple analog to digital converters; pulse, square-wave and time delay generators, wide range VCO, MOS clock timers, multi-vibrators, and high voltage digital logic gates. The LM193-N series was designed to directly interface with TTL and CMOS. When operated from both plus and minus power supplies, the LM19-N series will directly interface with MOS logic where their low power drain is a distinct advantage over standard comparators.
Interfacing in Analog Mode

In the above diagram, the A0 pin of the LM393 module is connected with the A0 pin of Arduino.The sensor is connected to Electronic module (LM393) which connects the probe to Arduino
As it is seen in the image the pin is connected to 5v of Arduino, GND is connected to GND of Arduino, and A0 pin of comparator module LM393 is connected to the A0 pin of Arduino.
| Soil Sensor | Arduino |
| VCC | VCC |
| GND | GND |
| A0 | A0 |
Arduino Sketch For Analog Reading:
const int Soil_Sensor = A0;
int Moisture_val = 0;
void setup() {
Serial.begin(9600);
pinMode(Soil_Sensor , INPUT);
Serial.println("*************Soil Mositure Reader*****************");
Serial.println("Reading data from sensor............................");
}
void loop() {
Moisture_val = analogRead(Soil_Sensor);
Moisture_val = map(Moisture_val, 0, 1023, 100,0);
Serial.print("Moist_level: ");
Serial.print(Moisture_val);
Serial.println(" %");
delay(500);
if (Moisture_val < 50) {
Serial.println("Soil is Dry, Water it");
}
else {
Serial.println("Moisture level is normal");
}
}
Analog Output:

Interfacing In Digital Mode
Calibration
The module has a built-in potentiometer for calibrating the digital output (DO). By turning the knob of the potentiometer, you can set a threshold.
Now to calibrate the sensor, insert the probe into the soil when your plant is ready to be watered and adjust the pot clockwise or anticlockwise according to glow LED when the moisture level is low. So that users can understand the status of the soil.

While from the previous example you have to do the same connection except connect D0 pin of the module to pin 13 of Arduino.
| Soil Sensor | Arduino |
| VCC | VCC |
| GND | GND |
| D0 | 13 |
Arduino Sketch For Digital Reading:
const int Soil_Sensor = 13;
int Moisture_val = 0;
void setup() {
Serial.begin(9600);
pinMode(Soil_Sensor , INPUT);
Serial.println("************Soil Mositure Reader*************");
Serial.println("Reading data from sensor.......");
}
void loop() {
Moisture_val = digitalRead(Soil_Sensor);
Serial.print("Moist_Status: ");
Serial.println(Moisture_val);
delay(500);
if(Moisture_val== 1)
{
Serial.println("Moisture level is low");
delay(100);
}
else{
Serial.println("Enough moisture content in Soil");
delay(100);
}
}

Wrap-Up & Next Steps
With just a few lines of code and a budget-friendly sensor, you've successfully given your plants a voice!
To take this project to the next level, you can easily connect a 5V Relay Module and a mini water pump to the Arduino. That way, instead of just printing a warning to your computer screen, your system can automatically turn on a pump and water the plant itself!
What extra features would you add to this smart garden setup? An LCD screen? A Wi-Fi module for smartphone alerts? Let your imagination grow, and leave your thoughts in the comment section below!