Diode bridged across a motor's terminals with a glowing current loop

Flyback Diodes: Why Motors and Relays Kill Pins

A flyback diode is a diode placed across an inductive load (motor, relay coil, solenoid) to absorb the high-voltage spike the load generates the instant its current is switched off; without it, that spike, easily 100V or more from a 5V coil, punches through the transistor or microcontroller pin doing the switching. The diode is wired in reverse across the load, cathode (the striped end) to the positive side, so it does nothing while the load runs. At switch-off it springs into action, giving the coil's stubborn current a safe loop to circulate in while its energy dies away as heat. One 1N4007 in the right place is the difference between a driver circuit that lasts years and one that dies mysteriously in a week.

Why inductors fight back

A coil of wire, and every motor, relay, and solenoid contains one, stores energy in its magnetic field while current flows. Inductance is the property that resists changes in that current. Increase it and the coil pushes back gently. But interrupt it suddenly, by opening a switch, and the coil does whatever it takes to keep the current flowing for one more instant. What it takes is voltage: the collapsing magnetic field drives the voltage across the coil as high as necessary to keep pushing charge.

The physics is V = L × (rate of change of current). Open a switch in microseconds and the rate of change is enormous, so the voltage is enormous. A humble 5V relay coil can generate a spike of 100 to 300V. It lasts only microseconds and carries little total energy, which is exactly why it is so treacherous: it will not flicker a bulb, but it will punch through the delicate junctions inside a transistor or an Arduino Uno R3 pin, silently and permanently.

What the diode does

A diode conducts in one direction only, and only when its anode is about 0.7V above its cathode. Place it across the coil pointing "backwards": cathode to the coil's positive supply side, anode to the switched side. During normal operation the supply reverse-biases the diode and it sits invisible, conducting nothing.

At switch-off the coil's voltage reverses polarity as it tries to keep current flowing. That reversal forward-biases the diode. Now the current has a private loop: out of the coil, through the diode, back into the coil, round and round while the resistance of the wire converts the stored energy into a little warmth over a few milliseconds. The voltage across the coil is clamped to one diode drop, about 0.7V, instead of hundreds. The switching transistor sees nothing worse than supply plus 0.7V. The name flyback comes from this voltage snapping back; you will also hear freewheeling diode or snubber diode for the same job.

Choosing the diode

The requirements are mild. The diode's reverse voltage rating must exceed the supply (easy), and its current rating should match the load current it briefly carries. The 1N4007 (1A, 1000V) is the everyday choice for relay coils and small motors, costs almost nothing, and belongs in every parts box next to the resistor variety pack. For fast PWM switching of larger motors, a Schottky diode such as the 1N5822 clamps faster and drops less. For loads above an amp or two, scale the diode current rating with the load.

Worked example: a bare relay coil on a BC547

You are driving a bare 5V relay (not a module) from an Uno via a BC547 transistor: coil from 5V to the collector, emitter to GND, 470Ω from pin 8 to base, on a 400-point breadboard with Dupont jumper wires.

Add the 1N4007 directly across the coil pins: striped end (cathode) into the same row as the coil's 5V side, plain end (anode) into the coil's collector-side row. That is the whole fix. Without it, every single switch-off fires a spike at the collector; the BC547 may survive dozens or thousands of hits, degrading each time, and then one day pin 8's transistor simply stops switching. With the diode, the collector never sees more than about 5.7V. If you use a relay module instead, this diode is already on the board, which is one of the main things the module is for.

Where this bites you

The classic sequence: a beginner wires a small DC motor straight to a pin "just to test", or through a transistor with no diode. It works. It keeps working through the whole afternoon. Days later the board develops odd symptoms: one pin dead, the board resetting when the motor stops, analog readings gone noisy. Nobody connects the symptoms to the motor because the damage was cumulative and the failure delayed. Inductive spikes rarely announce themselves; they degrade junctions hit by hit.

The subtler version: the diode is present but backwards. Installed with the anode to positive, the diode conducts continuously, shorting the supply through the transistor the moment it switches on. Things get hot fast. Remember: stripe to positive, and the diode should be doing absolutely nothing while the load is on.

Also, know what the diode does not fix: motor brush noise (that needs small ceramic capacitors across the motor terminals) and supply sag from stall current (that needs a better supply). The flyback diode handles exactly one problem, the switch-off spike, and handles it completely.

FAQ

Does my L298N motor driver need external flyback diodes?

The common L298N motor driver boards include the eight clamp diodes the chip requires, so no extra parts are needed with those modules. If you ever use a bare L298N chip, external diodes are mandatory; the chip has none inside. Modern MOSFET driver boards handle clamping internally as well.

Why does the diode slow my relay's release?

While the freewheel current circulates, the coil stays weakly magnetised, so the armature drops out a few milliseconds later than it would unprotected. For hobby projects this is irrelevant. Where release speed matters, designers put a resistor or zener in series with the diode to burn the energy faster at the cost of a higher clamped voltage.

Do I need a flyback diode for LEDs, heaters, or buzzers?

LEDs and heaters are not inductive; no diode needed. Electromagnetic buzzers and anything with a coil or winding, yes. When unsure, look for wire wound around anything inside the part, or just fit the diode; a correctly oriented flyback diode never hurts a DC circuit.

Add a motor or relay to a project with Compoden's AI build assistant Soldr and it will put the protection diode in the wiring plan before you ever hit the switch-off spike.

Back to blog