Circuits / Transistors
Relay with an NPN and a flyback diode
A small base current lets the coil's 71 mA flow; the coil pulls the contact over and the LED lights. Released, the diode takes the coil's current (without it, its voltage would jump far past the supply)

Tap a part to see its voltages and currents. It is a model, not a measurement.
What do you need?
- Push buttonSearch on Amazon
- Resistor 1 kΩSearch on Amazon
- Relay SRD-05VDC-SL-CSearch on Amazon
- Diode 1N4007Search on Amazon
- Bipolar transistor 2N2222ASearch on Amazon
- Resistor 330 ΩSearch on Amazon
- Red LEDSearch on Amazon
- Jumper wires × 6Search on Amazon
- BreadboardSearch on Amazon
Why does a relay need a transistor and a diode?
A relay is a switch moved by an electromagnet. This coil is 70 Ω, so at 5 V it wants about 71 mA, more than a microcontroller pin should give. So a transistor carries it: pressing S1 sends about 4.2 mA through R1 (1 kΩ) into the base of a 2N2222A, and the coil's current flows. About 7 ms later the contact has moved, COM meets NO and the LED lights with about 9.8 mA. The contact is insulated from the coil, which is the point of a relay: here both share the 5 V, but a small signal can switch something electrically apart. Release S1 and the coil's current cannot stop at once. Without D1 (1N4007) the voltage jumps to hundreds of volts in this model, far past the 2N2222A's 40 V limit. With D1 that current, about 70 mA, circles through the diode, the coil's voltage stays under 1 V and the contact lets go a little later, 4.2 ms rather than 2 ms in this model.
Values from the Protoboard ISO simulation: a model, not a bench measurement.
Hear about the next circuit
One email when a new circuit is out, about twice a month. Nothing else.