Build it step by step
0 of 7 doneWire the control side
Connect VCC, GND and IN to the Uno.
Upload the sketch
Listen for the relay click every two seconds.
Check the contacts
With the 12 V adapter unplugged, wire COM and NO through the strip.
Plug in the adapter
The strip should switch on and off with the click.
Flip the logic
If it works backwards, change ACTIVE_LOW.
Look at the module
Find the flyback diode and the optocoupler on the board.
Try the other contact
Use NC (normally closed) and see the strip on when the relay is off.
How do you build a relay module lab at 12 V?
Switch a 12 V lamp with a relay module from an Arduino and see why a flyback diode and opto-isolation matter. You need Arduino Uno R3, Relay Module 5V, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 30 minutes.
- Level
- Beginner
- Time
- About 30 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- InterfacesBuyRelay Module 5V × 1
- OptoelectronicsBuy
- PowerBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Relay module VCC | Uno 5V | Coil power |
| Relay module GND | Uno GND | Ground |
| Relay module IN | Uno D7 | Control signal |
| 12 V adapter + | Relay COM | Supply into the relay contact |
| Relay NO (normally open) | LED strip + | Strip is powered when the relay closes |
| LED strip - | 12 V adapter - | Return path |
| Uno | USB cable to the computer | Power for the Uno, separate from the 12 V adapter |
Code
Only low voltage is used: a 12 V DC adapter and a 12 V LED strip. Never use mains in this lab, and never connect a mains load to a relay module on a classroom bench; mains wiring belongs to a qualified electrician. The relay coil is an inductor and makes a voltage spike when it switches off, which is why the module has a flyback diode across the coil and a transistor and optocoupler between your Arduino and the coil. Many modules turn on when the input is pulled low, so the code has a flag. Keep the 12 V wires short and tidy and check polarity before connecting the adapter. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Relay module control. Most blue relay boards are active-low: LOW turns the relay on.
const byte RELAY = 7;
const bool ACTIVE_LOW = true; // set false if your module turns on with HIGH
void relay(bool on) {
digitalWrite(RELAY, (on == ACTIVE_LOW) ? LOW : HIGH);
}
void setup() {
pinMode(RELAY, OUTPUT);
relay(false); // start off
Serial.begin(9600);
}
void loop() {
relay(true);
Serial.println("relay on");
delay(2000);
relay(false);
Serial.println("relay off");
delay(2000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
relay on relay off relay on relay off
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sketch running | Click every two seconds |
| 12 V strip on NO | On when the relay clicks on |
| Strip on NC | On when the relay is off |
| Active level wrong | Strip switches opposite to the serial text |
If it does not work
No click
Check the 5 V and GND to the relay board.
Clicks but no light
Check the COM and NO wiring and the adapter.
Uno resets when it clicks
Power the Uno separately from USB and keep wires apart.
Strip stays on
Check you used NO and not NC.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the relay module lab at 12 V?
Arduino Uno R3, Relay Module 5V, 12 V LED strip warm white (5 m, 2835), 12 V 2 A DC adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the relay module lab at 12 V take to build?
About 30 minutes for a beginner maker, in 7 steps.
How do I know the relay module lab at 12 V works?
Sketch running: Click every two seconds. 12 V strip on NO: On when the relay clicks on. Strip on NC: On when the relay is off.
No click: what should I check?
Check the 5 V and GND to the relay board.
Clicks but no light: what should I check?
Check the COM and NO wiring and the adapter.
Uno resets when it clicks: what should I check?
Power the Uno separately from USB and keep wires apart.
Strip stays on: what should I check?
Check you used NO and not NC.
