The water tank pump that stopped cycling: hysteresis with one D flip-flop
Final project for the Digital Systems practicum, 2026
A water pump at home that is operated by a manual switch has two common failure modes: someone forgets to turn it off and the tank overflows, or someone forgets to turn it on and the tank is empty when water is needed. The simplest-looking fix is to install a single water-level sensor and let it turn the pump on when the water is low and off when the water is high.
The trouble appears right around the sensor threshold. The water surface is never still; ripples and small waves make the sensor alternate between wet and dry within seconds. The pump switches on and off repeatedly. The pump motor was not designed for cycles that fast, and the electricity bill goes up with it.
What the system needs is a memory of what the pump is currently doing. If the pump is filling, let it fill until the tank is full. If the pump is waiting, let it wait until the tank is truly empty. This behaviour is called hysteresis, and in a digital system one flip-flop is enough to implement it.
Two sensors, two states, one variable
Our Digital Systems practicum final project used two sensors: A at the top of the tank and B at the bottom. A value of 1 means the sensor is wet, 0 means dry. The combination AB = 10, with the top sensor wet while the bottom sensor is dry, cannot happen in a real tank because water cannot reach the upper sensor without first passing the lower one. We treated that combination as a sensor fault.
The pump has only two states: OFF and ON. With only two states, one state variable Y is enough, and a single D flip-flop stores it. The transition rules are simple:
- From OFF, the pump may only turn on when AB = 00, meaning the tank is empty.
- From ON, the pump turns off when AB = 11 (full) or AB = 10 (sensor fault).
- Otherwise, the pump stays in its current state.
That third rule is the hysteresis. When the water rises past B and when it falls past A, the sensor combination is AB = 01 in both cases, yet the pump can be in a different state each time. Only the previous value of Y distinguishes them.
Table 1: State assignment table
| Present state Y | AB = 00 | AB = 01 | AB = 11 | AB = 10 | Output Z |
|---|---|---|---|---|---|
| 0 (OFF) | 1 | 0 | 0 | 0 | 0 |
| 1 (ON) | 1 | 1 | 0 | 0 | 1 |
Because we used a D flip-flop, the excitation table does not need to be derived separately: the D input equals the next state.
From Karnaugh map to NAND gates
The four rows of the table above are enough to fill a two-variable K-map. Two groups of 1s appear: the AB = 00 column and the Y = 1 row across the AB = 00 and 01 columns. The result is:
D = A’B’ + A’Y
Table 2: K-map for input D
| Y \ AB | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 |
There was one temptation we deliberately rejected. If the AB = 10 cell were treated as a don’t care, the equation would shorten to D = B’ + A’Y. Unfortunately that short form makes the pump run when the sensor is faulty. We chose the longer equation for safety: an impossible sensor reading must stop the pump, not start it.
The equation is built from three NAND gates. Two inverters first produce A’ and B’. The first NAND computes (A’B’)’, the second computes (A’Q)’, and the third combines them into D = A’B’ + A’Q. The feedback Q from the flip-flop output to the second NAND gate is what makes the pump remember its own state.
Indicator lights and fault detection
Besides the pump, the system lights four LEDs: Empty, Full, Half, and Error. Their equations come from the same table:
- Empty = A’B’
- Full = AB
- Half = (A’B’ + AB)’ = A’B + AB’
- Error = AB’ + AY = A(B’ + Y)
The Error light comes on in two situations. First, when a sensor is faulty (A = 1, B = 0). Second, when the tank has just become full while the pump has not had time to stop (A = 1, Y = 1). The second situation lasts only one clock pulse, so Error blinks briefly and then goes dark along with the pump. In simulation, that blink is actually useful: it shows that the sequence of events is running as designed.
The circuit: six ICs, one transistor, one diode
The system was assembled from the ICs used throughout the practicum: 74HC04 for NOT, 74HC00 for NAND, 74HC08 for AND, 74HC32 for OR, 74HC74 for the D flip-flop, and an LM555 as the clock. Seven practicum modules are used: Module I (trainer board), II (AND/NAND), III (OR/NOR), V (two-level AND-OR), VI (NAND-NAND), VII (OR-AND), and XII (flip-flop).
The LM555 clock is wired as an astable with R1 = 10 kΩ, R2 = 47 kΩ, and C1 = 4.5 µF. Its frequency is:
f ≈ 1.44 / ((R1 + 2R2) × C1) ≈ 3 Hz
Three pulses per second is fast enough for bench testing, but still slow enough for the eye to follow the lights as they change.
The flip-flop output cannot supply the motor current, so Q feeds the base of an NPN transistor through a resistor. The transistor connects the motor to ground, and a flyback diode sits in parallel with the motor to absorb the voltage spike when the transistor turns off. The motor runs from a separate 9 V battery, with its ground tied to the 5 V logic ground.
On the trainer board, the 555 circuit is replaced by the built-in Clock & Pulser block, while the motor, transistor, and 9 V battery are not available. The Pump LED stands in for the pump, and the motor driver is only shown in simulation.
Test results
Testing in Tinkercad followed the water rising and falling. Each row needs one clock pulse.
Table 3: System test results
| Step | A | B | LED on before clock | Pump after clock |
|---|---|---|---|---|
| 1. Water at mid-level (start) | 0 | 1 | Half | Off |
| 2. Tank empty | 0 | 0 | Empty | On |
| 3. Water passes B | 0 | 1 | Half | Stays on |
| 4. Water reaches A | 1 | 1 | Full, Error briefly | Off |
| 5. Water falls past A | 0 | 1 | Half | Stays off |
| 6. Water falls until B is dry | 0 | 0 | Empty | On again |
| 7. Sensor fault | 1 | 0 | Half, Error | Off, Error on |
Rows 3 and 5 are the proof of hysteresis. The sensor combination is identical, AB = 01, yet the pump stays on in row 3 and stays off in row 5. Only the value of Y from the previous step distinguishes them. Without the flip-flop, both rows would produce the same output and the pump would blink every time the water passed the lower sensor.
Row 7 tests the safety path. When A is wet but B is dry, the pump is forced off and the Error light stays on. The Half light also comes on because the combination really is A ≠ B, but Error makes the fault condition easy to tell apart.
Three fixes for next time
The project report lists a few fixes that did not make it into the simulation file.
First, the base resistor R3 should be 1 kΩ, not 330 Ω. With 330 Ω the base current is about 13 mA, too much for the 74HC74 output, which is rated at about 4 mA. Second, B’ is made from two inverters with their outputs tied together; one inverter would be enough. Third, there is a leftover wire from U4 pin 5 to U2 pin 10 that is not used, and unused gate inputs should be tied to GND so they do not float.
These findings may sound minor, but they are exactly what separates a simulation that runs from a circuit that is ready to move onto a trainer board. In Tinkercad, a floating pin does not always cause trouble. On a real board, such a pin picks up noise and makes the logic behave randomly.
What we learned
The circuit is small: six ICs, one flip-flop, one transistor. Yet it packs almost the entire digital systems practicum into one working system: basic gates, two-level circuits, flip-flops, clocks, and load drivers.
The K-map is only a tool. The biggest lesson is that one bit of memory changes the behaviour of the whole system. Without the flip-flop, the same circuit is just an automatic switch that blinks. With the flip-flop and Q feedback, it becomes a controller that knows when to start and when to stop.
We also approached the same problem from the basic electronics side, with discrete components and no ICs. That write-up is in A two-level water tank with no ICs.
This final project was done with Rafsanjani Raffa Syahzidan, Radhitya Kurnia Asmara, and Sabrina Haqni Naura Arif for the Digital Systems practicum, Computer Engineering, Universitas Diponegoro. The complete circuit can be opened in Tinkercad: