16 / 20
Automatic water pump
A level probe and a relay keep a tank between two marks.
Run this experiment →Why it’s here
Lower the level below the low mark, then fill beyond the high mark.
How it works
A level probe and a relay keep a tank between two marks. Hysteresis keeps the previous relay state between the marks and prevents rapid switching. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Lower the level below the low mark, then fill beyond the high mark.
Connections
- GPIO 34 — 3.3V level-probe signal
- GPIO 26 — Relay module input · HIGH=ON
- Low-voltage DC supply — Isolated pump load circuit, common control reference
Example sketch
bool pumping = false;
// Low-voltage teaching pump only. Relay module HIGH=ON, isolated load supply.
void setup() {
pinMode(26, OUTPUT); digitalWrite(26, LOW);
}
void loop() {
int percent = constrain(map(analogRead(34), 0, 4095, 0, 100), 0, 100);
if (percent <= 25) pumping = true;
if (percent >= 80) pumping = false;
digitalWrite(26, pumping);
delay(100);
}Check your understanding
Why use two thresholds?
Show the answer
Hysteresis keeps the previous relay state between the marks and prevents rapid switching.