Microcontrollers freezing on relay switching is a classic field fault that passes in the prototype as “happened once” but repeats shift after shift in production. When coil current is interrupted, reverse EMF, contact arcing, and noise on a shared ground return as resets, watchdog trips, or locked communication.
Board design sits under PCB design; firmware debounce, reset, and isolation belong with software development. The examples below come from lab and commissioning notes; no customer names or machine brands.

An inductive relay coil generates reverse EMF when de-energised. Without a flyback diode or with an inadequate snubber, that energy arcs across contacts and creates brief high dV/dt on the line. If the MCU reset pin, crystal trace, or ADC reference shares the same ground plane, noise reaches the core directly.
When a relay driver is driven from GPIO without an optocoupler, sudden coil current changes ripple the supply. A shared ground loop between a long field cable and the field relay lets return current pass through the MCU analog ground reference. Result: one “freeze” on every pull-in, then watchdog reset — the operator says “the device reboots by itself”.
On a lab bench with one relay, short wiring, and a stable supply, the issue may never appear. On the line the same board commands ten relays per second; EMI accumulates. Modbus or RS-485 run parallel to relay cables and frame errors rise. Extending watchdog timeout in software hides the root cause; the next relay command locks up again.
Typical complaint: “When relay 3 turns on, the display freezes.” Measurements show hundreds of volts spike on the driver MOSFET drain and a 200 mV dip on MCU VCC. The reset pin may have triggered on the scope; the real culprit is coil energy not being clamped or dissipated.
Coil protection: A flyback diode (or MOSFET body diode) returns reverse EMF to the supply; coil current decays in a controlled way. On the contact side, an RC snubber (typical 100 Ω–1 kΩ + 100 nF–1 µF per relay datasheet) limits arc energy except for AC relays or SSRs. Snubber values must not be copied as “generic 0.1 µF”; damping depends on coil L and contact C.
Ground and power: MCU analog/digital ground and relay power ground should meet at one star point; relay return current must not flow under the MCU. Ferrite beads on the supply and bulk + decoupling (100 nF + 10 µF) near the coil absorb spikes. Reset and crystal traces stay away from relay drivers; guard rings or ground fill are preferred.
Isolation: An optocoupler or relay driver IC (ULN2003, ULN2803, etc.) separates GPIO from the coil current path. If field cable is shielded, bond the shield at the board entry only — dual-end shield ties create ground loops.
Firmware: Relay commands are debounced; multiple on/off events in the same millisecond are staggered. Brown-out threshold and watchdog are backup safety layers after hardware fixes — not the primary solution.
First confirm spikes on coil terminals and VCC with a scope or at least a meter. Flyback + snubber revision on PCB if a new spin is possible; otherwise a suitable snubber module in parallel with contacts. Review the ground scheme: relay return on power ground, MCU reference on a separate path.
Revan boards usually use optocouplers and a separate power domain per relay channel; in PCB design the rule of thumb is inductive load routing stays more than 5 mm from reset/crystal traces. Firmware defines relay sequencing and minimum off-time.
In field wiring, relay cables run in separate ducts from signal and communication cables; twisted-pair return is used where possible.
When microcontrollers freezing on relay switching is fixed, watchdog resets drop, Modbus/RS-485 frame errors fall, and operator intervention and warranty calls decrease. Hardware is corrected once; software only supports with sequencing and debounce.
Measurable target: zero unexpected resets in relay stress test (e.g. 10 Hz on/off for 10 minutes); VCC ripple below the defined limit.
“ We extended the watchdog and it was fine” works for a while; in heat and with an ageing coil, spikes grow and the fault returns. Snubber cost is lower than one field visit. Skipping the EMI package because there is no relay on the prototype or only one channel is tested is one of the most common root causes.
In industrial panels with mixed AC and DC relays, snubbers on AC and flyback on DC must not be forgotten.
Microcontrollers freezing on relay switching is the combination of coil energy, ground path, and missing isolation. Snubbers, flyback, optocouplers, and star ground cut noise at the source; watchdog is only the last safety net. Validating the board with relay stress testing before the field prevents surprise resets in production.
🔗 Get in touch with us:
Phone/WhatsApp: +41 76 212 8248
📧 E-Mail: info@revantechnology.ch
For detailed information about our services in electronics development & PCB design:
Revan Technology – Your partner for professional electronics and PCB development