Ultrasonic Water-Level Controller
Closed-loop tank control with a failsafe that is not software.


A single threshold would let surface ripple flip the pump several times a second. The 80-point deadband is the entire design.
Overview
A closed-loop tank controller: an HC-SR04 measures the water surface from above, an Arduino Uno turns that into a percentage full, and an L298N switches a submersible pump to keep the tank between 10% and 90%. A Basic Electronics mini-project at AITM Bhatkal, guided by Prof. Shrishail Bhat.
Problem
Tanks overflow because nobody is watching them. This one watches its own level and switches the pump on and off by itself.
System
An ultrasonic sensor above the water converts distance to percentage full. Below 10% the pump starts; above 90% it stops. Between those, the controller deliberately does nothing.
How it works
- Every 300 ms the sensor takes five pings and keeps the median.
- The distance becomes a percentage full, clamped to 0-100%.
- Below 10% the pump starts, at 90% it stops, and in between it keeps doing whatever it was doing.
- A button starts the pump early, but the 90% cut-off always wins.
- Five missing echoes in a row stop the pump and show SENSOR FAULT; it recovers on the next good reading.
Hardware
| Part | What it does |
|---|---|
| Arduino Uno | Level calculation and control |
| HC-SR04 | Distance to the water, from the lid |
| L298N | Switches the 12 V pump rail |
| Submersible DC pump | Fills the tank |
| 16×2 I²C LCD | Level and pump state |
| Button, rocker switch, 12 V adapter | Override, isolation, supply |
Software
- The decision logic is two pure functions, distance-to-percent and the pump update, kept apart from the pin I/O.
- Sixteen PC-side checks: the conversion and clamping, the switching points, chatter against a jittering reading, the override against the cut-off, and the fault path.
- A serial log at 9600 baud with the distance, the level and the pump state.
My part
Led the team, split the subsystems, integrated and demonstrated it.
Challenges
Chatter
With one threshold, surface ripple flips the pump several times a second. An 80-point gap between on and off means the level has to travel a long way before the decision reverses.
When the software is wrong
One bad echo or a loose wire and the code is confidently wrong, so the overflow is plumbed to drain away from the electronics. Software covers the bugs you thought of; the plumbing covers the rest.
A lost sketch
The original controller sketch was lost. The current one is a rewrite from the documented design, checked by the tests and clearly labelled as a rewrite.
Result
We demonstrated it working on a 5 L tank. As a backup, the overflow pipe drains away from the electronics in case the control ever fails.
What's next
- Flash the rewrite, calibrate the tank and re-run the demo on hardware.
- Wireless monitoring, a flow sensor and solar power, from the original seminar.