A two-level water tank with no ICs: hysteresis from a relay contact

Final project for the Basic Electronics practicum, 2026

A water pump at home is usually switched on and off by hand. Two mistakes happen often: the pump is left running until the tank overflows, or it is left off until the water runs out. A single-level automatic switch tries to solve that problem, but it creates a new one.

When the water surface sits right at the sensor threshold, small ripples make the sensor alternate between wet and dry. The pump switches on and off repeatedly. The relay contacts wear out quickly, and the pump motor sees a cycle it was never designed for.

Our solution: two sensors and one memory. The pump starts when the tank is empty, keeps filling until it is full, then stops. It starts again only after the water has fallen past the lower sensor. This behaviour is called hysteresis: the switch-on threshold and the switch-off threshold are made different.

The design flow is simple: operating rules, state diagram, logic equations, circuit, calculations, then testing.

One sensor is not enough

A single sensor can only give one answer: is the water above or below the sensor? That answer is not enough to decide whether the pump should run. When the water is right at the threshold, the same sensor reading can mean “keep filling” or “keep waiting”, depending on what the pump was doing before.

Sensor Previous pump state Correct decision
wet filling pump stays on
wet waiting pump stays off

Without a memory of the previous state, the circuit has to pick one decision for two different situations. One of them will always be wrong.

Two sensors and five rules

We placed sensor B at the bottom and sensor A at the top. A value of 1 means the sensor is wet, 0 means dry. We write the combination as BA, with B as the first bit and A as the second. The five operating rules are:

Step Tank condition B A Pump
1 Empty 0 0 on
2 Water passes B 1 0 stays on
3 Full 1 1 off
4 Water falls past A 1 0 stays off
5 Empty again 0 0 on again

Rows 2 and 4 have the same sensor values: B wet, A dry. The pump is in a different state. In row 2 the pump is filling; in row 4 it has finished and is waiting. The circuit has to store that difference.

Step 1: draw the pump states

We started with four states: empty, half full, full, and falling back to half. A diagram of state transitions like this is called a state diagram, or FSM (finite state machine). Four states looks excessive, and it is. The empty and half-full states always produce the same output. For every possible input, they also lead to the same next state. They can be merged into ON. The full and falling-to-half states can likewise be merged into OFF.

State diagram with four states A, B, C, and D and output z; states A and B mean the pump is on, states C and D mean the pump is off.
The initial state diagram with four states. A and B turn the pump on; C and D turn it off. On inspection, A is equivalent to B, and C is equivalent to D.

After merging, two states remain: ON and OFF, matching the labels already in the diagram. One variable y is enough to store the state, with y = 0 for ON and y = 1 for OFF.

Reduced state diagram: state ON with y = 0 and z = 1, state OFF with y = 1 and z = 0; transitions occur only at BA = 11 or BA = 00.
The reduced state diagram. The pump only changes state when the tank is full (BA = 11) or empty (BA = 00). Ripples between the two sensors do not change its state.

Table 1: Two-state transition table

Present state BA = 00 BA = 01 BA = 10 BA = 11 Pump
ON (y = 0) ON d ON OFF on
OFF (y = 1) ON d OFF OFF off

BA = 01 means A is wet but B is dry. Water cannot reach the upper sensor without first passing the lower one, so this condition is impossible in a real tank. We marked it d (don’t care, its value is not used).

The table can be read as two rules. From ON, the pump moves to OFF only when the tank is full (BA = 11). From OFF, it moves to ON only when the tank is empty (BA = 00). Outside those two conditions, the pump stays in its current state.

Step 2: turn the table into equations

The transition table is enough to fill a K-map (Karnaugh map), a helper table for simplifying logic equations. The rows hold the state y, the columns hold the input BA.

Table 2: K-map for the next state Y

y \ BA 00 01 11 10
0 0 d 1 0
1 0 d 1 1

There are two groups of 1s to circle: the 11 column, and the pair of y = 1 cells in the 10 and 11 columns. In the equations below, a dot means AND, a plus sign means OR, and an apostrophe (’) means NOT. The result is:

Y = B·A + y·B
  = B·(A + y)

z = y'

