Learning Goals 5 min
Yesterday's build worked, but it had a hidden problem: every time the transistor switched off, the motor generated a spike that the transistor barely survived. Today we add the 3-cent part that fixes it. By the end of this lesson you will:
- Explain in your own words why a coil of wire (a motor, a relay, a solenoid) generates a high-voltage spike when its current is suddenly cut — the "inductive kick".
- Wire a 1N4001 (or 1N4148) flyback diode across the motor with the correct polarity — cathode (banded end) to battery +, anode to the transistor — and explain what happens if the polarity is wrong.
- Choose the right diode for a given motor: average current rating, peak current rating, and switching speed — and know why ultra-fast diodes (Schottky) are needed for PWM drives but standard rectifiers are fine for on/off.
Warm-Up 10 min
Rebuild yesterday's circuit (one-direction transistor switch). Make sure it's spinning on / off as before.
The hidden symptom
Watch the on-board LED on your Arduino very carefully (pin 13) while the motor is switching. On some boards / motors you'll see the LED flicker briefly at each off-transition. That's the inductive spike feeding back into the supply rail through the transistor's parasitic capacitances and momentarily upsetting the Arduino. With a more sensitive motor, the Arduino might even reset on every motor stop.
Recall: what's a diode?
A diode is a one-way valve for current. Symbol: an arrow pointing in the direction current is allowed. The little stripe on the physical diode marks the "cathode" — current flows into the unstriped end, out of the striped end. Try to push it the other way: nothing happens (until you exceed the diode's reverse-breakdown voltage, by which point you've usually destroyed it).
New Concept · Inductive kick + the protection diode 25 min
Why a coil resists current changes
A motor winding is a coil of wire. The key fact: the current through a coil cannot change instantly. The coil's magnetic field stores energy in proportion to the current. If you suddenly try to cut the current (e.g. by turning off a transistor), the magnetic field collapses very fast, and the coil generates whatever voltage it needs to keep the current flowing for an instant longer.
For a hobby motor switching ~500 mA, that "whatever voltage" can easily be 50–100 V — orders of magnitude above the 6 V supply. The spike appears across the transistor (collector to emitter) because the transistor has just become a tiny gap in the circuit.
What the spike does to a transistor
Most NPN transistors are rated for ~30–60 V collector-to-emitter. A 100 V spike exceeds that. Sometimes the transistor survives because the spike is brief. Other times it doesn't. Either way, you're stressing it on every switch-off — which kills it over hundreds of cycles even if it didn't die on cycle 1.
The fix: a parallel diode "across" the motor
Place a diode in parallel with the motor, reverse-biased relative to the normal current flow. That is:
- Anode (unbanded end, arrow head in the symbol) → motor − / transistor collector.
- Cathode (banded end, the line in the symbol) → motor + / battery +.
During normal operation, the diode is reverse-biased — no current flows through it. The motor sees the same voltage as before.
The moment the transistor switches off, the motor tries to push current in the same direction it was already going. With the diode there, that current finds a path: through the diode, back through the motor, in a tiny loop. The magnetic field bleeds off harmlessly through the motor's own resistance. No spike appears across the transistor.
Diode polarity — get it wrong, and…
If you wire the diode the other way round (cathode towards the transistor, anode towards battery+), it's forward-biased during normal operation. As soon as you energise the motor, the diode short-circuits the battery — through the diode it goes, motor never sees the current, diode immediately fries (and so does the battery wire, sometimes literally).
Picking a diode
| Diode | Average current | Speed | Best for |
|---|---|---|---|
| 1N4001 – 1N4007 | 1 A | Slow (~30 µs) | Simple on/off motor switching. Fine for < 1 A motors. |
| 1N4148 | 200 mA | Fast (~4 ns) | Small motors, relay coils, PWM up to a few kHz. |
| 1N5817 (Schottky) | 1 A | Very fast, low voltage drop | PWM drives at higher frequencies. Standard in H-bridge ICs. |
| SS34 / SS36 (Schottky, SMD) | 3 A | Very fast | L298N, motor controller modules. |
Rule of thumb: pick a diode rated for at least the motor's stall current and at least twice the supply voltage. For 6 V / 500 mA motors, a 1N4001 is overkill (1 A, 50 V reverse) — overkill is good here.
Bonus: the H-bridge already has flyback diodes inside
When we meet the L298N in L03-08, you won't need external flyback diodes on its outputs — they're built in. But understanding what they're doing is essential, because plenty of cheaper motor drivers don't include them, and you'll need to add them yourself.
Worked Example · Add the diode and test 25 min
Step 1 — identify the diode
Take a 1N4001 (or similar). You should see a black cylindrical body with a single white / silver band at one end. That band marks the cathode. The other end is the anode.
If you can't see the band, check with a multimeter on its diode-test setting: red probe to anode reads ~0.6 V (silicon diode forward drop). Reverse the probes → over-range (open circuit).
Step 2 — wire the diode in parallel with the motor
Pick the diode up by both leads. Look at its band. Then plug it into the breadboard so:
- Banded end (cathode) shares a node with the motor + lead.
- Other end (anode) shares a node with the motor − lead (which is also the transistor's collector).
You're building a small loop: motor and diode in parallel, both connected between the same two nodes.
Step 3 — re-upload yesterday's sketch and watch
const int MOTOR_GATE = 9;
void setup() { pinMode(MOTOR_GATE, OUTPUT);
}
void loop() {
digitalWrite(MOTOR_GATE, HIGH);
delay(2000);
digitalWrite(MOTOR_GATE, LOW);
delay(2000);
}The motor switches on / off as before — visually identical. The change is invisible at this scale, but in terms of transistor stress, it's the difference between "works forever" and "works for a few weeks".
Step 4 — the dramatic test (with a relay, if you have one)
The effect of a missing flyback diode is more obvious with a relay coil than a motor — relays have higher inductance per amp of running current. If you have a small 5 V relay module, swap it in for the motor (only the coil end, not the contacts). Pulse it on / off without a flyback diode and you may hear/see arcing or feel the transistor get warm. Add the diode → silent operation. (We'll meet relays properly later — for now, this is just the demonstration.)
Step 5 — deliberate wrong polarity (DON'T leave it like this!)
With the motor + battery disconnected, flip the diode round (cathode now towards the transistor). Reconnect briefly — the motor won't spin at all because the diode is now short-circuiting the battery through itself. The diode will get hot fast. Disconnect immediately. Test the diode with the multimeter — it may still work, or it may now be a 0 Ω short forever. Either way, you've seen what "wrong way round" looks like. Restore the correct orientation before moving on.
Step 6 — PWM test (preview of L03-09)
Switch to PWM with analogWrite at the default 490 Hz:
for (int duty = 0; duty <= 255; duty += 5) {
analogWrite(MOTOR_GATE, duty);
delay(50);
}
delay(1000);
for (int duty = 255; duty >= 0; duty -= 5) {
analogWrite(MOTOR_GATE, duty);
delay(50);
}At ~490 Hz, the 1N4001 is just fast enough to handle the switching cycles. If we crank the PWM frequency up to 10 kHz (which we'll do in L04 for quieter motors), the 1N4001 starts to overheat — that's when we switch to a Schottky like the 1N5817.
Basic 5 min
Goal: Replace the 1N4001 with a 1N4148 (200 mA fast diode). Confirm the small motor still runs cleanly. Why might the 1N4148 be a worse choice for a bigger motor?
Challenge 1 5 min
Goal: Add a second transistor + second motor + second flyback diode. Make them turn on alternately: motor 1 spins for 1 second while motor 2 stops, then swap. (You'll need a second base resistor + a second Arduino pin.)
Challenge 2 5 min
Goal: Drive a 5 V relay's coil with the same one-transistor + flyback-diode circuit. Use the relay's contacts to switch an LED that's on a different power supply (e.g. another 4 × AA pack). Watch the LED come on / off in step with your transistor signal.
Challenge 3 · Pick and check the diode 10 min
Your parts box holds these four diodes:
| Diode | Max current | Max reverse voltage | Speed |
|---|---|---|---|
| 1N4001 | 1 A | 50 V | Slow |
| 1N4148 | 200 mA | 75 V | Fast |
| 1N5817 | 1 A | 20 V | Very fast |
| SS34 | 3 A | 40 V | Very fast |
Use the rule of thumb from New Concept. The current rating must be at least the stall current. The voltage rating must be at least twice the supply. PWM above about 5 kHz needs a fast diode.
- Build 1: a 6 V motor with a stall current of 800 mA, switched on and off. Which diodes pass all three checks?
- Build 2: a 5 V relay coil of 200 Ω. Work out the coil current. Which is the smallest diode that passes?
- Build 2, continued: without a diode the kick reaches about 50 V. Your transistor is rated 60 V. How much margin is left? With the diode fitted, roughly what does the collector rise to?
- Build 3: a 12 V motor with a stall current of 2.5 A, on PWM at 10 kHz. Which diode do you pick? Give the reason each of the other three fails.
- Wiring: for Build 2, which end of the coil does the diode's band go to?
It works if every diode you pick passes all three checks, with the sums written out.
Recap 5 min
The inductive kick is the biggest hidden hazard in motor driving. Any coil — motor, solenoid, relay — generates a huge voltage spike when its current is cut. The fix is one cheap part: a diode wired across the load, banded end (cathode) towards the supply +. The diode does nothing while the motor runs and conducts only the spike. Pick a diode rated for at least the motor's stall current and twice the supply voltage. Standard rectifiers (1N4001) for on/off; Schottky (1N5817) for fast PWM. Tomorrow we move from one-direction switching to full forward/reverse/brake/stop control using a single chip: the L298N H-bridge.
- Inductive kick / flyback voltage
- The brief, large voltage spike a coil generates when its current is suddenly cut. Can exceed the supply voltage by 10–100× for hobby motors.
- Inductance
- The property of a coil that resists changes in current. The energy stored in the magnetic field has to go somewhere when you switch off; the flyback voltage is the result.
- Flyback diode
- A diode placed in parallel with an inductive load, reverse-biased during normal operation, that provides a current path for the inductive kick when the load is switched off.
- Anode / cathode
- The two terminals of a diode. Current flows anode → cathode in the forward (low-resistance) direction; reverse direction blocks. Cathode is marked with a band on the physical part.
- Forward voltage drop
- The small voltage (~0.7 V for silicon, ~0.3 V for Schottky) that appears across a conducting diode. The lower the drop, the less heat the diode dissipates during the flyback event.
- Reverse breakdown
- The reverse voltage at which a diode stops blocking and conducts catastrophically. A 1N4001 is rated 50 V reverse — plenty for a 6 V battery; the 1N4007 (1 kV) is overkill for hobby uses.
- Schottky diode
- A faster, lower-drop diode used where switching speed matters (PWM > 1 kHz, switching regulators). More expensive than a standard rectifier; usually worth it for motor PWM.
Extra Mission 5 min
Part 1 — Design a coil-powered gadget
Motors, relays and solenoids are all coils, and all need a flyback diode. Design a small battery-powered gadget that uses one. Ideas: a relay that switches a separate LED lamp, a solenoid door chime, or a bubble-machine fan. Keep everything on batteries — never mains.
Your design must include:
- The coil device, its voltage, and its current (show the sum).
- The diode you would use, with the current and voltage checks written out.
- A circuit drawing with three coloured arrows. Green shows the coil current when the transistor is on. Red shows the flyback current at switch-off. Blue shows the control current from the pin.
- What makes the gadget switch on: a button, a timer or a sensor.
Part 2 — Make it
Build the transistor-and-diode circuit from today. Drive your motor, or a relay coil if you have one, from your chosen trigger. Use a button on D2 or a timed on/off pattern in loop(). Check the diode's band points to battery + before you power up.
It works if the coil switches cleanly on your trigger, and the diode and transistor stay cool.
Bring back next class: your design, your uploaded sketch, and a close-up photo showing the diode's band. Also bring an L298N motor driver, two DC motors and a fresh battery pack for L03-08.