zeenaixSample page

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

PartQtyNote
ESP32 DevKit V1130 or 38-pin both fine
Capacitive soil sensor v2.01Does not corrode like resistive probes
Jumper wires (F–F)3—

Wiring

Sensor pinESP32 pin
VCC3V3
GNDGND
AOUTGPIO34 (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.