Electricity/Diodes/Diodes and flyback

Diodes and flyback

A diode is a one-way valve, and most of the time that is all you need to know. The exception is the diode fitted across a relay or a motor, which does nothing at all until the moment it saves the transistor beside it.

Switch the coil off with the diode out, then fit it and try again. The scale is logarithmic because the two answers do not fit on one linear axis.

Switching a relay coil off
voltage across the transistor
5 V railpeak:
Nothing is watching this loop. The coil is energised and the transistor is holding it on. Switch it off and see what the transistor gets.

The one job that needs a diode and nothing else

What a diode is covers the rest of the chapter's ground: it conducts one way, blocks the other, and charges about 0.7 V for the privilege. Reverse-polarity protection and steering two supplies are both jobs a better part can do instead — a MOSFET, or a chip full of them.

Flyback is not. Across a coil there is nothing cheaper, faster or more reliable than one diode, and the reason is what the rest of this page is about.

Why a coil needs one

Current through a coil creates a magnetic field, and that field stores energy. Switch the current off and the field collapses — but it will not simply stop. It keeps the current flowing by generating whatever voltage that takes, and with a fast switch, "whatever it takes" is hundreds of volts.

The transistor is what pays. A 2N2222A is rated for 40 V, and the plain 2N2222 for only 30. The spike from a small relay coil is comfortably 200 V, in the reverse direction, across a part that has no defence against it.

Fitting it

The diode goes directly across the coil, pointing the wrong way for normal current: cathode (the striped end) to the positive side. In normal operation it does nothing. When the field collapses, the coil's voltage reverses, the diode conducts, and the energy circulates harmlessly around the loop and turns into a small amount of heat.

A 1N4001 or 1N4007 costs a few cents and handles any relay, solenoid or small DC motor you will meet.

The bug it produces

This failure rarely looks like a failure. The transistor survives the first hundred spikes, the project works on the bench, and three weeks later the relay stops clicking — or worse, sticks on. Boards that reset when a relay switches, or where a nearby sensor reads nonsense on every actuation, are showing you the same spike coupling into everything else.

Edit this page — content/fundamentals/electricity/diodes-and-flyback.mdx

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Fundamentals on the forum