← Block library

Relay Driver

@electrace/relay-driver@1.0.0 · CC-BY-4.0
vcoil 5–24 Vicoil_max 0.2 Avctrl 3–5.5 V
The actual schematic inside this block — every part is explained below.

Relay Driver

A GPIO can't drive a relay coil — 30–150 mA is 10× what a pin can source, and the coil bites back when you turn it off. One transistor and one diode fix both problems.

  • Q1 — an NPN switch on the coil's low side. The GPIO supplies a few milliamps of base current; the transistor sinks the full coil current. Wire the coil between vcc and coil.
  • R1 (1 k) — sets the base current: (3.3 V − 0.7 V) / 1 k ≈ 2.6 mA. The rule of thumb is base ≈ collector ÷ 10 for solid saturation — 2.6 mA comfortably saturates a 100 mA coil load.
  • D1 — the famous flyback diode, and the reason this block exists. A coil is an inductor: its current cannot stop instantly. Open Q1 without D1 and the coil voltage flies up — hundreds of volts — until something breaks down, usually Q1. D1 sits reversed across the coil doing nothing… until turn-off, when it gives that current a quiet loop to decay through.

Exposes: ctrl (GPIO), vcc (coil supply — also the flyback return), coil (the coil's low side), gnd.

⚠ The relay's contact side is a separate world — this block drives the coil only. Switching mains on the contacts is its own safety problem (creepage, isolation, fusing) that no driver circuit solves for you.

Exposed nets

ctrlin · signal
vccin · power · 5–24 V
coilout · signal
gndin · gnd

Inside this block

Q1
npn-gp
the switch — saturates to pull the coil's low side to ground; a garden-variety NPN handles a signal relay easily
R1
1k
sets the base current (~3 mA at 3.3 V) — enough to saturate Q1 at 10× less than the coil current
D1
flyback
the flyback path — catches the coil's inductive kick at turn-off so it never reaches Q1

Limits & gotchas

flyback.note 0D1 is NOT optional. A relay coil is an inductor; cutting its current without a flyback path generates hundreds of volts at the transistor's collector. The diode gives the coil current somewhere to go while it dies down.
icoil.max 0.2ASized for typical 5–24 V signal relays (30–150 mA coils). A contactor-class coil needs a bigger transistor — check the coil's rated current, not the contact rating.
Use this block in a real design
Drop it on a canvas, wire it up, and watch the live checks — free, no card.
Start designing →
This page is generated from the block's source — the same content powers the editor's explanations and live checks.