Lessons and the learning game

Water: level, flow, leaks and pumps

Measure and move water with an Uno: float switches, a sonar tank gauge, a flow sensor, leak probes, a pump on a relay, a dry-run guard, a sump controller.

Take the course at /learn/path/water-level-and-flow. It is an intermediate course on the Uno.

Low voltage only. Everything here runs on 5 V and 12 V DC. A mains pump, a mains float switch or anything plugged into the wall is a job for a licensed electrician, with a GFCI and a rated enclosure, never a hobby relay board.

The bench

Each lesson uses the parts it needs: a high float on pin 4 and a low float on pin 5 (to ground, read with INPUT_PULLUP), an HC-SR04 in a tank lid (TRIG 6, ECHO 7), a YF-S201 on interrupt pin 2, the kit water sensor as a leak probe on A0 powered from pin 8, a buzzer on pin 12, and a relay module on pin 10 whose COM and NO contacts switch a 12 V adapter to an R385 diaphragm pump.

The lessons

Float switches. EMPTY, PART and FULL from two floats, a fault for the state that cannot happen, and a float turned over to NC so a broken wire fails safe.

Ultrasonic tank level. Echo time to millimeters to liters in a 400 mm tank, the dead zone, and a hot day: at 35 C a sketch that assumes 20 C reads 3.5 L for 3.0.

YF-S201 flow. 7.5 pulses a second per L/min, 450 a liter, counted with an interrupt, and a batch that closes late because it looks once a second.

Leak probes. Powered for 10 ms a second so the traces last, a buzzer, and a latch for the leak that dried before anyone looked.

Pumps on relays. Why a pin cannot run a pump, a relay switching the pump's own 12 V supply, and a rest time against short cycling.

Dry-run protection. No flow within the priming time, or flow lost, stops the pump until a person retries.

Boss: a sump controller. Two floats as hysteresis, a dry-run guard, a high-water alarm, a maximum run time and a lockout.

The sketches

Sketch What it does
wtxfloat Two floats: EMPTY, PART, FULL and a fault
wtxsonar HC-SR04 tank level in millimeters and liters
wtxflow YF-S201 flow, total and a batch
wtxleak A leak probe powered only to read, with a latch
wtxpump A 12 V pump on a relay, with a rest time
wtxdry The dry-run guard
wtxsump The sump controller

What the simulation leaves out

The parts do not share water: the floats, the flow sensor and the ultrasonic target do not follow the pump, so the lessons ask you to move them as the water would. The water sensor's reading does not change with how conductive the water is, and corrosion is not modeled. Relay contact bounce and arcing are not modeled. The water quality probe (waterprobe) measures TDS, pH and the like rather than whether water is present, so the leak lesson uses the kit water sensor instead.

The float switch, the YF-S201, the water level sensor, the water pump, the relay and the HC-SR04.