Relay Driver
Switching a 50 mA lamp from a 20 mA pin
Relay
Transistor
Current
Isolation
What you will learn
- That a GPIO pin has a hard current limit (about 20 mA source, ~40 mA across all pins) and why exceeding it is not "a bit dimmer"
- How a base resistor converts that limit into a design: the pin only ever supplies base current, the load supply supplies everything else
- How an NPN transistor uses a small base current to switch a large collector current, and what saturation means
- What a relay gives you that a transistor cannot — a break in the wire between the control circuit and the load circuit
- Why every relay coil needs a flyback diode across it, and what a coil's stored magnetic energy does to the transistor without one
What you will need
| Component |
|---|
| 1× Arduino Uno |
| 1× pushbutton (the "call the lift" button) |
| 1× 10 kΩ resistor (pull-down, so the input never floats) |
| 1× 1 kΩ resistor (base resistor — this is the part that protects the pin) |
| 1× NPN transistor (2N2222) |
| 1× 5 V relay (SPDT) |
| 1× 1N4148 diode (flyback clamp across the coil) |
| 1× 9 V battery (the load's own supply — deliberately not the Arduino) |
| 1× LED (stands in for the lamp) |
| Breadboard |
| Jumper wires |
Step by step
Take it further
- Swap the NO contact for NC and the lamp turns on when the button is released — the other half of a relay's SPDT switch.
- Size the base resistor yourself: work out what base current a 2N2222 needs to saturate at 50 mA, pick the nearest standard value, then check the resulting base current still leaves the pin under 20 mA.
- Drive two relays from the same pin — one for the lift going up, one for the lift going down — and find out what happens if both are energised at once.
- Find out what an opto-isolator does that a relay does not, and why a mains-rated design might reach for one instead.
Practise it before you build it
Wire this circuit in the ThinkEdge Learn simulator first. The simulator runs a real Arduino sketch against a modified-nodal-analysis solver, so the LED on screen actually lights when the current is right — no hardware, no burnt components, and a class can try it in a browser.
Related projects
LED Light UpYour first circuit — light it up
Button-Controlled LEDPress to light, release to turn off
RGB Color Mixer — Three Switches, Seven ColorsMix any color with three separate LED channels
Arduino — Blink Without DelayUse millis() instead of delay() — the right way to blink
Arduino — Fade an LED with PWManalogWrite on D9 — the smoothest way to dim an LED
Arduino — Button + Buzzer DoorbellPress the button, hear a tone. The classic Arduino starter.
Guides that use this project
4 guides on the site build this project as part of a longer explanation. The guide says why the circuit works; this page says how to wire it.
How to Build a RobotHow to build a robot from scratch: one motor and a switch, then sensors, then a line-follower that steers itself. Every stage runs in a browser simulator first.
ESP32 IoT Projects: From a Single Sensor to a Live DashboardFive ESP32 IoT projects that teach sensors, MQTT publishing, deep sleep and reconnection, each staged so the logic runs in a browser simulator first.
Mesh Networking: How Nodes Relay Data for Each OtherA mesh network lets nodes relay data for each other. How flooding and hop limits work, what mesh costs in latency, and when a simple star is better.
GPU Repair: Why Graphics Cards Fail and Whether Fixing One PaysGraphics cards fail from solder fatigue, VRM breakdown, dead fans and ageing capacitors. How to diagnose the cause and whether a repair is worth the money.
Where this project sits
It is also part of these lists, which is how a class usually finds it.
Arduino LED projects for beginners36 projects in this list
Arduino push button projects for beginners14 projects in this list
Engineering projects for school students12 projects in this list
Try the full simulator with your class
103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. One licence covers a whole school.