Snubber Circuits and Flyback Diodes: Protecting Switching Circuits from Inductive Kickback
Almost every maker who's driven a relay, a motor, or a solenoid directly from a microcontroller or MOSFET has run into some version of the same mystery: a circuit works fine for a while, then a transistor or microcontroller pin fails for no obvious reason, or a nearby sensor glitches every time the relay clicks. The usual cause is inductive kickback — the voltage spike an inductive load (any coil: relay, motor, solenoid, transformer) generates the instant current through it is interrupted — and it's one of the most common, most preventable failure modes in maker electronics once the underlying physics is understood.
Why Inductors Fight Back When Switched Off
An inductor resists any change in the current flowing through it — that's the defining property of inductance. While current flows steadily, this is invisible; the moment a switch (a transistor, a relay contact, a mechanical switch) opens and tries to stop that current instantly, the inductor responds by generating whatever voltage is necessary to keep current flowing for an instant, following V = L(di/dt). Because di/dt is enormous when current goes from several hundred milliamps to zero in nanoseconds, the resulting voltage spike can be tens to hundreds of volts — far beyond the few volts the circuit normally operates at, and easily enough to exceed the breakdown voltage of a switching transistor or punch through a microcontroller's GPIO protection.
Flyback Diodes: The Simple, Essential Fix for DC Loads
For any DC inductive load — a relay coil, a DC motor, a solenoid — a flyback diode (also called a freewheeling or snubber diode) wired in reverse-bias parallel across the coil gives that collapsing magnetic field somewhere to dump its current besides through the switching transistor. In normal operation the diode is reverse-biased and does nothing; the instant the switch opens and the coil's voltage flips polarity trying to maintain current flow, the diode becomes forward-biased and provides a path for that current to circulate and decay safely instead of spiking through the switch.
A standard 1N4001-1N4007 series diode handles most small relay and solenoid coils; for faster switching or higher current motor applications, a faster recovery diode (like an MUR or UF series ultrafast diode) responds quickly enough to actually protect against the fast edges a MOSFET produces — a slow general-purpose diode can let a brief but still-damaging spike through before it starts conducting. The diode should be rated for at least the peak current the coil draws and placed as physically close to the coil terminals as practical, since trace/wire inductance between the coil and a distant diode reintroduces a small amount of the same problem the diode exists to solve.
One tradeoff worth knowing: a simple flyback diode, while essential, also slows the coil's release — a relay or solenoid protected only by a flyback diode releases noticeably slower than one with no protection at all, because the diode lets the current recirculate and decay gradually rather than collapsing instantly. For applications where release speed matters (a fast-switching solenoid valve, for example), a series resistor with the flyback diode, or a TVS diode instead, trades a little protection margin for faster release.
RC Snubbers: For AC Loads and Switch Contact Protection
Flyback diodes work because they rely on the coil current flowing in one consistent direction — they don't work for AC loads, since the diode would block current during half the AC cycle. For AC inductive loads (an AC relay coil, a motor run off mains or line voltage) and for protecting mechanical switch or relay contacts themselves from the arcing that inductive kickback causes, an RC snubber (a resistor and capacitor in series, wired across the switch contacts or the load) is the standard approach instead. The capacitor absorbs the initial voltage spike's energy, and the resistor damps the resulting oscillation and limits the capacitor's discharge current back through the contacts when they close again. Typical starting values for a small relay-contact snubber are in the range of 100Ω and 0.01-0.1µF, though the correct values genuinely depend on the specific load's inductance and switching current — component manufacturers publish snubber design guides with more precise sizing formulas worth consulting for anything beyond a small hobby relay.
TVS Diodes: A Faster-Acting Alternative
A transient voltage suppressor (TVS) diode, wired similarly to a flyback diode but designed to clamp any transient above a specific voltage rather than simply providing a current path, reacts faster than a standard flyback diode and is a common choice in motor driver and relay driver ICs' datasheet reference designs. For MOSFET-switched DC motor applications especially, a TVS diode rated just above the circuit's normal operating voltage, placed across the drain-source of the switching MOSFET, is a common and effective belt-and-suspenders addition alongside a flyback diode across the motor itself.
Where This Shows Up in Maker Projects
Project typeProtection needed ESP32/Arduino driving a relay moduleMost pre-built relay modules already include a flyback diode on the relay coil — verify this before assuming a bare relay is protected Solenoid valve driven by a MOSFETFlyback diode across the solenoid coil, sized for the solenoid's actual current draw Brushed DC motor driven by a transistor or MOSFETFlyback diode minimum; TVS diode across the switching device recommended for anything beyond a small, low-current motor Mechanical switch controlling an inductive load directlyRC snubber across the switch contacts to prevent arcing and contact wearSkipping flyback protection on a hobby relay driven occasionally might get away with it for a while, since marginal components can survive repeated small overstress before finally failing — but that's exactly what makes it a frustrating bug to diagnose later: a microcontroller pin or transistor that mysteriously dies weeks into a project, with no obvious cause, is worth checking for an unprotected inductive load before assuming a component was simply defective.