Work
07 Control Systems 2024

Ultrasonic Water-Level Controller

Closed-loop tank control with a failsafe that is not software.

Team lead · 4 members
ArduinoC++HC-SR04L298NHysteresis
Sensing, display and closed-loop pump control, with the overflow routed clear of the electronics.
Sensing, display and closed-loop pump control, with the overflow routed clear of the electronics.
The finished build. Sensor above the water, electronics clear of the overflow path.
The finished build. Sensor above the water, electronics clear of the overflow path.
Tank
5 L
Accuracy
≈ 0.5 cm
Thresholds
10% on · 90% off
Driver
L298N
The finding

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.

echoIN1, IN2, ENAHC-SR04In the lidArduino UnoEvery 300 msL298NPump driverPump12 VTank10% to 90%ButtonManual top-upI²C LCDLevel, pump state

How it works

  1. Every 300 ms the sensor takes five pings and keeps the median.
  2. The distance becomes a percentage full, clamped to 0-100%.
  3. Below 10% the pump starts, at 90% it stops, and in between it keeps doing whatever it was doing.
  4. A button starts the pump early, but the 90% cut-off always wins.
  5. Five missing echoes in a row stop the pump and show SENSOR FAULT; it recovers on the next good reading.

Hardware

PartWhat it does
Arduino UnoLevel calculation and control
HC-SR04Distance to the water, from the lid
L298NSwitches the 12 V pump rail
Submersible DC pumpFills the tank
16×2 I²C LCDLevel and pump state
Button, rocker switch, 12 V adapterOverride, 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.