Switches & motion
Relay
A switch flipped by an electromagnet. A small current in the coil pulls a metal blade over, so a microcontroller can switch a big or mains-voltage load that shares no wires with it.
Think of it as: Ringing a doorbell that wakes someone to throw a heavy lever for you.
Pins
- Coil (2 pins)
- : The control side. Usually 5 V or 12 V, drawing 30 to 100 mA.
- COM
- : The common contact: the moving blade.
- NO / NC
- : Normally open (connects to COM when the coil is on) and normally closed (connects when it is off).
The common blue cube relays switch 10 A at 250 V AC from a 5 V coil. Relay modules add the transistor, flyback diode and an LED on a small board.
What to look for inside
- The coil is switched on for 4 seconds, then off.
- With the coil on, it becomes an electromagnet (purple field) and pulls the iron blade down against the spring. The contacts close and the lamp lights.
- Notice the short delay: a relay takes 5 to 15 ms to move. When the coil switches off, the spring pulls the blade back.
- The lamp circuit and the coil circuit never touch. That isolation is why relays can switch mains safely from a 5 V board.
The numbers that matter
| Spec | Typical |
|---|---|
Coil voltage Drive it with this voltage. Too little and it won’t pull in. | 5 V · 12 V · 24 V |
Coil current / resistance Too much for a microcontroller pin: use a transistor. | 70 mA · 70 Ω (5 V) |
Contact rating What the contacts can switch. DC is harder to break than AC. | 10 A 250 V AC · 10 A 30 V DC |
Operate time Relays are slow: no good for PWM. | 5 ms to 15 ms |
Where you’ll use it
- Switching mains appliances (lamps, heaters, pumps) from a microcontroller.
- Switching loads that need full isolation from the control circuit.
- Car electrics: horns, headlights, starter motors.
Common mistakes
- No flyback diode across the coil. The coil is an inductor: switching it off makes a spike that destroys the transistor driving it.
- Driving the coil straight from a GPIO pin. It needs far more current than the pin can give.
- Trying to PWM a relay. It can only click on and off a few times a second.
Lessons that use it
Lesson 2.4 has a relay-coil preset and shows the flyback spike; lesson 3.2 shows the MOSFET that drives it.
- Lesson 2.4: Inductors & the Flyback Diode Explained
- Lesson 3.2: MOSFET as a Switch: Gate Voltage & Heat
Go deeper
Coil current, and why switching it off without a diode makes a huge spike.