
A Capacitive Soil Moisture Sensor is an advanced version of the traditional resistive soil moisture sensor. Unlike resistive sensors, which corrode easily due to direct exposure to water and soil electrolytes, the capacitive sensor uses capacitance to measure moisture levels. This makes it more durable, accurate, and long-lasting.
When soil is wet, its dielectric constant increases, which changes the capacitance of the sensor. The ESP8266 reads this change as an analog voltage value via its ADC (A0) pin. By using this value, we can monitor soil moisture in real-time and trigger actions such as turning on a water pump or sending data to an IoT platform.
In this tutorial, you’ll learn how to connect a capacitive soil moisture sensor to ESP8266, read moisture values, and display them on the Serial Monitor.

// Capacitive Soil Moisture Sensor with ESP8266
int sensorPin = A0; // Soil moisture sensor output to A0
int soilValue = 0; // Variable to store sensor reading
void setup() {
Serial.begin(115200); // Start Serial Monitor
}
void loop() {
// Step 1: Read analog value (0 - 1023)
soilValue = analogRead(sensorPin);
// Step 2: Print value
Serial.print("Soil Moisture Value: ");
Serial.println(soilValue);
// Step 3: Interpret condition (example thresholds)
if (soilValue > 800) {
Serial.println("Soil is very dry!");
} else if (soilValue > 500) {
Serial.println("Soil is moderately moist.");
} else {
Serial.println("Soil is wet.");
}
Serial.println("-------------------------");
delay(1000); // Read every 1 second
}
Pin Setup
int sensorPin = A0;
The soil moisture sensor analog output is connected to the ADC pin (A0) of ESP8266.
Reading Analog Value
soilValue = analogRead(sensorPin);
Reads soil moisture as a value between 0–1023.
Condition Check
if (soilValue > 800) { ... }
Thresholds categorize soil condition as Dry / Moist / Wet.
Serial Output
Prints real-time readings and conditions on the Serial Monitor.
| Issue | Cause | Solution |
|---|---|---|
| Sensor values unstable | Electrical noise | Add a 0.1µF capacitor between A0 and GND |
| Values always high/low | Wrong wiring | Recheck VCC → 3.3V, GND → GND, OUT → A0 |
| Sensor corroding | Wrong sensor type | Always use capacitive, not resistive |
| ESP8266 resets | Drawing too much current | Ensure stable USB power supply (≥ 500mA) |
Capacitive sensors don’t corrode and give more stable, long-term readings compared to resistive sensors.
It gives an analog voltage (0–3.3V) proportional to soil moisture.
Yes, connect the OUT pin → A0 of ESP8266.
Yes. By adding a relay module, you can turn ON/OFF a pump based on soil moisture levels.
Yes. You can integrate with Blynk, MQTT, or ThingSpeak to log and monitor moisture data online.