The term B·A means the tank is full, whatever the previous state, so the pump must stop. The term y·B means that if the pump is already off and B is still wet, the pump stays off. The output z = y’ means the pump runs when y = 0.

This equation was wrong in our first notes. The first form we wrote was Y = y + BA. The mistake is small on paper, but it stops the pump from ever starting again after the tank empties.

At y = 1 and BA = 00:
Y = y + BA = 1 + 00 = 1   (wrong, should be 0)

The correct form:
Y = B·(A + y)
Handwritten derivation of the state diagram: four-state diagram, transition table, K-map, and equations; the equation Y = y + BA is visible and was later corrected.
Handwritten notes from deriving the state diagram. The equation Y = y + BA on the right is the form that was later corrected.

Step 3: turn the equation into memory

The equation for Y is still just logic. To become a circuit, we convert it to the output form Q, the signal that turns the pump on. Since Q is the inverse of y, the equation becomes:

Q = z = y'
Q = B' + A'·Q

Read it like this: the pump runs if B is dry (B’ = 1), or if the pump is already running (Q = 1) and the upper sensor is not yet wet (A’ = 1). The term A’·Q is the memory. Once Q is on, that term holds Q on until A becomes wet.

This form is the same as a NAND SR latch, a one-bit locking circuit made from two NAND gates. Its SET and RESET inputs are active low: SET from signal B, RESET from the inverse of A. SET happens when B is dry; RESET happens when A is wet. The forbidden combination (B dry and A wet at the same time) cannot occur in a real tank. If it happens in simulation, B wins and the pump runs.

In this circuit the memory is not a chip. The memory is made by a contact on relay K1. A relay is a switch driven by an electromagnet. When the pump runs, current flows through coil K1, the COM (common) to NO (normally open) contact closes, and 5 V is fed back to point H. As long as H is high, the pump keeps running even after B becomes wet. When A becomes wet, T1 pulls H to 0 V. The pump stops, coil K1 loses current, and its contact opens. Now H stays low even when A dries again, because no more 5 V is coming in. The pump waits until B is dry.

How it works in five steps

The signal sequence is easier to follow if you read it as the journey of the water.

  1. Tank empty. B is dry, T2 is off, NB is high. Z is high, T3 is on, current flows through coils K1 and K2. Contact K1 closes and locks H; contact K2 closes and the pump starts.
  2. Water passes B. B is wet, T2 is on, NB is low. But contact K1 is still closed and feeding 5 V to H. Z stays high, so the pump keeps running.
  3. Water reaches A. A is wet, T1 is on, H is pulled to 0 V. Z goes low, T3 turns off, contacts K1 and K2 open. The pump stops.
  4. Water falls past A. A is dry, T1 is off. Contact K1 is already open, so no 5 V reaches H. H stays low and the pump stays off.
  5. Water falls until B is dry. NB goes high again, Z goes high, and the pump starts. The cycle returns to step 1.

Steps 2 and 4 are the heart of hysteresis. The sensors give the same values, but the relay is in a different state.

The circuit: four blocks

The circuit is divided into four blocks. Each block has one job, and that job can be read from the equations above.

System block diagram: sensors B and A, NOT inverter, AND detector, OR gate, T3 driver, relay coils K1 and K2, and contact K1 as memory.
The four circuit blocks. Sensor B produces NB, sensor A and contact K1 produce H, then NB and H feed the OR gate.

Block 1: sensor B and the inverter

Potentiometer B acts as the water-level sensor. The voltage at its middle terminal (the wiper) moves from 0 V to 5 V. A full turn toward the 5 V side means wet; toward the 0 V side means dry. R2 and R3, both 4.7 kΩ, form a voltage divider. T2 inverts that signal: when B is wet, T2 saturates (conducts fully) and NB drops to about 0 V. When B is dry, R6, the pull-up resistor, pulls NB up to the 5 V rail. C1, 100 µF, slows the voltage change so ripples do not make NB flicker.

Sensor B block: potentiometer B, R2 and R3 4.7 kΩ, C1 100 µF, transistor T2, and R6 330 ohm produce NB.
Sensor B and inverter T2. NB is low when B is wet and high when B is dry.

