Sub topic 8
Protecting your circuit with a flyback diode
This chapter assumes you can upload sketches, use digitalWrite and analogWrite, and read a basic schematic. You should also know that a motor needs its own supply with a shared ground, and that a motor can draw far more current than an Arduino pin can give. The next chapter builds the MOSFET switch. Here we look at the part that keeps that switch alive.
The problem: a motor is an inductor
A DC motor is a coil of wire wound around an iron core, so part of its behavior is that of an inductor. An inductor resists changes in current. While current flows, the coil stores energy in a magnetic field. The relevant relationship is:
V = L * di/dtL is the inductance in henries, and di/dt is how fast the current changes. When a switch opens, the current tries to drop to zero almost instantly. A very large di/dt produces a very large voltage across the coil. The coil pushes current in the same direction it was already flowing, and it will generate whatever voltage it takes to do so.
That voltage spike is called inductive kickback or a flyback spike. With a 6 V motor and a fast transistor, the spike can reach tens or even hundreds of volts for a few microseconds. It appears at the point where the motor meets the switch, and it can:
- Exceed the drain-to-source rating of the MOSFET and destroy it.
- Couple back through the MOSFET gate and damage the Arduino pin.
- Inject noise into the supply and ground, causing resets and erratic readings.
- Make small arcs at mechanical switch contacts, which wears them out.
The spike only happens when current is interrupted. That includes every falling edge of a PWM signal, so a motor driven at 490 Hz or 980 Hz generates hundreds of spikes per second.
The fix: give the current somewhere to go
The inductor's current must continue for a short time. If you provide a path, the current circulates there and decays gently. A diode placed across the motor does exactly this. It is called a flyback diode, and it is also known as a freewheeling diode, a snubber diode, or a catch diode.
The diode is wired in reverse across the motor, so it does nothing during normal operation:
- Motor running: the supply side of the motor is more positive than the switch side. The diode is reverse-biased and blocks current.
- Switch opens: the motor's polarity reverses as the coil pushes current onward. The diode is now forward-biased and conducts. The current loops through the motor and diode until the stored energy is spent as heat.
The voltage across the motor is clamped to about one diode drop (0.7 V for a silicon diode) above the supply, instead of climbing to hundreds of volts.
Orientation: which way does the diode face?
A diode has an anode (the positive side for conduction) and a cathode (marked by a stripe on most through-hole parts). Current flows from anode to cathode.
For a motor between the supply positive rail and a low-side switch, wire the diode like this:
- Cathode (stripe) to the motor terminal connected to the supply positive.
- Anode to the motor terminal connected to the MOSFET drain.
This matches the wiring comment in the MOSFET example sketch: the flyback diode sits across the motor with the cathode toward the supply positive. A quick check is to ask whether the diode would conduct if you simply connected the supply across it. If it would, it is backwards, and it will short your supply the moment the motor is powered. That produces heat, a collapsing supply, and possibly smoke.
Choosing a diode
The diode must handle three things: the current, the voltage, and the speed.
| Property | What to check | Typical choice for small motors |
|---|---|---|
| Forward current rating | At least the motor's stall current, since the kickback current equals the current that was flowing | 1 A or more |
| Reverse voltage rating | Above the supply voltage with a margin | 40 V or higher for a 6 to 12 V supply |
| Switching speed | Must turn on quickly, because PWM edges are fast | Schottky or fast-recovery |
Common parts are:
- 1N4001 to 1N4007: general-purpose rectifier diodes rated at 1 A. They work for small motors at low PWM frequencies. They turn on more slowly, so at higher PWM frequencies they clamp less well.
- 1N5817, 1N5819: 1 A Schottky diodes. They have a lower forward drop (around 0.3 to 0.45 V) and switch faster. They are a good default for PWM work.
- 1N4148: a signal diode rated at around 200 mA. It is too small for most motors and is a common mistake because it looks similar.
The kickback current equals the current the motor was drawing at the moment the switch opened. A motor that draws 800 mA when loaded sends 800 mA through the diode, and the stall current is the worst case. Pick a diode rated above that value.
Where to place the diode physically
Put the diode as close to the motor terminals as you can, ideally soldered directly onto them. A long wire between the motor and the diode adds its own inductance, and that wire's inductance creates a smaller spike of its own. On a breadboard, keep the leads short and make the diode's two connections land at the same two points the motor wires use.
What the diode does not do
A flyback diode handles one specific problem. It does not:
- Remove the broadband noise created by brushes making and breaking contact. A ceramic capacitor across the motor terminals handles that, and the chapter on noise and brownouts covers it.
- Prevent a brownout when the motor starts. That is an inrush current problem solved with supply capacity and bulk capacitance.
- Protect against reversing the supply connection.
- Work for a motor that you drive in both directions through an H-bridge using only one external diode. The bridge needs diodes in each leg, or a driver that has them built in.
Do I need one with an H-bridge driver?
Dedicated driver chips such as the TB6612FNG include internal clamp diodes (body diodes in the output transistors) that handle the kickback from one motor. For a small motor within the chip's current rating, you normally do not add anything. Check the datasheet for your exact chip. Older bipolar drivers such as the L293D also include internal clamp diodes. The L298N module is a frequent exception: its chip does not include them, but most breakout boards add external diodes. If the board shows a ring of diodes near the output terminals, it has them.
When in doubt, a Schottky diode across the motor terminals does no harm, as long as the driver output is not being used for direction reversal through that diode. With a bridge, put the diodes from each output to the supply and from each output to ground, which is what the internal body diodes already do.
The same applies to other coils
Anything that contains a coil needs the same protection when switched by a transistor:
- Relay coils
- Solenoids
- Electromagnets
- Buzzers that use a coil (not piezo ones)
The wiring is identical: a reverse-biased diode directly across the coil.
Testing the effect
You cannot see a spike without an oscilloscope, but you can notice its effects. Without a diode, a PWM-driven motor circuit often shows these symptoms:
- The Arduino resets or freezes when the motor starts or stops.
- A MOSFET that works for a few minutes and then stops switching, staying either permanently on or permanently off.
- Unrelated pins reading wrong values when the motor runs.
With the diode installed, these should disappear or become much less frequent. The sketch below uses the same low-side wiring as the MOSFET example and is useful for testing that the diode is in place. It runs the motor at a fixed duty cycle and toggles it, producing a regular stream of switching events.
// Switching stress test for a low-side MOSFET motor circuit.
// Wiring is the same as the MOSFET chapter: pin 5 -> 100-220 ohm -> gate,
// 10k pull-down from gate to GND, flyback diode across the motor
// with its cathode (stripe) toward the supply positive.
const int MOTOR_PIN = 5;
void setup() {
pinMode(MOTOR_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Starting switching test");
}
void loop() {
analogWrite(MOTOR_PIN, 180); // about 70 percent duty
delay(1000);
analogWrite(MOTOR_PIN, 0); // abrupt stop: the worst case for kickback
delay(1000);
Serial.println(millis());
}If the serial output keeps printing a rising millis() value once per two seconds, the Arduino is not resetting. If the numbers restart from near zero, the board is rebooting on each stop, and the diode is missing, backwards, or too slow.
Common mistakes
- Diode backwards. The supply is shorted, or the diode does nothing useful.
- Diode too small. A 1N4148 across a motor that draws an amp burns out the first time the motor stalls.
- Diode far from the motor. Long leads add inductance and weaken the clamp.
- Diode connected to the Arduino side. It must be across the motor, not across the gate or the signal pin.
- Assuming the driver board has one. Check the schematic or look for the diodes on the board.
Exercise
A small DC motor is connected between a 9 V supply and the drain of a low-side N-channel MOSFET. You solder a 1N5819 Schottky diode across the motor. Which end of the diode goes to the 9 V supply, and why does the diode not conduct while the motor runs normally?
Show answer
The cathode (the striped end) goes to the 9 V supply side and the anode goes to the MOSFET drain side. While the motor runs, the supply side is more positive than the drain side, so the diode is reverse-biased and blocks. When the MOSFET turns off, the coil drives the drain side above the supply, the diode becomes forward-biased, and the motor current circulates through it instead of building a large voltage spike.
Exercise
Your sketch ran the motor at full PWM duty and your Arduino reset each time the motor was turned off. You then discovered the diode was installed with the stripe toward the drain. Explain what is happening at turn-on and what you should change.
Show answer
With the stripe toward the drain, the diode is forward-biased between the supply and the drain whenever the MOSFET is off, and it conducts from the supply into the motor's drain-side terminal, so the motor effectively has current bypassing the switch. When the MOSFET is on, the diode shorts the supply through the MOSFET, which makes the supply sag and can reset the Arduino. Swap the diode so the stripe faces the supply positive terminal.