Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.
Supplier photo
Temu affiliate offer · Project idea

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

ESP32 Water Probe: Why a Sensor Should Not Stay Powered All Day

Two metal contacts can reveal water because ordinary tap water conducts electricity. But leaving a direct-current probe energized continuously also encourages electrochemical changes at the contacts. This experiment applies a short measuring pulse and spends most of its time with the drive turned off. You can observe the tradeoff between sampling interval, sensitivity and electrode exposure.

The current path

GPIO means general-purpose input/output. GPIO25 drives electrode A through 100 kΩ. Water adds a variable resistance between electrodes A and B. A 1 MΩ pull-down connects electrode B to ground, and GPIO34 measures the resulting voltage. An ADC, or analog-to-digital converter, converts that voltage into a number. The sensor branch stays entirely within the board’s 3.3 V logic supply.

With a dry gap there is almost no conducting path and the pull-down keeps SENSE low. With water bridging the gap, SENSE rises by an amount depending on conductivity, spacing and immersed area. For an illustrative 100 kΩ water path, the ideal midpoint is 3.3 × 1,000/(100 + 100 + 1,000) = 2.75 V. Treat that as a circuit calculation, not a prediction for your particular water.

Parts to gather

  • Classic ESP32-DevKitC V4 / ESP32-WROOM-32 with MicroPython 1.26
  • Two separate stainless-steel electrodes held a few millimetres apart
  • 100 kΩ resistor, 1 MΩ resistor, 680 Ω resistor and red LED
  • Shallow plastic tray, a little tap water and dry supports for the electronics
ESP32 Water Probe: Why a Sensor Should Not Stay Powered All Day. GPIO25 → 100 kΩ → electrode A Electrode B → SENSE → GPIO34 SENSE → 1 MΩ → GND GPIO26 → 680 Ω → LED anode; cathode → GND
Original Tricky Circuit connection diagram. Nominal values are calculated; this build has not been physically tested.

Complete connections

ConnectionPurpose
GPIO25 → 100 kΩ → electrode AThis is the pulse source and current-limiting path.
Electrode B → SENSE → GPIO34Water bridges the two electrodes; they do not touch.
SENSE → 1 MΩ → GNDThe pull-down creates a low dry reading.
GPIO26 → 680 Ω → LED anode; cathode → GNDBoard powered by USB; keep it and the cable outside the tray.

Why pulse the probe?

The 100 kΩ series resistor bounds drive current below approximately 3.3/100,000 = 33 µA even if a downstream fault bypasses the normal pull-down. During an ordinary near-zero-resistance wet bridge, the 1 MΩ pull-down also remains in series, giving only about 3 µA. High resistance makes the measurement sensitive to interference and input loading, so the program uses a settling interval and the median of several readings.

About 98 ms of nominal active time in a roughly five-second cycle is around a 2% duty fraction, plus interpreter overhead. Duty fraction means the portion of time the source is on. Reduced exposure may reduce corrosion; it does not eliminate it, and this circuit does not reverse polarity. For continuous conductivity instrumentation, the Analog Devices reference uses alternating excitation with very low direct-current offset to address polarization. Our short, pulsed demonstration retains a direct-current component and does not claim that protection.

Calibrate the actual tray

  1. Run the program with WET_ON and DRY_OFF left as None. It prints raw readings while keeping the LED off.
  2. Keep the electrodes separated and dry. Record the stable raw range.
  3. Add just enough tap water to bridge the gap. Record the wet range. Keep all board electronics outside the water.
  4. If there is a clear gap, choose DRY_OFF above the dry range and WET_ON below the wet range, with DRY_OFF smaller than WET_ON. Enter the two measured thresholds and restart.
  5. Remove and dry the electrodes. Verify that the indication clears. Residue may keep the reading elevated; clean the contacts and compare.

Complete MicroPython program

"""Conductivity demo, NOT flood protection. ESP32 GPIO25 drives via 100k.
Second electrode -> GPIO34, with 1M to GND. Never apply external voltage.
"""
WET_ON = None   # set after measuring dry and wet readings
DRY_OFF = None

def decision(raw, wet, wet_on, dry_off):
    if wet_on is None or dry_off is None:
        return False
    if not 0 <= dry_off < wet_on <= 65535:
        raise ValueError("Require 0 <= DRY_OFF < WET_ON <= 65535")
    if raw >= wet_on:
        return True
    if raw <= dry_off:
        return False
    return wet

def main():
    from machine import Pin, ADC
    from time import sleep_ms
    drive = Pin(25, Pin.OUT, value=0)
    adc = ADC(Pin(34)); adc.atten(ADC.ATTN_11DB)
    led = Pin(26, Pin.OUT, value=0)
    wet = False
    decision(0, False, WET_ON, DRY_OFF)
    try:
        while True:
            drive.on()
            try:
                sleep_ms(80)
                samples = []
                for _ in range(9):
                    samples.append(adc.read_u16()); sleep_ms(2)
                raw = sorted(samples)[4]
            finally:
                drive.off()
            wet = decision(raw, wet, WET_ON, DRY_OFF)
            led.value(wet)
            print("raw=%d wet=%s calibrated=%s" % (raw, wet, WET_ON is not None and DRY_OFF is not None))
            sleep_ms(4900)
    finally:
        drive.off(); led.off()

if __name__ == "__main__":
    main()

Test the misleading cases

Distilled water may conduct too weakly to reach your threshold. A finger, damp residue or ionic contamination can conduct more strongly than expected. Try spacing the electrodes farther apart and explain the changed reading before recalibrating. The ESP32 ADC here provides a threshold signal, not a calibrated water-resistance meter.

Unplug electrode A and the circuit will look dry. A broken wire is therefore indistinguishable from a clean dry tray in this simple topology. The program’s finally blocks turn off drive when a software exception or normal interruption unwinds the loop, but they cannot guarantee shutdown after every possible hardware failure. This is a conductivity demonstration, not flood protection. Do not attach it to a pump, mains appliance or unattended water-supply control.

Challenge: does doubling the five-second interval improve detection?

It reduces how often you sample and the average energized time, but a new wet event can wait longer before the next sample. Better electrode life and faster detection are separate design goals that must be balanced.

Sources and related learning

Explore the Tricky Circuit interactive lessons. This article presents a design and software checks; no physical build results are claimed.

📡Broadcast the signal — amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu

Supplier photo of an assembled two-wheeled line-following car with a blue circuit board, two motors and an empty battery holder.

Supplier product photo

Build a line-following car

Soldering and assembly required. Check battery and track requirements before buying.

View kit on Temu