ITI/NCVT Mechanic Consumer Electronics (AITT Theory) study materials
ITI/NCVT Mechanic Consumer Electronics (AITT Theory) study resources

Microcontroller Resets When an Off-Board 5 V Relay Turns Off

ITI/NCVT Mechanic Consumer Electronics (AITT Theory) · Put your knowledge to work in context.

All case studies

Microcontroller Resets When an Off-Board 5 V Relay Turns Off

A custom controller board uses an ATmega328P at 16 MHz, a 5 V AMS1117 regulator fed from 12 V, and a 5 V SPDT relay. The relay coil is mounted off-board and connected by a 15 cm two-wire lead; a 1N4007 flyback diode is fitted at the relay, but the return wire shares a 0.3 m ground trace with an LM35 sensor and the MCU ground pin. Everything works on the bench with a short USB cable. Inside the enclosure, the MCU resets about one time in five when the relay turns off; a scope with a short ground spring shows a −1.8 V spike on the 5 V rail at the MCU and a 2.4 V spike on the sensor input. The 100 nF decoupling capacitor is 4 cm from the MCU. The 12 V supply is a 2 A adapter. The customer reports that adding a 470 µF capacitor at the regulator output reduced but did not eliminate the resets.

1. Explain the likely mechanism and why the flyback diode at the relay is not sufficient.

Read the worked answer

The 1N4007 at the relay coil clamps the coil's inductive kick, but the current loop is still completed through the long 15 cm lead and the shared 0.3 m ground trace. The diode clips the voltage at the coil, yet the fast di/dt and the trace inductance produce a voltage difference between the relay's ground point and the MCU's ground pin. The scope shows −1.8 V on the 5 V rail at the MCU and 2.4 V on the sensor input, which is consistent with ground bounce rather than a pure supply droop.

The 100 nF decoupling capacitor is too far away and has too little energy to absorb a millisecond transient. The relay coil and the MCU are sharing a return path, so the coil current pulse develops a voltage across the ground trace. That shifts the MCU's internal reference and can trip its brown-out detector, causing a reset. The 470 µF capacitor reduced the disturbance by supplying charge, but it cannot remove the ground-potential difference.

2. List the fixes in priority order and explain why a single large capacitor is not the answer.

Read the worked answer

First, give the relay coil its own return wire directly to the 12 V supply or the regulator input ground, not through the MCU ground trace, and twist the coil pair to reduce loop area. Second, move the flyback diode physically across the coil terminals and use a fast diode such as 1N4148 or a Schottky if the coil is small; a 1N4007 is slow but usually acceptable. Third, add a star ground at the regulator output and return the sensor and MCU grounds separately. Fourth, fit a 100 nF X7R capacitor within 5 mm of the MCU VCC/GND pins and a 10–100 µF bulk capacitor at the regulator output. Fifth, consider a relay driver transistor with a base-emitter resistor and, for severe noise, an optocoupler or a solid-state relay. A series ferrite bead on the relay leads can also help.

A large capacitor only supplies charge after the ground has already bounced. It can hide the reset symptom while the sensor input still jumps, so the layout fault remains.

3. How would you verify the repair, and what would you check if resets still occur?

Read the worked answer

Trigger the scope on the relay control signal, use a short ground spring at the MCU ground pin, and measure VCC, the sensor input and the relay coil current simultaneously. Compare the spike before and after each change; the target is a rail deviation well under the MCU brown-out threshold, typically about 0.1–0.2 V, and no sensor input excursion beyond the ADC range. Repeat relay switching at least 100 times at the worst-case supply voltage, both cold and warm, because the fault is intermittent. Also test with the enclosure assembled, since the bench cable was shorter.

Do not simply increase the bulk capacitor until the layout is corrected. If resets persist, check the reset-pin pull-up, add a 100 nF capacitor to ground at the reset pin, and verify the brown-out fuse setting. Also check whether the relay coil is being driven directly from an MCU pin without a transistor, which would overload the port.