Capacitive Soil Moisture Sensor with ESP8266

Introduction
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.
Components Required
- ESP8266 (NodeMCU / Wemos D1 Mini)
- Capacitive Soil Moisture Sensor (v1.2 or v2.0)
- Jumper Wires
- Breadboard
- USB Cable
Circuit Diagram
- Soil Moisture Sensor VCC β 3.3V
- Soil Moisture Sensor GND β GND
- Soil Moisture Sensor OUT (Analog) β A0

Arduino Code
// 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
}
Step-by-Step Code Explanation
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.
- Dry soil β higher values (~700β900)
- Wet soil β lower values (~200β500)
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.
Output
- Place the sensor in dry soil β Serial Monitor shows “Soil is very dry!”
- Place in slightly wet soil β Shows “Soil is moderately moist.”
- Place in wet soil β Shows “Soil is wet.”
Real-Life Applications
- Smart Irrigation Systems β Automatically water plants when soil is dry.
- Greenhouse Monitoring β Maintain ideal soil moisture for crops.
- IoT Agriculture Projects β Send soil data to dashboards for analysis.
- Home Gardening β Keep potted plants healthy with auto-watering.
- Soil Research β Collect soil moisture data for climate studies.
Troubleshooting
| 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) |
Why use a capacitive soil moisture sensor instead of resistive?
Capacitive sensors donβt corrode and give more stable, long-term readings compared to resistive sensors.
What is the output range of the capacitive sensor?
It gives an analog voltage (0β3.3V) proportional to soil moisture.
Can I connect the sensor directly to A0?
Yes, connect the OUT pin β A0 of ESP8266.
Can this project control a water pump?
Yes. By adding a relay module, you can turn ON/OFF a pump based on soil moisture levels.
Can I send soil data to IoT platforms?
Yes. You can integrate with Blynk, MQTT, or ThingSpeak to log and monitor moisture data online.