Input devices

Capacitive soil moisture with ESP32

Look at the chip before you trust this sensor. Good boards use a TLC555 or similar CMOS timer, which works at 3.3 V. Some cheap clones have an NE555, rated down to only 4.5 V, and they behave unpredictably at 3.3 V. If your readings jump around, that small marking may be the reason. Resistive probes corrode quickly; capacitive ones hold up better, which is why they cost a little more.

The output runs backwards: dry soil gives a higher voltage, wet soil a lower one. Forgetting that is the most common bug. There is no true percentage either. Read the sensor in air and in a glass of water, and scale between those two values. Results change with soil type, compaction and supply voltage, and two sensors from the same bag can differ. Recalibrate if you change any of them.

Water kills these boards from the top. Push it in only up to the marked line, since the timer chip and edges above that have no protection. One builder saw readings go wrong after about six months in wet soil, and coating the exposed electronics is a common fix. Powering the sensor from a GPIO only while reading is suggested too, and on a battery it saves energy. On an ESP32 use an ADC1 pin if WiFi is on. LCD Ultra Pro can read an analog pin in a rule and scale it to a range, so a bar can show moisture without code: enter a reversed minimum and maximum, based on your own readings.

Capacitive soil moisture wiring diagram for ESP32
Wiring diagram drawn by LCD Ultra Pro.

Specifications

Supply3.3–5.5 V with a CMOS timer
OutputAnalog, lower when wetter
CalibrationRead in air and in water
Check firstTimer marking: TLC555, not NE555

Power and logic levels

3.3 V: safe to connect directly

Supply3.3 V with a CMOS timer
Signal levelAnalog output stays below the supply
On an ESP32Run it from 3V3 and check for a TLC555. At 5 V, measure the output first.

ESP32 pins, including those on a display board's connectors, work at 3.3 V and are not 5 V tolerant. Modules differ, so if in doubt, measure the signal before you connect it.

Wiring

Capacitive soil moistureConnect toNote
VCC3V3Use a GPIO to power it only while reading
GNDGND
AOUTGPIO 4ADC1 pin

Arduino code

const int AOUT_PIN = 4;
const int DRY = 2800, WET = 1200;     // replace with your own readings

void setup() {
  Serial.begin(115200);
}

void loop() {
  int raw = analogRead(AOUT_PIN);
  int pct = constrain(map(raw, DRY, WET, 0, 100), 0, 100);
  Serial.printf("raw %d  moisture %d %%\n", raw, pct);
  delay(2000);
}

No extra library needed. Compiled for ESP32-S3 with arduino-esp32 3.x. Not yet tested by us on a physical sensor. Change the pins to match your board.

On a display

In LCD Ultra Pro a rule can read an analog pin and scale it, so a bar or label can show moisture without code. Use your own dry and wet readings.

Design a display for Capacitive soil moisture

Boards with a ready connector

Only boards whose connectors we have surveyed. Others may still work on free GPIOs.

Elecrow CrowPanel ESP32 HMI 2.4"GPIO_D port: GPIO 32 (ADC)
Elecrow CrowPanel ESP32 HMI 2.8"GPIO_D port: GPIO 32 (ADC)
Elecrow CrowPanel ESP32 HMI 3.5"GPIO_D port: GPIO 32 (ADC)
LilyGO T-Display (classic) 1.14"Right pin header: GPIO 36 (ADC)36 / 37 / 38 / 39 are input-only
M5Stack AtomS3 0.85"Grove port: GPIO 2 (ADC)
M5Stack M5StickC Plus2 1.14"Grove port: GPIO 32 (ADC)
Sunton ESP32-2432S028R 2.8"GPIO header (P3): GPIO 35 (ADC)GPIO 21 is the display backlight — not usable. GPIO 35 is input-only. No 3V3 pin on P3 (only GND).
Waveshare ESP32-S3-LCD-7BGPIO connector (J8): GPIO 6 (ADC)

Good to know

  • Check for a TLC555 rather than an NE555.
  • Dry reads high, wet reads low.
  • Do not push it past the marked line.
  • The percentage is relative, not absolute.

What it is good for

  • Plant and greenhouse monitors
  • Watering controllers with a relay
  • Garden dashboards

FAQ

Why do the readings look backwards?

This sensor gives a lower voltage when wetter. Reverse the mapping.

Why are readings unstable at 3.3 V?

The board may have an NE555. Check the chip marking.

How long does it last in soil?

Protect the top edge, as water getting in is the main cause of failure.

Sources

Related parts

Use this information at your own risk. It is for general guidance only: the example code compiles, but it has not been tested on every part, and modules differ between sellers. Check the manufacturer's data before you build. Product names belong to their owners, and LCD Ultra Pro is not affiliated with them. See our Terms.