Back to Hub | RP2040 MicroPython Lab
Relay & DC Pump: OFF

ðŸŒą Real-Time Soil Evaporation & 25% Cooldown Hysteresis

When soil moisture drops below $25\%$, the RP2040 relay triggers the $5\text{V}$ pump. Once it re-hydrates to $25\%$, the relay turns OFF and enforces a **10-second lockout delay** to prevent relay jittering[cite: 1]!

ðŸŠī Soil Bed, Relay Terminals & Submersible DC Motor
Moisture: 30.0% (Soil Adequate)
WATER RESERVOIR 5V DC PUMP + - Capacitive Probe 5V RELAY SRD-05VDC NO COM NC LED Relay NO -> DC Pump (+) RP2040 MCU 3V3 ── VCC GP26 ── ADC GND ── GND GP16 ── RELAY AOUT: 2.46 V ADC0: 3058 / 4095
🎛ïļ Dynamic Evaporation & 10s Cooldown Controls
30.0 %
0% (Bone Dry / 3.0V) 25% (Trigger & Stop Point) 100% (Saturated / 1.2V)
📊 Inverse Capacitive Signal Physics 3.0V = Dry â€Ē 1.2V = Wet

Capacitive soil sensors output an INVERSE analog voltage: higher soil water permittivity lowers capacitance impedance, producing a lower output voltage!

1. Sensor Output Voltage ($V_{out}$):
$V_{out} = 3.0\text{V} - (\text{Moisture} \times 1.8\text{V}) =$ 2.46 V
2. RP2040 12-Bit ADC & 16-Bit Register:
ADC_12bit = 3058  |  duty_u16 = 48935
3. Relay Contact & Cooldown Status:
Relay = OPEN | DC Motor = IDLE
🐍 MicroPython Hysteresis Controller RP2040 Executing
import machine, time
soil_adc = machine.ADC(machine.Pin(26))
relay = machine.Pin(16, machine.Pin.OUT)
cooldown_until = 0 # Lockout timestamp

while True:
  raw = soil_adc.read_u16() # 48935
  now = time.time()

  if moisture < 25.0 and now >= cooldown_until:
    relay.value(1) # Relay ON -> Pump Active
  elif moisture >= 25.0 and relay.value() == 1:
    relay.value(0) # Relay OFF at 25%
    cooldown_until = now + 10 # 10s Lockout
  time.sleep(1)
📝 Soil Moisture & Relay Logic Quiz
Why does a capacitive soil sensor's analog voltage DECREASE as the soil becomes wetter?