Maharashtra HSC Electronics and Hardware Technician (NSQF E5) study materials
Maharashtra HSC Electronics and Hardware Technician (NSQF E5) study resources

A pump controller with a floating input and no freewheel diode

Maharashtra HSC Electronics and Hardware Technician (NSQF E5) · Put your knowledge to work in context.

All case studies

A pump controller with a floating input and no freewheel diode

A trainee has built 12 identical pump-control boards around an ATmega328P running at 5 V, 16 MHz. Each board drives a 5 V relay with a 70 Ω coil (about 71 mA) through a BC547 whose base is connected to PD6 via a 1 kΩ resistor. There is no diode across the coil, because the trainee says 'the transistor protects itself'. The start/stop signal comes from a float switch on the tank, 4 m away, wired in ordinary single-core flexible cable. The firmware sets DDRD bit 2 as input and leaves PORTD bit 2 at 0. On three boards the relay buzzes and the pump starts and stops at random; on two boards the BC547 has failed short. One board resets the moment the relay pulls in, and on one the input pin reads low even with the float switch open. The trainee's planned fix is to add a 100 ms delay in the loop and to change the base resistor to 470 Ω 'for more gain'.

1. Explain why the float-switch input behaves erratically and give the correct input circuit and firmware measures.

Read the worked answer

Why it misbehaves. Setting DDRD bit 2 to 0 makes the pin an input, but leaving PORTD bit 2 at 0 also switches off the ATmega328P internal pull-up (writing 1 to PORTD while the pin is an input is what enables the 20–50 kΩ pull-up). The pin is therefore floating at high impedance. Four metres of unshielded cable next to pump and relay wiring acts as an antenna, so the pin follows mains hum and switching transients; the readings are random, not faulty logic.

Correct input circuit

  • Enable the internal pull-up in firmware (PORTD |= (1 << PD2);), or fit an external 10 kΩ to VCC – the external resistor is preferable because a switch or cable short to ground then only dissipates 0.5 mA and the value is known.
  • Add 100 nF from the pin to ground at the board, forming an RC with the pull-up (about 1 ms) that shunts RF noise. A 100 nF directly across the switch terminals works too, but at the board is better for cable-borne noise.
  • Use shielded or twisted-pair cable for the float switch, route it away from motor and relay wiring, and earth the shield at the controller end only.
  • Decide the logic: wire the switch to pull the pin low when the tank is full, and make the firmware treat a broken wire (pin stuck high) as a safe stop.

Firmware. A blind 100 ms delay only slows the scan; it does not filter noise. Count consecutive identical samples – for example require 5 readings at 10 ms intervals, i.e. about 50 ms of agreement – and act only when that is reached. That gives real hysteresis and debounce. If the pin still reads low with the switch open, check for a solder bridge from that pin to ground or a damaged pad.

2. Evaluate the relay driver: base resistor value, transistor choice, dissipation and the missing diode. Show numbers.

Read the worked answer

Base drive. Ib = (5 − 0.7) / 1000 = 4.3 mA. The coil needs 5 / 70 = 71 mA. Forced beta = 71 / 4.3 ≈ 16.5, which is well inside saturation for a BC547 (hFE typically 110–200 at low current, and a forced beta of 10–20 guarantees saturation), so the 1 kΩ resistor is correct. Dropping to 470 Ω gives 9.1 mA, raises the forced beta margin and wastes current, loads the MCU pin further and can slow turn-off with a weak driver. It does not fix anything – the problem is not gain.

Transistor margin. A BC547 is rated Ic = 100 mA and VCEO = 45 V. Running a 71 mA coil leaves only 29% margin, and Vce(sat) at that current is about 0.25 V, so Pd ≈ 18 mW – no heatsink needed, but a BC337 (Ic = 800 mA) is the better engineering choice.

Missing freewheel diode – the real fault. The coil is an inductor. At turn-off, V = L × di/dt can drive the collector far above 45 V, so the BC547 avalanches and fails short. That is exactly what happened on two boards. Fit a 1N4148 (or 1N4007) across the coil terminals, cathode to +5 V, so it is reverse-biased during pull-in and clamps turn-off to about 0.7 V above the rail. Add a 100 µF electrolytic plus 100 nF at the relay to supply the pull-in current locally instead of letting it come down long supply leads.

3. Why does one board reset when the relay pulls in, and what sequence of checks would you follow?

Read the worked answer

Likely mechanism. Relay pull-in current (about 71 mA plus inrush) flows through the same ground return and supply track as the MCU. Two things can trip a reset:

  • Supply dip – if the 5 V rail sags below the brown-out detector threshold during pull-in, the MCU resets. Long thin supply leads or a regulator near its current limit make this worse.
  • Ground bounce – the coil current raises the potential of the MCU's ground reference for a few microseconds through shared track impedance, which looks like a reset or a corrupted instruction fetch.

Check sequence

  1. Scope the 5 V rail at the MCU VCC pin at the instant of pull-in; look for a dip below 4.5 V. Repeat with the probe tip and ground spring, not the long ground lead.
  2. Add a 100 µF electrolytic and 100 nF ceramic right at the MCU pins; route the relay supply and its ground return separately, joining at the regulator output (star point).
  3. Confirm the reset pin has its 10 kΩ pull-up to VCC and 100 nF to ground, and that the reset line is not routed beside the relay.
  4. Check the relay coil resistance against the 5 V regulator rating; if several relays share one regulator, feed them from a separate rail.
  5. Confirm the freewheel diode is actually fitted on that board – a missing diode also causes a large negative spike at turn-off that can disturb neighbouring logic.

Only after these should the MCU or board be replaced; the majority of such resets are layout and decoupling, not silicon.