Block 2: sensor A and the memory

Sensor A uses the same arrangement (R1, R4, and C2), but the collector of T1 becomes point H. H also receives 5 V from contact K1. So H is high only when two conditions are met: A is dry and K1 is closed. When A is wet, T1 pulls H to 0 V and breaks the memory chain.

Sensor A block: potentiometer A, R1, R4, and C2 feed T1; contact K1 sends 5 V through R5 330 ohm to point H.
Sensor A and the memory contact K1. H is high only when A is dry and contact K1 is still closed.

Block 3: OR gate and relay driver

D1 and D2 form an OR gate. Z follows the higher of NB and H, minus the diode drop of about 0.7 V. The diode on the low side is reverse-biased, so it does not pull the high side down. Z feeds the base of T3 through R7. T3 energises coils K1 and K2. D3 is the flyback path, the route for coil current when T3 turns off.

Diode OR gate D1 and D2, T3 driver, relay coils K1 and K2, and flyback diode D3.
The OR gate made from D1 and D2. T3 drives both relay coils, and D3 absorbs the voltage spike when T3 turns off.

Block 4: the pump switch

Contact K2 connects the 9 V battery to the DC motor. The 9 V circuit is separate from the 5 V rail so motor current surges do not disturb the logic. The LU-5-R relay used here is rated at 3 A, and the motor current must be measured to confirm it stays well below that limit.

Pump circuit: 9 V battery, contact K2, and motor M1; contact K2 closes when the coil is energised.
Contact K2 is the switch for the 9 V motor. The motor circuit is not connected to the 5 V rail; only ground is shared.

Calculations

Every value was calculated before assembly. The results were used to choose resistors and to check that the transistors really saturate.

Sensor threshold

The transistor starts to conduct when the base-emitter voltage is about 0.7 V. The base is formed by the divider R_series and R_bottom, both 4.7 kΩ.

V_wiper = 0.7 V × (R_series + R_bottom) / R_bottom
        = 0.7 V × (4.7 kΩ + 4.7 kΩ) / 4.7 kΩ
        = 1.4 V

1.4 V / 5 V × 100% = 28%

The threshold is about 28% of the potentiometer’s rotation. Below it, the sensor is considered dry. Above it, wet.

Base and collector current

With the wiper at 5 V, the base current of T2 is calculated from two resistor paths:

I_B = (5 V − 0.7 V) / 4.7 kΩ − 0.7 V / 4.7 kΩ
    = 0.915 mA − 0.149 mA
    ≈ 0.77 mA

When the transistor is saturated, the collector-emitter voltage is about 0.2 V. The collector current is:

I_C = (5 V − 0.2 V) / 330 Ω
    ≈ 14.5 mA

The required gain is only:

β_min = I_C / I_B
      = 14.5 mA / 0.77 mA
      ≈ 19

A typical NPN transistor has a β of about 100, so it is well into saturation. The pull-up resistor’s power dissipation is also safe:

P_R = (5 V − 0.2 V)² / 330 Ω
    ≈ 70 mW

A 1/4 W resistor is rated at 250 mW, so 70 mW is far below the limit.

RC filter

C1, 100 µF, is connected in parallel with R3. From the capacitor’s point of view, R2 and R3 appear in parallel:

R_Thevenin = 4.7 kΩ ∥ 4.7 kΩ
           = 2.35 kΩ

τ = R_Thevenin × C1
  = 2.35 kΩ × 100 µF
  ≈ 0.24 s

5τ ≈ 1.2 s

In one τ the voltage reaches about 63% of its final value. In 5τ, about 1.2 seconds, it reaches 99%. Ripples faster than that will not be read.

NB and Z voltages

NB does not reach 5 V because T3’s base current also flows through R6:

NB = 5 V − I_B(T3) × R6
   ≈ 5 V − 5.5 mA × 330 Ω
   ≈ 3.2 V

The voltage at Z with one path active:

Z (one path) = 5 V − 0.7 V − 5.5 mA × 330 Ω
             ≈ 2.5 V

Z (two paths) ≈ 3.1 V

When both paths are active, NB and H are both high, so R5 and R6 appear in parallel and Z rises.

