ToolSphere
All perfboard layouts

Relay Driver Circuit Perfboard Layout

A relay coil needs far more current than a GPIO pin can give, and it kicks back a voltage spike when switched off. This board handles both: an NPN transistor switches the coil, a 1N4007 diode across the coil absorbs the spike, and the relay's contacts go out to a 3-way terminal.

Relay driver perfboard layoutK1 RELAY 5VD1 1N4007Q1 2N2222RB 330RJ1 INJ2 CONTACTS
Open this layout in the simulator Connection check: no shorts, 8 named nets

Red wires carry power, white is ground, yellow and blue are signals. Every hole is an isolated pad; connections are the wires shown. In the simulator you can move parts, add your own and re-run the check.

Parts list

As an Amazon Associate, ToolSphere earns from qualifying purchases.

How it works

A typical 5 V relay coil is about 70 Ω, so it draws:

I_coil = 5 V ÷ 70 Ω ≈ 71 mA

To switch it fully on, give the transistor a base current of about a tenth of that, around 7 mA:

RB = (3.3 V − 0.7 V) ÷ 7.1 mA ≈ 364 Ω  →  use 330 Ω (7.9 mA)

That is within what a 3.3 V microcontroller pin can supply. Check your relay's coil resistance on its datasheet or with a multimeter and redo the sum if it differs.

The diode matters. When the transistor turns off, the coil's magnetic field collapses and drives the collector voltage far above 5 V. The 1N4007, fitted with its cathode (stripe) to +5V, gives that current a safe path. Without it the transistor eventually fails.

The contacts (COM, NO, NC) are a separate, isolated switch: wire your load through COM and NO for "on when energised".

Building it, step by step

  1. Run +5V along the top row and GND along the bottom; join the microcontroller's ground to this GND.
  2. Fit the relay, then the 1N4007 across its coil with the stripe (cathode) to +5V.
  3. Fit the 2N2222 with its collector to the coil's lower end and its emitter to GND.
  4. Fit the 330 Ω base resistor between the GPIO input and the base.
  5. Bring COM, NC and NO out to the terminal. For mains loads use a relay rated for it, keep the high-voltage side well away from the low-voltage side, and enclose it.

Tools for this build

Frequently asked questions

Why does a relay need a diode?

Switching off a coil makes a voltage spike that can destroy the transistor. A diode across the coil, cathode to the positive supply, lets that current circulate harmlessly.

Can a 3.3 V microcontroller drive a 5 V relay?

Not directly from the pin, but through a transistor, yes: the pin supplies a few mA of base current and the transistor switches the coil from the 5 V supply.

What is the difference between NO and NC?

NO (normally open) connects to COM only while the coil is energised; NC (normally closed) connects to COM while it is off.