Arduino Relay Driver — Switching the Mechanical World

An Arduino can't switch a heavy load directly, but a 2N2222 can drive a small relay that can. Add a flyback diode, ship it.

Difficulty: Breadboard. Estimated build time: about 30 minutes. Estimated parts cost: about US$5.80. 7-line bill of materials. Compare supplier offers when available. A relay driver that lets a 5 V Arduino digital pin (sourcing 20 mA) switch a 5 V coil relay (drawing ~70 mA), which in turn switches a separate load circuit at any voltage and current within the relay's contact rating — typically 1 A at…

Wire the load side first

Take an LED + 470 Ω resistor + 9 V battery as your load. Connect battery + to 470 Ω → LED anode → relay COM (pin 1 on the G5V-1). Battery − → LED cathode is wrong; instead battery − → relay NO contact (pin 4). When the relay energizes, COM connects to NO and the LED lights. The Arduino is nowhere near this circuit.

Wire the coil

G5V-1 coil is between pins 2 and 5. Pin 5 → +5 V (Arduino's 5 V rail or a separate 5 V supply if your Arduino's regulator is overworked). Pin 2 → 2N2222's collector.

Add the flyback diode

Place a 1N4007 with its cathode at +5 V (pin 5) and its anode at the collector node (pin 2). When the coil de-energizes, the flyback voltage forward-biases the diode and circulates the inductive energy harmlessly through it instead of punching a hole through the transistor.

Wire the transistor

2N2222 in TO-92, pins (flat face up): emitter, base, collector. Emitter → GND. Collector → relay coil pin 2 (and the diode anode). Base → 1 kΩ → Arduino digital pin 8. The 1 kΩ resistor limits base current to ~4 mA, which is plenty to saturate the transistor at the ~70 mA collector current the coil needs.

Run a blink sketch

Set pin 8 OUTPUT in setup(), then digitalWrite(8, HIGH) and LOW alternately every second in loop(). You hear the relay click as it switches; you see the load LED toggle. The Arduino's GND and the load's GND are NOT connected — galvanic isolation, just like the optocoupler, but mechanical.