Water Tank Pump Control
On an Arduino Nano 33 BLE, fill a water tank between two float switches: filter out sloshing, keep the pump off between the floats, catch impossible float readings as a fault, and latch a dry-run fault if no water arrives within ten seconds.
- Placa
- Nano 33 BLE · Arduino
- Dificultad
- Difícil
- Tema
- Applied Integration
- Acceso
- Gratis
La tarea
Water Tank Pump Control
A rooftop water tank is filled by a pump. Two float switches hang in the tank: a low float near the bottom and a high float near the top. Each switch closes when the water lifts it. The controller fills the tank from the low mark to the high mark, and must protect the pump when something is wrong.
Hardware
- Arduino Nano 33 BLE (nRF52840, 3.3 V logic). Serial console on
Serial1(D0/D1), 115200 baud.Serialis USB and is not seen by the tests. - D2: low float, D3: high float. Each closes to GND while it is submerged (wet): with the internal pull-up,
LOW= wet,HIGH= dry. - D4: pump relay input,
HIGH= pump running. - D6: fault LED with a series resistor to GND,
HIGH= on.
Requirements
Write the sketch in sketch/sketch.ino (setup() and loop()).
- Start-up. Open
Serial1at 115200 baud, pump and fault LED off, floats with pull-ups. Take the floats' current readings as they are, then printREADYand apply the restart rule (below). - Settling. Water sloshes. After start-up, a float's new reading is accepted only when it has stayed the same for 200 ms without a change.
- Filling rule. Whenever an accepted reading changes:
- low float dry: pump on (the tank is below the low mark);
- high float wet: pump off (the tank is full);
- otherwise (between the floats): keep the pump as it is.
- Restart rule. At power-on and when a fault clears: pump on unless the high float is wet (fill the tank up to the high mark).
- Messages. Print
PUMP ON/PUMP OFFwhen the filling or restart rule switches the pump. - Impossible reading. High float wet while the low float is dry cannot happen with real water: it is a fault. Print
FAULT, pump off, fault LED on. When the readings agree again, printFAULT CLEARED, fault LED off, and apply the restart rule. - Dry run. If the pump has run for 10000 ms and the low float has not been wet at any moment of this run, the pump is running dry: pump off, fault LED on, print
DRY RUN. This is latched: from then on the pump stays off and the LED stays on until power-off, whatever the floats do. - Never block with
delay()(a 1 ms pause insetup()for the pull-ups is fine).
Example console output:
READY
PUMP ON
PUMP OFF
PUMP ON
FAULT
FAULT CLEARED
PUMP ON
Wiring
Build the circuit in the Wiring tab: the low float between D2 and GND, the high float between D3 and GND, the relay module's IN to D4 (VCC to 3V3, GND to GND), and the fault LED with its series resistor on D6.
Success criteria
- The sketch builds.
- The pump fills from the low float to the high float and keeps its state in between.
- A sloshing float does not switch the pump.
- An impossible reading stops the pump with a fault that clears by itself; a dry run stops it for good.
Qué incluye
- Tu firmware se compila y ejecuta en una placa emulada y se comprueba con pruebas a nivel de hardware.
- No necesitas placa de desarrollo ni toolchain local.
¿Nuevo en embebidos? Empieza por la hoja de ruta: Cómo aprender sistemas embebidos (en inglés)