Soil Moisture Monitor using ESP32
Reads a capacitive soil sensor and shows moisture percentage on the serial monitor. A simple first IoT project.
Controller: ESP32Supply: 5 V USBLevel: BeginnerBuild: 2 hoursCost: ~₹600
Block diagram
5 V USB
→ESP32
←Soil sensor (analog)
→Serial monitor
Components
| Part | Qty | Note |
|---|---|---|
| ESP32 DevKit V1 | 1 | 30 or 38-pin both fine |
| Capacitive soil sensor v2.0 | 1 | Does not corrode like resistive probes |
| Jumper wires (F–F) | 3 | — |
Wiring
| Sensor pin | ESP32 pin |
|---|---|
| VCC | 3V3 |
| GND | GND |
| AOUT | GPIO34 (ADC1) |
⚠ Power the sensor from 3V3, not 5V. Use ADC1 pins only — ADC2 stops working when Wi-Fi is on. Match pins by their printed label.
Code
const int SENSOR_PIN = 34;
const int DRY = 3200; // reading in dry air — calibrate
const int WET = 1300; // reading in water — calibrate
void setup() {
Serial.begin(115200);
}
void loop() {
int raw = analogRead(SENSOR_PIN);
int pct = constrain(map(raw, DRY, WET, 0, 100), 0, 100);
Serial.printf("Raw: %d Moisture: %d%%\n", raw, pct);
delay(1000);
}
Calibration
Note the raw value with the sensor in dry air and again in a glass of water. Put those numbers in DRY and WET.