The flyback diode: where a coil’s current goes when you switch it off
- 192parts on the bench
- 25boards running now
- 1.00xreal time, on every board
A relay coil, a solenoid and a motor winding are all inductors, and an inductor has one stubborn property: the current through it cannot change instantly. Switch off the transistor feeding it, and for a moment the coil keeps pushing the same current as before into whatever path is left. If the only path left is a switched-off transistor, the voltage there climbs until something conducts, and on a real bench that something is usually the transistor breaking down.
The circuit above is a small relay coil drawn as what it is electrically: a 10 mH inductor with the 50 ohms of wire it is wound from. An IRLZ44N MOSFET switches it from a 5 Hz clock, on for 100 ms and off for 100 ms, and the scope watches the drain, the node between the coil and the switch. A 1N4007 sits across the coil, band towards the supply, and a slide switch lets you take it out of the circuit.
Press Run with the diode in and open the Scope tab. Then click the switch to take the diode out, and look again.
While the coil is on
With the MOSFET on, the coil has 5 V across it and 50 ohms of winding in series, so its current rises towards 5 V / 50 ohm = 100 mA. It does not jump there. An inductor with a resistor has a time constant just as a capacitor with a resistor does, L / R, which is 10 mH / 50 ohm = 0.2 ms, so the current gets to its full 100 mA in about five of those, a millisecond, and stays there for the rest of the on time. The drain sits within a few millivolts of ground.
The energy stored in the coil at that current is half L I squared: 0.5 x 0.01 H x (0.1 A) squared, 50 microjoules. That is a tiny amount of energy. The trouble is not how much there is but how fast it has to go somewhere when the switch stops accepting it.
Switching off with the diode
At the falling edge the MOSFET turns off, and the coil tries to keep its 100 mA flowing down into the drain. The drain rises until the diode’s anode is a diode drop above the supply, about 5.8 V, and the diode conducts. The coil’s current now goes round a small loop, out of the bottom of the coil, up through the diode and back into the top, and dies away through the winding’s resistance in a fraction of a millisecond.
On the scope the drain steps up to about 5.8 V and settles back to 5 V. Nothing in that picture is more than a diode drop above the supply, which is the whole of the diode’s job. For that instant it carries the coil’s full 100 mA, so it has to be rated for the coil current, which a 1N4007 easily is.
Switching off without it
Now take the diode out. At the falling edge the coil still wants to push 100 mA into the drain, and the only paths left are the switched-off MOSFET and the scope’s own 1 megohm probe. To push 100 mA through a megohm would take 100 000 V. The coil runs out of energy long before that, but the drain still shoots up past 400 V within a few microseconds and is back down a few microseconds later. A 5 V circuit has just produced a spike eighty times its own supply.
To catch it, set the time base to its fastest, 10 us per division, the trigger to channel 1 rising, and turn the volts per division up until the peak fits on the screen. A spike that short is easy to miss at a slow time base, and a multimeter will never show it at all, which is why it surprises people on a real bench.
A real MOSFET or transistor would not see 400 V. A small one is rated somewhere between 30 and 100 V, and the coil’s energy is dumped into it instead, a small avalanche every time the coil switches off. Parts survive a lot of those and then one day stop working. Mokxi’s MOSFET has no breakdown, so you get to see the voltage the coil is trying to reach rather than the damage it would do.
What it costs, and a faster option
The diode makes the coil let go gently. The current decays round a loop with only a diode drop across it, so a relay’s contacts take a little longer to open than they would if the current were cut hard. For almost everything that does not matter. When it does, a Zener diode in series with the flyback diode lets the drain rise to a chosen voltage, say 12 V, and the current collapses several times faster, with the switch chosen to take that voltage.
Relay modules for Arduino include the diode on the board, which is why you rarely see one in a wiring diagram for them. A bare relay, a solenoid valve or a small motor driven from your own transistor needs one fitted by you.
Common mistakes
Fitting the diode the wrong way around. With the band towards the switched end of the coil it conducts the moment the switch turns on and shorts the supply through the switch. The band always goes to the positive end of the coil. Putting the diode across the transistor instead of across the coil is the other one: it does not give the coil’s current a loop of its own. And forgetting that a motor is a coil too. The motor on the transistor-as-a-switch page carries the same diode for the same reason, even though Mokxi’s motor model does not produce the spike.
Everything on this page is low voltage and safe to build. The same physics in an ignition coil or a mains transformer produces spikes that can hurt a person, which is one of the reasons those are not beginner projects.
Questions
Which way around does a flyback diode go?
Across the coil, with the band (the cathode) on the positive supply side and the anode on the side the transistor switches. It is reverse biased while the coil is on and only conducts when the coil is switched off.
What diode should I use as a flyback diode?
Any diode rated for at least the coil current and the supply voltage. A 1N4007 or 1N4148 is fine for a small relay; for a motor drawing an amp or more, a 1N4007 or a Schottky such as a 1N5819.
Do relay modules need a flyback diode?
Most Arduino relay modules already have one on the board, next to the relay, along with the transistor that drives it. A bare relay driven from your own transistor needs one added.
Why does my relay release slowly with the diode?
Because the coil’s current now decays gently round the diode loop instead of being cut off. Adding a Zener in series with the diode speeds the release up at the cost of a higher spike the transistor has to be rated for.
Keep going
Build this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.