Sub topic 8
Protecting Your Circuit with a Flyback Diode
Assume you can upload Arduino sketches, use pinMode() and digitalWrite(), and understand voltage, current, and ground. This chapter focuses on a small brushed DC motor switched by a transistor or MOSFET. A hobby servo usually contains its own motor driver, so its external wiring is different.
Why a motor creates a voltage spike
A motor contains coils of wire. A coil resists sudden changes in current. While the motor runs, current creates a magnetic field in those coils. When a MOSFET suddenly turns off, the current still tries to flow.
The motor then raises its terminal voltage until it finds a path for that current. This event is called inductive kickback or flyback. The voltage can damage the MOSFET, Arduino pin circuitry, or other components. It can also create electrical noise that causes resets and unreliable sensor readings.
A flyback diode gives the stored energy a safer path. It is connected in parallel with the motor, not in series.
Correct diode orientation
For a low-side switch, connect the motor between the positive external supply and the MOSFET drain. Connect the MOSFET source to ground. Place the diode across the motor:
- The cathode goes to the motor terminal connected to the positive supply.
- The anode goes to the motor terminal connected to the MOSFET drain.
- The diode is normally reverse-biased while the motor runs.
- When the MOSFET turns off, the diode becomes forward-biased and carries the collapsing current.
The cathode is usually marked with a stripe. Check the diode's datasheet instead of relying only on its appearance.
Selecting and installing the diode
The diode must tolerate the motor's current pulse. A useful starting point is a diode with a forward-current rating at least as high as the motor's expected running current, while also considering the motor's stall current. Its reverse-voltage rating must exceed the motor supply voltage.
| Choice | Typical use | Important consideration |
|---|---|---|
| 1N400x diode | Low-frequency switching | Often acceptable for simple on/off control |
| Schottky diode | PWM and faster switching | Lower forward voltage, but check reverse leakage and voltage rating |
| Driver-integrated clamp | H-bridge modules | Follow the module's datasheet and wiring guide |
A diode across a motor reduces the voltage spike but also makes the motor current decay more slowly. For ordinary Arduino PWM control, this trade-off is usually acceptable. High-speed or high-power designs need calculations and a diode selected for the switching frequency and current waveform.
Example: PWM motor control
The Arduino's PWM output controls the MOSFET gate. The diode does not change the sketch. It protects the hardware when the PWM signal switches off.
// Low-side MOSFET switch with a flyback diode.
// Arduino pin 5 -> 100-220 ohm resistor -> logic-level MOSFET gate.
// Add a 10k pulldown from gate to GND.
// Motor: external supply (+) -> motor -> MOSFET drain.
// MOSFET source -> common GND.
// Diode across motor: cathode to supply (+), anode to drain.
// External supply GND must connect to Arduino GND.
const int MOTOR_PIN = 5;
void setup() {
pinMode(MOTOR_PIN, OUTPUT);
}
void loop() {
for (int speed = 0; speed <= 255; speed += 5) {
analogWrite(MOTOR_PIN, speed);
delay(40);
}
for (int speed = 255; speed >= 0; speed -= 5) {
analogWrite(MOTOR_PIN, speed);
delay(40);
}
}Limits of the simple arrangement
This diode orientation is for one-direction, low-side switching. Do not place the same diode directly across a motor driven by an H-bridge, because an H-bridge reverses the motor terminals. Use the protection components specified by the H-bridge module or driver datasheet.
If the Arduino resets when the motor starts, the diode may be correct but insufficient by itself. Check the shared ground, use a separate motor supply, shorten motor-current wiring, and add suitable capacitors near the motor supply and driver.
Exercise
In a low-side MOSFET circuit, where should the flyback diode's striped end connect?
Show answer
The striped cathode should connect to the motor terminal connected to the external supply's positive terminal. The anode connects to the MOSFET drain side.