Skip to content

Relay · Arduino Uno guide

Controlling 5V Relay Module (1-Channel, SRD-05VDC-SL-C) with Arduino Uno

Let a 5 V or 3.3 V pin switch a lamp, pump, fan or solenoid on its own supply, with COM, NO and NC screw terminals.

Updated November 25, 2026 Arduino C++None neededAlso forESP32

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

PinSideWhat it does
VCCControl5 V supply for the coil driver and LED
GNDControlGround, shared with the microcontroller
INControlSignal from a GPIO pin. LOW turns the relay ON on active-LOW boards
COMLoadCommon contact: connect one wire of the load circuit here
NOLoadNormally open: connected to COM only while the relay is ON
NCLoadNormally closed: connected to COM while the relay is OFF
JD-VCCJumperSeparate 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

PartQtyNotes
Arduino Uno (or Nano)1Any 5 V Arduino works the same way
5 V 1-channel relay module1SRD-05VDC-SL-C type
Push button1For the toggle example
Jumper wires5Female-to-male for the module header
Test load1A 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 pinUno pinNote
VCC5VPowers the coil driver: about 75 mA when ON
GNDGNDCommon ground
IND7Any digital pin works; D7 is clear of serial and SPI
  1. 1Red wire: Uno 5V to module VCC.
  2. 2Black wire: Uno GND to module GND.
  3. 3Signal wire: Uno D7 to module IN.
  4. 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.

sketch.ino
// 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.

Extra wiring for the button

Button legUno pinNote
Leg 1D2INPUT_PULLUP, reads LOW when pressed
Leg 2GNDUse legs on opposite sides of the button
sketch.ino
// 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

Keep learning

Related guides & projects