Relay Driver with Flyback Protection
Learn to safely control a relay with a transistor, including the essential flyback diode to protect against back-EMF spikes.
Overview
Relays are electromagnets that control switches—perfect for using a small signal to control a large load. But there's a catch: when you turn off a relay, the collapsing magnetic field creates a dangerous voltage spike (back-EMF) that can destroy transistors and microcontrollers. This project teaches you to add the essential flyback diode for protection.
Components Needed
- 1x Relay (5V or 12V coil, SPDT)
- 1x NPN Transistor (2N2222 or similar)
- 1x Diode (1N4001 or 1N4148)
- 1x Resistor 1kΩ
- 1x LED (any color)
- 1x Resistor 330Ω (for LED)
- 1x Push button (momentary)
- 1x 9V Battery (or appropriate supply for your relay)
- 1x 9V Battery clip
- 1x Breadboard
- severalx Jumper wires
Instructions
Understand the Relay
Find the relay coil terminals (usually marked). The other terminals are the switch contacts: Common (C), Normally Open (NO), Normally Closed (NC). When energized, C connects to NO instead of NC. Check your relay's coil voltage rating.
Build WITHOUT Flyback Protection First
Connect: Push button → 1kΩ resistor → transistor base. Transistor emitter to ground. Relay coil between supply voltage and transistor collector. When you press the button, the relay should click. DON'T skip to the protection step—we want to demonstrate the problem first.
Observe the Danger
In a dim room, watch the transistor closely as you release the button quickly. You might see a tiny spark or flash at the transistor—this is the back-EMF arcing across the transistor junction! Each spark degrades the transistor. (If using a microcontroller, this could destroy it instantly.)
Add the Flyback Diode
NOW add the 1N4001 diode ACROSS the relay coil with cathode (stripe) toward the positive supply. The diode is reverse-biased during normal operation (blocks current). When the transistor turns off, the coil tries to keep current flowing, forward-biasing the diode and providing a safe path.
Test Protected Circuit
Press and release the button multiple times. No more sparks! The clicking might sound slightly different—the relay releases a bit slower as energy safely dissipates through the diode.
Add Load LED
To see the relay switching a load: Connect an LED (with 330Ω resistor) between relay Common and ground. Connect relay NO terminal to the positive supply. Now the LED is controlled by the relay—button press turns LED on.
Challenges
- Measure the voltage spike without the diode using an oscilloscope (if available)
- Try a zener diode in series with the flyback diode for faster release
- Build a relay latch circuit (pressing button toggles relay on/off)
- Control the relay from a microcontroller (Arduino, Pi)—the diode is even more critical!
- Use the relay to switch a higher-power load (small motor, light bulb)
- Build a relay-based H-bridge for motor direction control