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.

Carte
Nano 33 BLE · Arduino
Difficulté
Difficile
Thème
Applied Integration
Accès
Gratuit

La tâche

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. Serial is 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()).

  1. Start-up. Open Serial1 at 115200 baud, pump and fault LED off, floats with pull-ups. Take the floats' current readings as they are, then print READY and apply the restart rule (below).
  2. 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.
  3. 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.
  4. 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).
  5. Messages. Print PUMP ON / PUMP OFF when the filling or restart rule switches the pump.
  6. 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, print FAULT CLEARED, fault LED off, and apply the restart rule.
  7. 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.
  8. Never block with delay() (a 1 ms pause in setup() 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

  1. The sketch builds.
  2. The pump fills from the low float to the high float and keeps its state in between.
  3. A sloshing float does not switch the pump.
  4. An impossible reading stops the pump with a fault that clears by itself; a dry run stops it for good.

Ce que vous obtenez

  • Votre firmware est compilé et exécuté sur une carte émulée, puis vérifié par des tests matériels.
  • Aucune carte de développement ni toolchain locale requise.

Débutant en embarqué ? Commencez par la feuille de route : Apprendre les systèmes embarqués (en anglais)