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.
Try It Yourself 15 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?
Reveal
The 1N4148 is rated for only 200 mA peak. For a small (no-load < 100 mA, stall < 200 mA) motor it's fine. For anything bigger, the diode would fry on the first inductive kick — which can briefly approach the motor's stall current. Match the diode to the worst-case current the motor can produce.
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.)
Hint
const int M1 = 9, M2 = 10;
void setup() {
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop() {
digitalWrite(M1, HIGH); digitalWrite(M2, LOW);
delay(1000);
digitalWrite(M1, LOW); digitalWrite(M2, HIGH);
delay(1000);
}Be careful with the battery budget — two motors at ~500 mA each is approaching the limit of 4 × AA. If your Arduino resets, you need a bigger pack.
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.
Hint
Relay wiring: coil pins are usually the two on one side, marked + and −. The other three pins are the contacts: COM (common), NO (normally open), NC (normally closed). Wire your LED through COM and NO so it's on only when the relay is energised. Don't forget the flyback diode across the coil — relays have lots of inductance per amp.
This is a real-world "control a high-voltage load from a microcontroller" pattern. Industrial gear (lights, pumps, garage doors) does it the same way.
Mini-Challenge · Annotate the symbol 10 min
Open a blank page in your notebook and draw the full circuit symbolically:
- Battery as two parallel lines, long = +, short = −.
- Motor as a circle with an M inside it.
- Transistor as the standard NPN symbol (three terminals with an arrow on the emitter pointing away).
- Flyback diode as a triangle pointing at a line (triangle = anode, line = cathode).
- Arduino pin as a small box labelled "D9".
Add labels and arrows for:
- The motor current path when the transistor is ON (green arrow).
- The flyback current path when the transistor switches OFF (red arrow — through the motor, through the diode, around in a loop).
- The control current path (Arduino pin → resistor → base → emitter → GND) (blue arrow).
Three colour-coded arrows on one diagram. This is the canonical "motor switch with flyback" circuit — you'll see it inside the L298N's schematic in L03-08, inside servo drivers, inside relay boards, inside almost every motor control PCB you ever buy.
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.
Homework 5 min
- Find one product in your house that opens an electrical switch under microcontroller control: a smart plug, a relay-driven appliance, a printer's motor driver. Open the casing (only if you can do so safely) or look up the datasheet image online. Spot the flyback diode. Take a photo or screenshot.
- Calculate: a relay coil of 200 Ω resistance running on 5 V draws how much current? When you turn it off, the inductive kick can easily exceed 50 V. If your transistor is rated 60 V VCE, are you safe? Add a flyback diode — what does the "spike" voltage become?
- Bring tomorrow: an L298N motor driver module (the bright red board with the big heatsink) + two DC motors + a fresh battery pack. We'll wire bidirectional control for the first time.
Bring back next class:
- Your annotated 3-arrow schematic from §6.
- Your relay-coil maths.
- L298N + two motors + battery pack for L03-08.