Monitoring soil moisture is the single most impactful thing you can do for a smart garden or precision farming setup. A soil moisture sensor tells you exactly when your plants need water — preventing both overwatering (which causes root rot) and underwatering (which stresses crops). In this guide, we compare the two main sensor types, show you how to wire them to an Arduino, and walk through building a complete automatic irrigation system with a relay and water pump.
Table of Contents
Why Monitor Soil Moisture?
In India, water scarcity is a growing concern in agriculture. Studies by the Indian Council of Agricultural Research show that drip irrigation combined with moisture-based scheduling can reduce water usage by 30 to 50 percent while maintaining or improving crop yields. For home gardeners, soil moisture sensors prevent the most common cause of plant death — overwatering. They also eliminate the guesswork of when to water, making gardening accessible even for beginners.
The applications range from small terrace gardens in Mumbai apartments to large-scale greenhouse operations in Maharashtra and Karnataka. Arduino-based soil moisture monitoring is now a popular project for agricultural colleges and Krishi Vigyan Kendras across India.
Sensor Types: Resistive vs Capacitive
There are two fundamentally different technologies used in soil moisture sensors available in the Arduino hobbyist market:
- Resistive sensors measure the electrical resistance between two metal probes inserted in the soil. Wet soil conducts electricity better than dry soil, so lower resistance means higher moisture.
- Capacitive sensors measure the dielectric permittivity of the soil around the probe. Water has a much higher permittivity than air or dry soil particles, so the capacitance of the probe changes with moisture content.
Both give you an analog voltage output that you can read with an Arduino analog pin. However, their long-term performance differs significantly.
Resistive Sensors Explained
The classic resistive sensor — recognisable by its two bare metal fork-shaped probes — is cheap and widely available. The sensor passes a small current through the soil via the two probes and measures the resulting voltage. A comparator on the module converts this to a digital HIGH/LOW output as well, with a trimpot to set the threshold.
Corrosion problem: The biggest drawback of resistive sensors is electrolytic corrosion. Because a DC current flows through the metal probes, electrolysis occurs, and within weeks or months of outdoor use the probes oxidise and corrode, changing the calibration and eventually destroying the sensor. The standard workaround in the maker community is to only energise the sensor for a brief reading (a few milliseconds) rather than keeping it powered continuously — this significantly extends probe life.
Despite this limitation, resistive sensors are perfectly fine for short-term projects, classroom demonstrations, and indoor potted plants where you can replace the sensor periodically.
Capacitive Sensor Advantages
Capacitive soil moisture sensors solve the corrosion problem entirely. The sensing circuit is embedded inside a conformal-coated PCB with no exposed metal in contact with the soil. The sensor measures how the soil changes the capacitance of an internal capacitor, which correlates with moisture content.
Key advantages over resistive sensors:
- No corrosion: No metal electrodes exposed to soil means multi-year outdoor lifespan
- Not affected by soil salinity: Resistive sensors are fooled by high-salt soils (saline soils, fertilised soil) but capacitive sensors are not
- Consistent readings: Stable output over time without recalibration
- Lower power: No DC current through soil means very low power consumption
The analog output range of a capacitive sensor is typically 1.5V (dry) to 3.0V (wet) when powered at 3.3V, or about 2.0V to 3.5V at 5V. You need to calibrate for your specific soil type.
Wiring to Arduino
Both sensor types connect to Arduino the same way:
| Sensor Pin | Arduino Pin |
|---|---|
| VCC | 3.3V or 5V (check sensor spec) |
| GND | GND |
| AOUT (Analog) | A0 |
| DOUT (Digital) | Pin 7 (optional threshold output) |
Important: For resistive sensors to extend probe life, wire VCC through a digital pin (pin 6) rather than directly to Arduino 5V. Power the sensor only for 10 to 100 milliseconds before taking a reading, then turn it off.
Reading Analog Values and Calibration
The analog output of soil moisture sensors is arbitrary — a raw value of 600 means nothing by itself. You need to calibrate for dry and wet extremes with your specific soil type:
const int SENSOR_PIN = A0;
const int POWER_PIN = 6; // for resistive sensors only
// Calibration values — measure these for your soil
const int DRY_VALUE = 850; // sensor reading in completely dry soil
const int WET_VALUE = 380; // sensor reading in saturated soil
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN, LOW);
}
void loop() {
// Power sensor only during reading
digitalWrite(POWER_PIN, HIGH);
delay(10);
int rawValue = analogRead(SENSOR_PIN);
digitalWrite(POWER_PIN, LOW);
// Convert to percentage (0% = dry, 100% = wet)
int moisture = map(rawValue, DRY_VALUE, WET_VALUE, 0, 100);
moisture = constrain(moisture, 0, 100);
Serial.print("Soil Moisture: ");
Serial.print(moisture);
Serial.println("%");
delay(2000);
}
Calibration steps: First, hold the sensor in the air and note the reading — this is your DRY_VALUE. Then place the sensor in a cup of water and note the reading — this is your WET_VALUE. Finally, push the sensor into your actual soil and observe where the reading falls relative to your calibrated range.
Automatic Irrigation System Project
This is the most useful project you can build with a soil moisture sensor — an automatic watering system that turns on a pump only when the soil needs water. You need: Arduino, soil moisture sensor, 5V relay module, and a 12V water pump (or solenoid valve).
const int SENSOR_PIN = A0;
const int POWER_PIN = 6;
const int RELAY_PIN = 8;
const int LED_PIN = 13;
const int DRY_THRESHOLD = 600; // Below this moisture level, water the plant
const int WET_THRESHOLD = 400; // Above this, stop watering
const int DRY_CALIB = 850;
const int WET_CALIB = 380;
bool pumping = false;
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
digitalWrite(POWER_PIN, LOW);
}
int readMoisture() {
digitalWrite(POWER_PIN, HIGH);
delay(10);
int raw = analogRead(SENSOR_PIN);
digitalWrite(POWER_PIN, LOW);
int pct = map(raw, DRY_CALIB, WET_CALIB, 0, 100);
return constrain(pct, 0, 100);
}
void loop() {
int moisture = readMoisture();
Serial.print("Moisture: "); Serial.print(moisture); Serial.println("%");
if (!pumping && moisture < 30) {
// Soil is too dry — start pump
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(LED_PIN, HIGH);
pumping = true;
Serial.println("Pump ON — watering");
} else if (pumping && moisture >= 60) {
// Soil is wet enough — stop pump
digitalWrite(RELAY_PIN, LOW);
digitalWrite(LED_PIN, LOW);
pumping = false;
Serial.println("Pump OFF — soil moist");
}
delay(5000); // Check every 5 seconds
}
The hysteresis approach (turn on at 30%, off at 60%) prevents the pump from rapidly cycling on and off. Connect the relay module input to pin 8, and wire your pump or solenoid valve through the relay’s NO (Normally Open) and COM terminals with an appropriate 12V power supply.
ESP32 Remote Monitoring
For agricultural fields or greenhouse setups where you want to monitor multiple zones from your phone, the ESP32 is ideal. You can send moisture readings to Blynk, Thingspeak, or a custom dashboard. Here is a minimal example using Thingspeak (free tier supports up to 8 channels):
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "YourWiFi";
const char* password = "YourPassword";
const char* API_KEY = "YOUR_THINGSPEAK_WRITE_KEY";
const int SENSOR_PIN = 34; // ESP32 ADC pin
const int POWER_PIN = 25;
const int DRY_CALIB = 3200; // ESP32 12-bit ADC, values differ from Arduino
const int WET_CALIB = 1500;
void setup() {
Serial.begin(115200);
pinMode(POWER_PIN, OUTPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500); Serial.print(".");
}
Serial.println("Connected");
}
void loop() {
digitalWrite(POWER_PIN, HIGH);
delay(10);
int raw = analogRead(SENSOR_PIN);
digitalWrite(POWER_PIN, LOW);
int moisture = map(raw, DRY_CALIB, WET_CALIB, 0, 100);
moisture = constrain(moisture, 0, 100);
String url = "http://api.thingspeak.com/update?api_key="
+ String(API_KEY) + "&field1=" + String(moisture);
HTTPClient http;
http.begin(url);
int code = http.GET();
http.end();
Serial.print("Moisture: "); Serial.print(moisture);
Serial.print("%, ThingSpeak code: "); Serial.println(code);
delay(15000); // ThingSpeak free tier: 1 update per 15 seconds minimum
}
Weatherproofing for Outdoor Use
For permanent outdoor installations in Indian monsoon conditions, weatherproofing is essential:
- Sensor probe: Capacitive sensors are inherently more weatherproof since the electronics are coated. For resistive sensors, use food-grade silicone sealant around the PCB edges.
- Electronics box: House the Arduino and relay in an IP65 waterproof enclosure (widely available at hardware stores for around 100 to 200 rupees).
- Cables: Use UV-resistant outdoor cable. Seal all cable entry points with waterproof cable glands.
- Power: A small 6V or 12V solar panel with a lithium battery pack makes the system completely off-grid — ideal for farms without power connections.
Sensor Comparison Table
| Feature | Resistive Sensor | Capacitive Sensor |
|---|---|---|
| Price | Very low (Rs 30 to 80) | Low (Rs 80 to 200) |
| Corrosion resistance | Poor (months) | Excellent (years) |
| Salinity sensitivity | High (false readings) | Low |
| Output accuracy | Good when new | Good and stable |
| Best for | Indoor, short-term | Outdoor, long-term, agriculture |
Frequently Asked Questions
Q: How deep should I insert the soil moisture sensor?
Insert the sensor to the depth of the root zone of your plant — typically 5 to 15 cm for vegetables and flowers, 15 to 30 cm for shrubs and small trees. Measuring at root depth gives the most relevant reading for plant health.
Q: Can I use one sensor for multiple plants?
You can rotate a single sensor between pots for manual checks, but for automated irrigation you need one sensor per independently watered zone. Using a multiplexer (like the CD74HC4067) you can connect up to 16 analog sensors to a single Arduino.
Q: What moisture level should I water at?
Most vegetables and flowers do best between 40% and 70% soil moisture (calibrated percentage). Water when it drops below 30% and stop when it reaches 60 to 70%. Succulents and cacti prefer drier conditions — water below 15%.
Q: My sensor readings are inconsistent — what is wrong?
For resistive sensors, inconsistency usually means corroded probes — clean with fine sandpaper or replace the sensor. For capacitive sensors, inconsistency is often due to air gaps around the probe — press the sensor firmly into the soil ensuring full contact along its length.
Q: Can I power the sensor from a battery for long-term deployment?
Yes — especially with deep sleep on ESP32 and powering the sensor only during readings. A typical setup drawing 2mA average (with deep sleep every 15 minutes) can run for months on a 18650 lithium cell. Use a capacitive sensor to minimise power even further.
Shop Sensors at Zbotic.in
Find sensors, modules, and components for your next project — fast delivery across India.
Add comment