What is the 5V Relay Module?
A relay module is the simplest way to let a microcontroller turn something bigger on and off: a 12 V pump, an LED strip, a solenoid lock, a fan, or (carefully) a mains lamp. The Arduino never touches the load. It only energises a small coil, and the coil pulls a metal contact that closes a completely separate circuit.
The common blue 1-channel module carries a Songle SRD-05VDC-SL-C relay, a transistor to drive its coil, a flyback diode, a status LED and, on most versions, an optocoupler. That extra circuitry is why you can connect it straight to a GPIO pin instead of building the driver yourself. This page explains what each part does, how to wire the load side, why most modules switch ON when the input is LOW, and what changes on a 3.3 V ESP32.
Specifications
- Relay
- Songle SRD-05VDC-SL-C (or equivalent)
- Coil voltage
- 5 V DC (operates from about 3.75 V)
- Coil current
- about 70–75 mA while ON (coil ≈ 70 Ω)
- Contact rating (relay)
- 10 A at 250 V AC, 10 A at 30 V DC
- Practical module limit
- about 5 A continuous; PCB traces and screw terminals are the weak point
- Contact form
- SPDT: COM switches between NC and NO
- Input (IN) current
- about 1–5 mA, depending on optocoupler and LED
- Trigger
- usually active LOW; some boards have an H/L jumper
- Switching time
- about 10 ms to operate, 5 ms to release
- Isolation
- optocoupler versions, with the JD-VCC jumper removed
Relay figures from the Songle SRD datasheet. Module limits vary between makers, so treat 10 A as the relay's rating, not the board's.
Relay module pinout
| Pin | Side | What it does |
|---|---|---|
| VCC | Control | 5 V supply for the coil driver and LED |
| GND | Control | Ground, shared with the microcontroller |
| IN | Control | Signal from a GPIO pin. LOW turns the relay ON on active-LOW boards |
| COM | Load | Common contact: connect one wire of the load circuit here |
| NO | Load | Normally open: connected to COM only while the relay is ON |
| NC | Load | Normally closed: connected to COM while the relay is OFF |
| JD-VCC | Jumper | Separate coil supply on optocoupler boards (jumpered to VCC by default) |
Wiring & code
Setting up 5V Relay Module with Arduino Uno
Library
None needed by Arduino core
No library required: the sketches use digitalWrite() and digitalRead(), which are built into Arduino.
This guide wires a 1-channel 5 V relay module to an Arduino Uno, switches it on a timer, then adds a push button that toggles the relay on each press. Because the Uno is a 5 V board, the module connects directly: no level shifting, no extra transistor. Read the relay module overview first if NO, NC and active LOW are new to you.
Parts
| Part | Qty | Notes |
|---|---|---|
| Arduino Uno (or Nano) | 1 | Any 5 V Arduino works the same way |
| 5 V 1-channel relay module | 1 | SRD-05VDC-SL-C type |
| Push button | 1 | For the toggle example |
| Jumper wires | 5 | Female-to-male for the module header |
| Test load | 1 | A 12 V lamp or LED strip with its own supply |
Step 1. Wire the control side
Unplug the USB cable while wiring. The relay module needs three wires from the Uno:
Wiring: relay module to Arduino Uno
| Module pin | Uno pin | Note |
|---|---|---|
| VCC | 5V | Powers the coil driver: about 75 mA when ON |
| GND | GND | Common ground |
| IN | D7 | Any digital pin works; D7 is clear of serial and SPI |
- 1Red wire: Uno 5V to module VCC.
- 2Black wire: Uno GND to module GND.
- 3Signal wire: Uno D7 to module IN.
- 4Leave the screw terminals empty for now. Test the click first, then add a load.
Tip
One Uno can power one or two relays from USB. Each energised relay draws about 75 mA. For four or more, power the module from a separate 5 V supply and join its ground to the Uno's GND.
Step 2. Click the relay on a timer
Upload this sketch. The relay should click on for two seconds, off for two seconds, and the module's red LED should follow it. The Serial Monitor at 9600 baud prints the state.
// 5V relay module on Arduino Uno: timed on/off
// Most modules are active LOW: LOW = relay ON, HIGH = relay OFF.
const int RELAY_PIN = 7;
const bool ACTIVE_LOW = true; // set to false for active-HIGH boards
void relayOn() { digitalWrite(RELAY_PIN, ACTIVE_LOW ? LOW : HIGH); }
void relayOff() { digitalWrite(RELAY_PIN, ACTIVE_LOW ? HIGH : LOW); }
void setup() {
relayOff(); // set the OFF level first...
pinMode(RELAY_PIN, OUTPUT); // ...so the relay doesn't click at start-up
Serial.begin(9600);
}
void loop() {
relayOn();
Serial.println("Relay ON");
delay(2000);
relayOff();
Serial.println("Relay OFF");
delay(2000);
}If the relay is ON when the sketch says OFF, your board is active HIGH. Change ACTIVE_LOW to false; nothing else in the sketch changes.
Step 3. Toggle it with a push button
Wire a push button between D2 and GND. The sketch uses the Uno's internal pull-up, so no resistor is needed: the pin reads HIGH normally and LOW while the button is pressed. Each press flips the relay.
// Push button toggles a 5V relay module (active LOW)
const int RELAY_PIN = 7;
const int BUTTON_PIN = 2;
bool relayIsOn = false;
bool lastReading = HIGH;
unsigned long lastChange = 0;
void applyRelay() {
digitalWrite(RELAY_PIN, relayIsOn ? LOW : HIGH);
}
void setup() {
digitalWrite(RELAY_PIN, HIGH); // start OFF
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool reading = digitalRead(BUTTON_PIN);
// react to a new press, ignoring contact bounce for 50 ms
if (reading == LOW && lastReading == HIGH && millis() - lastChange > 50) {
relayIsOn = !relayIsOn;
applyRelay();
Serial.println(relayIsOn ? "Relay ON" : "Relay OFF");
lastChange = millis();
}
lastReading = reading;
}Step 4. Add the load
With the Uno unplugged, put the relay in the positive wire of your 12 V load: supply positive to COM, NO to the load's positive, and the load's negative straight back to the supply's negative. The relay now switches the lamp exactly as the LED on the module shows. For a load that must stay on if the Uno fails, use NC instead of NO.
Warning
Keep mains for later. The sketch and wiring are the same for a 230 V lamp, but mains needs an enclosure, a fuse and insulated terminals. Learn with a 12 V load first.
Troubleshooting
Relay clicks once at reset
- Likely cause
- Pin LOW before setup() runs
- Fix
- Expected during upload; the HIGH-before-pinMode line stops it after start-up
LED on, no click
- Likely cause
- Weak 5 V supply
- Fix
- Use a powered USB port or a separate 5 V supply for the module
Uno resets when the load switches
- Likely cause
- Load noise on the shared supply
- Fix
- Separate load supply, short wires, diode across inductive loads
Button toggles twice
- Likely cause
- Contact bounce
- Fix
- Increase the 50 ms debounce to 80 ms
Works backwards
- Likely cause
- Active-HIGH module or load on NC
- Fix
- Set ACTIVE_LOW = false, or move the load to NO
Where to go next
- Switch the relay from your phone with the ESP32 version of this guide.
- Trigger it automatically with a sensor: turn on a light with a PIR motion sensor or a pump when the soil sensor reads dry.
- For loads you dim or switch quickly, use a MOSFET or a motor driver instead of a relay.








