ESP Projects

Build a soil moisture sensor with an ESP32 and ESPHome

By Ross · Updated November 18, 2026

Disclosure: As an Amazon Associate I earn from qualifying purchases. Links to parts on this page are affiliate links, some through brand partnerships, so I may earn a commission at no extra cost to you. It never changes which parts I recommend.

Capacitive soil moisture sensors cost about $2 and, unlike the older fork-shaped probes, don't corrode in the dirt. Wired to an ESP32 and calibrated properly, they tell Home Assistant exactly when each plant needs water — and can water it for you.

Cost
$10–15
Time
45 minutes
Difficulty
Beginner
Skills
3 wires, waterproofing

Choose the right sensor

Search for "capacitive soil moisture sensor v1.2" and you'll find dozens of near-identical boards. They're not all equal:

  • Check the chip. Good boards use a TLC555 timer chip. Many clones use an NE555, which doesn't work properly at the ESP32's 3.3 V and gives stuck or drifting readings. The chip's marking is printed on top; zoom in on product photos before buying.
  • Avoid resistive probes (two bare metal prongs, often labeled YL-69 or FC-28). They corrode within weeks.

Parts

  • An ESP32 DevKit and USB power supply.
  • One capacitive soil moisture sensor per pot.
  • Clear nail polish or conformal coating, and heat-shrink tubing.

Wiring

Sensor pinESP32 pin
VCC3.3V
GNDGND
AOUTGPIO34

The signal has to go to an ADC1 pin: GPIO32 to 39 on a classic ESP32. The other analog converter, ADC2, stops working when Wi-Fi is on, which in ESPHome is always. The ESP32 safe pin finder lists them; choose "Analog input".

Wiring diagram: Build a soil moisture sensor with an ESP32 and ESPHome
Wiring diagram. Click to open full size.

Waterproof the top

The probe's sensing area is coated, but the electronics at the top and the cut edges of the board aren't. Paint the components and edges with clear nail polish or conformal coating, then slide heat-shrink over the top. Push the probe into the soil only up to the line printed on it.

The ESPHome config

Build this config in the generator Pick your board, adjust pins, and copy a ready-to-flash config with fresh keys.

This reads the raw voltage and turns it into a 0–100% moisture value. Add it to an ESP32 config (the config generator makes the base):

sensor:
  - platform: adc
    pin: GPIO34
    name: "Soil moisture raw"
    id: soil_raw
    attenuation: 12db
    update_interval: 60s
    unit_of_measurement: "V"
    entity_category: diagnostic
  - platform: copy
    source_id: soil_raw
    name: "Soil moisture"
    unit_of_measurement: "%"
    device_class: moisture
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 2.80 -> 0.0
          - 1.20 -> 100.0
      - clamp:
          min_value: 0
          max_value: 100

The 12db attenuation lets the ESP32 read the sensor's full voltage range. The raw sensor is kept as a diagnostic entity, which you need for calibration.

Calibrate it

Capacitive sensors read higher voltage when dry and lower when wet, and every probe is a little different. The two numbers in calibrate_linear are placeholders until you measure your own:

  1. Dry reading: hold the sensor in the air and note Soil moisture raw in Home Assistant. Replace 2.80 with it.
  2. Wet reading: stand the probe in a glass of water up to its line and note the reading again. Replace 1.20 with it.
  3. Install the updated config. The percentage now runs from 0 in air to 100 in water.

Real soil sits in between. Most houseplants want watering somewhere around 30–40% on this scale, but it depends on the plant and the soil mix. Watch the reading for a week: note the value the day you water and the value when the soil feels dry an inch down, and you'll have your plant's thresholds.

Automations

  • Needs water: notify when moisture stays below your threshold for an hour. The hour stops a single low reading from setting it off.
  • Automatic watering: add a relay and a small 5 V pump. Run the pump for a few seconds when moisture is low, then wait at least 30 minutes before checking again — water takes time to soak down to the sensor, and without the wait the pump runs until the pot overflows.

Several plants on one ESP32

A classic ESP32 has six ADC1 pins exposed on most DevKits (GPIO32–36 and 39), so one board can watch six pots within wire's reach. For plants scattered around the house, a Bluetooth plant sensor plus an ESPHome Bluetooth proxy is often tidier.

Frequently asked questions

Are capacitive soil moisture sensors better than resistive ones?

Yes, for anything long term. Capacitive sensors don't expose metal to the soil, so they don't corrode the way the fork-shaped resistive probes do.

How do I calibrate a capacitive soil moisture sensor?

Record the reading in dry air and again with the probe in a glass of water, then map those two readings to 0 % and 100 % in ESPHome.

Can one ESP32 read several soil moisture sensors?

Yes. Each sensor needs its own analog input; on a classic ESP32, use ADC1 pins, because ADC2 can't be read while Wi-Fi is on.

Troubleshooting

SymptomLikely cause and fix
Reading never changesIt is on an ADC2 pin, which stops working with Wi-Fi on. Move it to GPIO32–39.
Readings drift for weeksWater is getting into the electronics at the top. Dry it and seal the edges.
Moisture shows over 100% or below 0%Calibration values are off. Take new dry and wet readings and update them.
Very noisy readingsSet attenuation to 12 dB, add a median filter, and keep the wire short.
Sensor reads wet in dry soilA cheap board with a 662K regulator. Run it on 3.3 V, or buy the TLC555 version.