A plant monitor is useful only if its numbers have a meaning. A cheap soil sensor cannot know your potting mix, insertion depth or definition of “needs water.” This project records two references from your own pot and turns the span between them into a relative wetness scale. A small light then reminds you to inspect the plant.
What the sensor actually measures
The SEN0193 uses capacitive sensing: material around its electrode changes an electrical property called capacitance. Its electronics convert that response into an analog output. Soil composition, packing, salts and probe position can change the result along with water. The manufacturer’s documented supply includes 3.3 V and its nominal output stays below the supply, so this example powers the specified sensor from 3.3 V. A visually similar unmarked module is not automatically equivalent.
An ADC, or analog-to-digital converter, turns that output into a number. GPIO34 is an input on the classic ESP32. With 11 dB attenuation selected, the program uses relative raw readings, not a claim that the ESP32 is a calibrated voltmeter. No wireless connection is needed.
Parts to gather
- Classic ESP32-DevKitC V4 / ESP32-WROOM-32 board with MicroPython 1.26
- DFRobot SEN0193 capacitive soil sensor, original documented version
- Red LED, 680 Ω resistor, jumper wires and a pot of soil

Complete connections
| Connection | Purpose |
|---|---|
| SEN0193 VCC → ESP32 3V3; GND → GND; analog OUT → GPIO34 | Use the sensor connector labels, not an assumed wire color. |
| GPIO26 → 680 Ω → LED anode; cathode → GND | An indicator reminder only; no pump is connected. |
| Board powered through USB | Probe supply and signal share the ESP32 ground. |
Make two reproducible reference conditions
- Start with DRY_RAW and WET_RAW set to None. The program prints readings while keeping the reminder off.
- Insert the probe to a marked depth in the chosen potting mix. Record a stable reading at a condition you judge sufficiently dry for that plant. Do not damage a plant to reach an extreme reference.
- Water the pot normally, allow drainage and redistribution, then record a second stable reading with the probe in the same place. Keep the connector and upper electronics dry; the sensing blade is not permission to immerse the entire board.
- Enter those values in the two constants. The documented sensor normally gives a lower output when wetter. This program requires DRY_RAW − WET_RAW to be at least 2,000 counts; if not, inspect supply, placement and separation between the chosen references.
For example, dry = 48,000, wet = 30,000 and current = 39,000 gives 100 × (48,000 − 39,000)/(48,000 − 30,000) = 50. Those are arithmetic examples, not suggested calibration values. “50” means halfway between your references. It does not mean 50% water by volume or relative air humidity.
Complete MicroPython program
"""Classic ESP32 + DFRobot SEN0193, supplied at 3.3 V; OUT -> GPIO34."""
DRY_RAW = None # replace both None values with YOUR calibration results
WET_RAW = None
def relative_wetness(raw, dry, wet):
if dry is None or wet is None:
return None
if dry - wet < 2000:
raise ValueError("Dry reading must exceed wet reading by >= 2000")
return max(0.0, min(100.0, 100.0 * (dry - raw) / (dry - wet)))
def next_reminder(percent, was_dry):
if percent is None:
return False
if percent < 25:
return True
if percent > 40:
return False
return was_dry
def main():
from machine import ADC, Pin
from time import sleep_ms
adc = ADC(Pin(34)); adc.atten(ADC.ATTN_11DB)
led = Pin(26, Pin.OUT, value=0)
reminder = False
relative_wetness(0, DRY_RAW, WET_RAW) # reject invalid calibration at boot
try:
while True:
samples = []
for _ in range(21):
samples.append(adc.read_u16()); sleep_ms(10)
raw = sorted(samples)[10]
value = relative_wetness(raw, DRY_RAW, WET_RAW)
reminder = next_reminder(value, reminder)
led.value(reminder)
print("raw=%d relative_wetness=%s reminder=%s" % (raw, value, reminder))
sleep_ms(2000)
finally:
led.off()
if __name__ == "__main__":
main()
A stable reminder
The program sorts 21 readings and uses the middle one, called the median, to reduce the influence of isolated spikes. The reminder switches on below 25 on the relative scale and clears above 40. Between those values it preserves its previous state. That separation is hysteresis: different thresholds for turning on and off. Adjust both thresholds based on observations of the actual plant; they are not horticultural prescriptions.
The ADC reading is sampled repeatedly, while the indicator is driven through its own resistor. An LED means light-emitting diode. With a red LED near 2 V, the 680 Ω resistor gives roughly 1.9 mA at 3.3 V.
Test failures before trusting the light
Test each calibration reference, then a middle condition. Move the probe slightly and note how much the result changes. Try a deliberately wrong pair of calibration constants: the program should reject reversed or nearly equal references. With no calibration it must print None rather than inventing a percentage.
An unplugged analog sensor may leave a floating input that still gives plausible numbers. This simple circuit cannot prove that the probe is connected; checking that requires a different electrical interface. It also cannot decide whether roots need water from one reading alone. Use the indicator as a prompt to inspect the pot, and retain manual watering for this experiment.
Challenge: why does the code clamp the display to 0–100?
Conditions can go beyond either calibration reference. Clamping makes the display easier to use, but it hides how far beyond the reference the raw reading went. Keep printing raw values so that drift and changed placement remain visible.
Sources and related learning
- DFRobot SEN0193 sensing principle
- DFRobot documented sensor supply and output
- MicroPython classic ESP32 ADC
Explore the Tricky Circuit interactive lessons. This article presents a design and software checks; no physical build results are claimed.



