Assam ASSEB HSLC NSQF Electronics and Hardware study materials
Assam ASSEB HSLC NSQF Electronics and Hardware study resources

Water-Tank Controller: Relay Chatter and Arduino Resets

Assam ASSEB HSLC NSQF Electronics and Hardware · Put your knowledge to work in context.

All case studies

Water-Tank Controller: Relay Chatter and Arduino Resets

A trainee builds a water-tank controller for a hostel in Barpeta. An Arduino Uno is powered from a 12 V 2 A adapter through the Vin pin. It drives a 5 V single-channel relay module whose IN pin is active LOW. The relay's NO contacts switch a 12 V, 5 A pump. The float switch is a reed switch 6 m away, wired with unshielded bell wire and using the Arduino's internal pull-up. The relay module has no flyback diode, and its VCC is taken from the Arduino 5 V pin. The pump and the reed cable run parallel for 4 m. When the tank fills, the relay chatters at about 8 Hz and the Arduino sometimes resets. The pump cable and the 12 V adapter share a terminal block. The trainee must make the system reliable before the hostel reopens, without changing the Arduino board.

1. Diagnose the chatter and resets. Rank the likely causes and explain the evidence for each.

Read the worked answer

Ranked causes:

  1. Supply and back-EMF: the relay coil has no flyback diode and is powered from the Arduino 5 V pin. When the coil switches off, the inductive kick can pull the 5 V rail down or inject noise, causing resets. The pump motor has no suppression, and it shares the 12 V adapter and terminal block, so starting current causes a dip.
  2. Coupled noise: the pump and reed cables run parallel for 4 m. Pump brush noise and switching transients couple into the high-impedance reed line, producing multiple false edges.
  3. Bounce and software: a reed switch bounces mechanically, and without hysteresis or debounce the code can toggle the relay rapidly. 8 Hz is too fast for a real tank level to cross a threshold, so this is electrical or software oscillation, not normal filling.

2. List the hardware changes you would make, with values where possible. Include the relay driver, flyback, sensor wiring and supply.

Read the worked answer
  • Do not take relay coil current from the Arduino 5 V pin. Use a separate 5 V supply, or a 12 V relay with a transistor driver, and join grounds at one point.
  • Fit a 1N4007 flyback diode across the relay coil, cathode to +5 V.
  • Fit a 1N4007 across the pump motor and a 100 nF ceramic capacitor across its terminals; add a fuse.
  • Power the pump from its own 12 V supply or terminal block, not shared with the Arduino adapter.
  • Twist the reed pair, use shielded cable with the shield earthed at the Arduino end, add a 10 kΩ external pull-up and 100 nF from the input to ground.
  • Keep the reed cable away from the pump cable; cross at right angles if unavoidable.
  • Verify the relay module is active LOW and that the pump's 5 A surge is within the relay rating.

3. Write the control logic in words or pseudocode that prevents chatter. Include hysteresis, debounce, fail-safe and pump protection.

Read the worked answer

Use a non-blocking state machine:

  • Read the float input every 20 ms; require it to be stable for 500 ms (debounce).
  • Define two thresholds in software: turn the pump ON only after the low level is continuously present for 2 s; turn it OFF only after the full level is continuously present for 5 s. This hysteresis prevents chatter around one level.
  • Enforce a minimum run time of 30 s and a minimum off time of 60 s.
  • If the sensor reads impossible or disconnected for more than 2 s, turn the pump OFF and show a fault.
  • Drive the relay only through the transistor or driver, and initialise the pin to the OFF state at boot.

This stops the 8 Hz cycling: a brief noise pulse cannot pass the debounce, and a real level change must persist through the hysteresis window.