Measurement results

The two most important numbers are the NB voltage when the sensor is dry and the transistor’s collector-emitter voltage (V_CE) when it is saturated.

Table 3: Calculated versus measured

Measurement point Condition Calculated Measured
NB B dry, one path active ≈ 3.2 V 3.17 V
V_CE T2 B wet, saturated ≤ 0.2 V 36.5 mV

NB stops at 3.17 V because part of the 5 V is dropped across R6 by T3’s base current. That is not a measurement error. The result actually confirms that the circuit calculations are correct.

Test sequence

Because the system has memory, the test order matters as much as the sensor values. Skipping a step can lead to the wrong conclusion. This table shows the state after the circuit has settled, not the instant after a sensor changes.

Table 4: Test scenarios and internal states

Step Condition B A K1 NB H Pump
1 Empty 0 0 closed high high on
2 Half full 1 0 closed low high stays on
3 Full 1 1 open low low off
4 Water falls to half 1 0 open low low stays off
5 Empty again 0 0 closed high high on

Steps 2 and 4 have the same B and A values, but different results. In step 2 contact K1 is still closed because the pump is filling. In step 4 K1 is already open because the pump has stopped. That is the memory at work.

Seven modules in one product

This final project required at least five practicum modules. Our product uses seven.

Module Used for Evidence
Resistors and Ohm’s law base current limiting and collector pull-ups currents and voltages across R1 to R7
Voltage dividers potentiometer and resistor pairs as threshold setters wiper and base voltages
Power, capacitors, and inductors RC filter and relay coils voltage rise time, coil voltage
Diodes OR gate and flyback diode Z voltage and D3 cathode
BJT transistors T1 and T2 as inverters, T3 as relay driver V_CE at saturation
DTL NOT and OR gates from discrete transistors and diodes measured truth table
Relays K1 as memory, K2 as pump switch coil and pump voltages

Every module meets three conditions: it plays a real role in the circuit, its values are calculated, and the result is proven by measurement.

Complete system schematic: two sensor blocks, diode OR gate, T3 driver, relays K1 and K2, flyback diode D3, motor M1, and 9 V battery.
The complete system schematic. All the blocks meet here: two sensors, K1 memory, OR gate, relay driver, and motor switch K2.

Frequently asked questions

Why two sensors? One sensor makes the pump switch on and off repeatedly around the threshold. Two sensors give two different thresholds, one to start and one to stop.

What does relay K1 do? Its contact feeds 5 V back to point H while the pump is running. That is the memory that keeps the pump filling after B becomes wet.

What does relay K2 do? Relay K2 is the load switch. The transistor cannot handle the motor current, and the relay isolates the 5 V circuit from the 9 V circuit.

Why is diode D3 there? A relay coil is an inductor. Without D3, the voltage spike when T3 turns off could destroy the transistor.

Why is NB only about 3.2 V instead of 5 V? T3’s base current flows through R6, so some voltage is dropped across that resistor.

How do I change the sensor threshold? Change the divider ratio. For example:

V_wiper = 0.7 V × (10 kΩ + 4.7 kΩ) / 4.7 kΩ
        ≈ 2.2 V

Is this an SR latch? Yes. The equation Q = B’ + A’·Q is the same as a NAND latch, with SET from signal B and RESET from the inverse of A.

Closing

This circuit is built from components that all came up in the practicum: three transistors, two relays, three diodes, two potentiometers, a handful of resistors, two capacitors, and one DC motor. There is no microcontroller and no IC. Every decision is made by voltage dividers, diode gates, and one relay contact that remembers the previous state.

That is exactly why the project felt satisfying. Hysteresis that is usually handled by code on a microcontroller had to be built from the physical behaviour of components. Once the circuit worked, we appreciated relays more: one contact closing and opening can be enough memory to stop a water pump from blinking.

We wrote up the digital version of this problem, using a D flip-flop and logic gates, in The water tank pump that stopped cycling.

This final project was done for the 2026 Basic Electronics practicum, Computer Engineering, Universitas Diponegoro. The complete circuit can be opened in Tinkercad:

Find me on LinkedIn and Instagram!

← all notesAlso available in Indonesian