Drive a relay: a schematic puzzle

A 3.3 V pin switches a 12 V coil, and one small diode keeps the transistor alive.

The pin cannot supply the coil's current, so it only nudges the transistor's base through the resistor. A few milliamps into the base let a hundred flow from collector to emitter, which pulls the coil to ground and closes the relay. When the pin goes low, the coil's magnetic field collapses and tries to keep current flowing, driving the collector voltage far above 12 V. The diode gives that current a short loop back into the coil, so the spike never reaches the transistor. Think of a heavy door: the transistor is the person opening it, the resistor is the polite knock, and the diode is the soft-close hinge that stops it slamming.

1 kΩ base resistor: Sets the base current: (3.3 V − 0.7 V) ÷ 1 kΩ ≈ 2.6 mA, enough to switch the transistor fully on while staying well inside what a microcontroller pin can give.

2N2222 NPN transistor: The muscle. A small base current lets a much larger coil current flow from collector to emitter, so the 3.3 V pin never touches the 12 V side.

Relay coil, 12 V: The load. Current through the coil makes a magnet that pulls the relay contacts closed, letting a tiny circuit switch a big one.

1N4007 flyback diode: Normally it does nothing: 12 V is on its cathode, so it is reverse-biased. The instant the transistor turns off, the coil's voltage flips and the diode conducts, letting the stored energy circulate harmlessly in the coil until it fades.

Related