Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Skip to main content

ESP32 Capacitive Soil Moisture: Smart Auto Watering | ShillehTek

June 10, 2026

ESP32 Capacitive Soil Moisture: Smart Auto Watering | ShillehTek
Project

Build an ESP32 capacitive soil moisture smart plant monitor that waters only when dry, supports deep sleep battery life, and can send alerts via ShillehTek.

30 min Beginner to Intermediate5 parts

Project Overview

ESP32 + capacitive soil moisture sensor smart plant monitor: In this project, you will use an ESP32 with a capacitive soil moisture sensor to measure soil moisture and automatically run a pump only when the soil is dry.

ESP32 wired to a capacitive soil moisture sensor for an automatic plant watering system

Resistive soil moisture sensors corrode in weeks because they pass current through the soil. Capacitive soil moisture sensors do not. They measure the dielectric of the soil without metal-to-soil contact, so a single sensor can last years. Pair one with an ESP32 and you have an automatic plant-watering controller that waters only when the soil is actually dry, sends you a notification when the reservoir is empty, and can run for months on a battery.

This guide builds an ESP32-based smart plant monitor around our V1.2 capacitive soil moisture sensor. Add a relay and a small pump and you have full automatic drip irrigation.

  • Time: 30 to 60 minutes (plus calibration testing time)
  • Skill level: Beginner to Intermediate
  • What you will build: An ESP32 reads a capacitive soil moisture sensor and switches a pump through a relay when moisture falls below a threshold.

Parts List

From ShillehTek

External

  • A small 5 V or 12 V submersible pump (3 to 6 W).
  • Silicone tubing for the drip line.
  • A water reservoir (a 1 L bottle works fine).

Note: Power the capacitive sensor from 3.3 V for safe ESP32 ADC readings. The relay module typically needs 5 V on VCC (often available from VIN when the ESP32 is USB powered). If your pump uses external power, share ground where required by your relay module setup.

Step-by-Step Guide

Step 1 - Understand how the capacitive sensor works

Goal: Know what the sensor output means so you can calibrate and map it to a moisture percentage.

Capacitive soil moisture sensor inserted into a plant pot for measuring soil moisture

What to do: The sensor PCB is essentially a capacitor: two copper traces separated by the PCB substrate. Water in the surrounding soil changes the dielectric constant, which the onboard 555-timer circuit converts to a voltage on the AOUT pin.

Dry soil is typically around 3.0 V. Saturated soil is typically around 1.2 V. No metal touches the soil, so there is no electrolysis and no corrosion.

Expected result: You understand that higher ADC readings usually mean drier soil, and lower readings usually mean wetter soil (after calibration).

Step 2 - Wire the ESP32, sensor, relay, and pump

Goal: Connect the sensor to an ESP32 ADC pin and connect the relay to a GPIO pin so the ESP32 can switch the pump.

What to do: Wire the capacitive sensor to the ESP32 using 3.3 V, GND, and one ADC-capable input pin. Then wire the relay module to 5 V, GND, and one GPIO output pin. Finally, route the pump power through the relay contacts.

Wiring reference:

Capacitive Sensor    ESP32
VCC (red)        ->  3.3V
GND (black)      ->  GND
AOUT (yellow)    ->  GPIO34 (ADC1_CH6)

Relay Module     ESP32
VCC              ->  5V (from VIN if powered USB)
GND              ->  GND
IN               ->  GPIO26
Pump+            ->  Relay NO
Pump-            ->  External power -

Expected result: The sensor is powered from 3.3 V and AOUT is connected to GPIO34. The relay input is connected to GPIO26, and the pump power is routed through the relay NO contact.

Step 3 - Calibrate dry and wet readings

Goal: Record your own dry and wet ADC values so your percentage mapping is accurate for your sensor and soil.

Calibrating a capacitive soil moisture sensor by comparing dry air reading versus wet water reading

What to do: Calibration is a 2-minute process you do once:

  1. Hold the sensor in air. Note the ADC reading. This is your dry max.
  2. Submerge the sensing area in a glass of water. Note the reading. This is your wet min.
  3. Define moisture% = map(reading, wet_min, dry_max, 100, 0).

Pick a watering threshold like 30%. Below that, run the pump for 5 seconds. Wait 5 minutes for water to absorb, re-read, and repeat until above threshold.

Expected result: You have two numbers you can insert into code (your DRY_MAX and WET_MIN) and a practical threshold for watering.

Step 4 - Upload the ESP32 sketch

Goal: Read the sensor on GPIO34, convert it to a moisture percent, and switch the pump through the relay on GPIO26.

What to do: Paste the sketch below, replace the calibration values with your own readings, compile, and upload to the ESP32. Then open Serial Monitor to verify the raw ADC and percentage values.

Code:

const int SENSOR = 34;
const int PUMP_RELAY = 26;
const int DRY_MAX = 2800;   // calibrate
const int WET_MIN = 1300;
const int THRESHOLD = 30;   // % moisture

void setup() {
  pinMode(PUMP_RELAY, OUTPUT);
  digitalWrite(PUMP_RELAY, HIGH);  // active LOW
  Serial.begin(115200);
}

void loop() {
  int raw = analogRead(SENSOR);
  int pct = constrain(map(raw, WET_MIN, DRY_MAX, 100, 0), 0, 100);
  Serial.printf("raw=%d pct=%d%%\n", raw, pct);
  if (pct < THRESHOLD) {
    digitalWrite(PUMP_RELAY, LOW);  delay(5000);
    digitalWrite(PUMP_RELAY, HIGH); delay(300000);
  } else {
    delay(60000);
  }
}

Expected result: The Serial Monitor prints the raw ADC value and moisture percentage. When the percentage drops below the threshold, the relay turns on for 5 seconds, then waits 5 minutes before checking again.

Step 5 - Add battery power and deep sleep

Goal: Reduce average power consumption so the monitor can run for months on a battery.

ESP32 powered from an 18650 battery with a charging board for deep sleep operation

What to do: Wake the ESP32 every 15 minutes via esp_deep_sleep_start(). Average current drops to about 1 mA. An 18650 then runs the entire monitor for about 4 months on a single charge.

Expected result: The system checks moisture periodically instead of continuously, greatly extending battery life.

Step 6 - Bonus: WiFi push notifications

Goal: Get a message when watering happens or when the reservoir runs dry.

What to do: Add WiFi plus a small HTTPClient call that POSTs to ntfy.sh whenever you water or when the reservoir runs dry.

Expected result: Your plants can push a notification to your phone when they need attention.

Conclusion

A capacitive soil moisture sensor, an ESP32, and a small relay are all you need to build an automatic watering controller that waters only when the soil is dry. With calibration and a simple threshold, you can avoid overwatering and keep a consistent moisture level for healthier plants.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.