The Direct Answer: Which 5V Relay Module to Pick

If you need to switch a standard 120V AC household load under 10A (like a lamp, small heater, or coffee maker), buy a 1-Channel 5V Relay Module with Optocoupler featuring the Songle SRD-05VDC-SL-C relay. It costs between $2 and $4, handles up to 10A at 250VAC, and includes the necessary flyback diode and optoisolator on the PCB. It is the default workhorse for hobbyist AC switching.

However, not all loads are created equal. Use this decision tree to ensure you don't melt your PCB traces or weld your contacts shut.

Load Characteristic If True... Concrete Pick
Resistive (Heaters, Incandescent Bulbs) < 10A Standard mechanical contacts are sufficient. Songle SRD-05VDC-SL-C (Blue 1-Ch Module)
Inductive (Motors, Pumps, Solenoids) Contacts will arc and weld. Needs zero-crossing or higher rating. Omron G3MB-202P Solid State Relay (SSR) Module
High Current (10A - 30A) at 120V/240V AC PCB traces on cheap modules will melt or catch fire. JQC3F-05VDC (30A Mechanical Relay Module)
Low Voltage DC (12V/24V LED Strips, Pumps) Mechanical relay is overkill, noisy, and lacks PWM support. IRF520 MOSFET Driver Module
MAINS SAFETY WARNING: Working with mains voltage (>50V AC) is lethal. Before touching the relay screw terminals, de-energize the circuit at the breaker panel, lock out the panel if possible, and verify the wires are dead with a non-contact voltage tester and a multimeter. If you are not comfortable working with mains wiring, hire a licensed electrician. Local electrical codes (NEC/IEC) always have final authority over hobbyist guidance.

Parts List & Spec Sheet

This build assumes you are targeting the Arduino Uno R3 or the newer Arduino Uno R4 Minima. Both boards share the same digital pinout and 5V logic levels, making them ideal for driving standard optocoupler modules directly.

Component Exact Variant / Specification Notes
Microcontroller Arduino Uno R3 (ATmega328P) or R4 Minima (RA4M1) 5V logic, 40mA max per GPIO pin
Relay Module 1-Channel 5V Optocoupler Isolated (SRD-05VDC-SL-C) Coil draws ~70mA; Active LOW trigger
Logic Wires 22 AWG solid core jumper wires (Male-to-Female) For breadboard-to-module connections
Load Wires (Mains) 14 AWG stranded copper (THHN or equivalent) Rated for 15A circuits; prevents overheating
Terminals Wago 221 Lever-Nuts or proper crimp ferrules Do not use cheap twist-on wire nuts for DIY enclosures

Pin Mapping & Wiring Procedure

The wiring for a 5V relay module for Arduino is straightforward, but the physical termination of the mains side is where most failures occur. The brass screw terminals on the Songle relay are soft; over-tightening them with a screwdriver will strip the threads and cause a high-resistance connection that melts under load.

Relay Module Pin Arduino Pin / Power Function
VCC 5V Powers the optocoupler LED
GND GND Logic ground reference
IN D8 Control signal (Active LOW)
COM (Common) Mains HOT (Line) Input from breaker panel
NO (Normally Open) Load HOT Output to the appliance

The JD-VCC Isolation Myth: A common bench mistake is assuming the 'JD-VCC' jumper on cheap 1-channel modules provides true galvanic isolation. It does not. On most mass-produced blue modules, the GND trace is shared between the optocoupler LED and the relay coil driver transistor. If you are switching noisy inductive loads, back-EMF will still couple into your Arduino's ground plane, causing random resets. For true isolation, you must buy a module with physically separated logic and load terminal blocks, or use a Solid State Relay (SSR). For standard resistive loads, leaving the jumper in place and powering from the Arduino 5V pin is acceptable.

Complete Arduino Code

This code targets the Arduino Uno R3/R4. It includes a runtime safety check to prevent you from accidentally assigning the relay to pins 0 or 1, which would interfere with the Serial monitor and USB communication. It also explicitly defines the Active LOW logic required by most optocoupler modules.

/*
 * Target Board: Arduino Uno R3 / R4 Minima
 * Module: 1-Channel 5V Relay with Optocoupler (Active LOW)
 * Site: ElectricalFlux
 */

#define RELAY_PIN 8
#define STATUS_LED LED_BUILTIN
#define RELAY_ON LOW   // Most optocoupler modules are Active LOW
#define RELAY_OFF HIGH

void setup() {
  Serial.begin(115200);
  // Wait for serial monitor to open, max 3 seconds
  unsigned long startTime = millis();
  while (!Serial && (millis() - startTime < 3000));
  
  // Safety check: Ensure we aren't using Serial pins (0,1) or invalid pins
  if (RELAY_PIN < 2 || RELAY_PIN > 13) {
    Serial.println("[ERR] Relay control pin failed initialization: Pin out of safe digital range");
    Serial.println("Action: Change RELAY_PIN to a value between 2 and 13.");
    while (true) {
      // Halt execution to prevent erratic behavior on Serial pins
      delay(1000); 
    }
  }
  
  pinMode(STATUS_LED, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
  
  // Engage safe state immediately (Relay OFF)
  digitalWrite(RELAY_PIN, RELAY_OFF);
  Serial.println("System OK: Relay module initialized in safe OFF state.");
}

void loop() {
  // Example: Engage relay for 5 seconds, then disengage for 5 seconds
  digitalWrite(RELAY_PIN, RELAY_ON);
  digitalWrite(STATUS_LED, HIGH);
  Serial.println("Relay ENGAGED (Closed)");
  delay(5000);
  
  digitalWrite(RELAY_PIN, RELAY_OFF);
  digitalWrite(STATUS_LED, LOW);
  Serial.println("Relay DISENGAGED (Open)");
  delay(5000);
}

Debugging: First 3 Checks & Exact Error Strings

When your 5V relay module for Arduino fails to click, or worse, causes your microcontroller to reboot, do not start rewriting your code. Hardware and power delivery are almost always the culprits.

The First 3 Things to Check

  1. Logic Level Inversion (Active LOW): Most optocoupler modules trigger when the IN pin is pulled LOW, not HIGH. If your code uses digitalWrite(RELAY_PIN, HIGH) to turn it on, it is doing the opposite. The optocoupler LED cathode is tied to the IN pin; pulling it to GND completes the circuit.
  2. Brownout Reset (Voltage Sag): The Arduino Uno's onboard 5V regulator can only supply ~400mA safely. A 5V relay coil draws ~70-90mA. If you have an LCD screen and multiple sensors attached, the voltage drops below 4.7V, causing the ATmega328P brownout detector to trigger a reset. Measure the 5V rail with a multimeter while the relay clicks.
  3. Flyback Diode Failure: If the relay clicks once and then the Arduino freezes or the USB port disconnects, the back-EMF from the collapsing magnetic field in the coil is injecting high-voltage noise into the logic rail. Verify the 1N4148 or 1N4007 diode is actually soldered across the coil pins on the PCB. See this guide on taming inductive flyback voltage for the physics behind it.

Exact Error Strings & Ranked Causes

If you encounter errors in the Arduino IDE or Serial Monitor, match them to these exact strings:

Compile-Time Error:

exit status 1: 'RELAY_PIN' was not declared in this scope
  • Cause 1: You deleted or commented out the #define RELAY_PIN 8 line at the top of the sketch.
  • Cause 2: You placed the #define macro after the setup() function. Preprocessor directives must be declared globally before they are used.

Runtime Serial Error:

[ERR] Relay control pin failed initialization: Pin out of safe digital range
  • Cause 1: You changed RELAY_PIN to 0 or 1. These are reserved for hardware Serial RX/TX and will cause USB communication failures.
  • Cause 2: You attempted to use an analog pin (e.g., A0) without mapping it to its digital equivalent (e.g., 14 on an Uno), triggering the safety bounds check in the code.

Extending and Simplifying the Build

Once you have the basic 5V relay module for Arduino working, you will likely want to scale the project. Here is how to adapt the hardware based on your end goal.

Extending: Moving to ESP32 and MQTT

If you want to control the relay over WiFi using MQTT, you will likely switch to an ESP32 DevKit v1. Warning: The ESP32 operates on 3.3V logic. The optocoupler LED on a standard 5V Arduino relay module usually requires ~4.5V to trigger reliably due to the internal current-limiting resistor. If you connect an ESP32 GPIO directly to the IN pin, the relay will chatter or fail to engage.
The Fix: Use a bidirectional logic level shifter (like the BSS138 module) between the ESP32 and the relay IN pin, or buy a relay module specifically advertised as '3.3V Logic Compatible' (which uses a lower value current-limiting resistor for the optocoupler).

Simplifying: The MOSFET Alternative

If your project only involves switching low-voltage DC loads (like a 12V LED strip, a PC fan, or a small 12V peristaltic pump), ditch the mechanical relay entirely. Mechanical relays are loud, suffer from contact bounce, and draw continuous current to hold the coil closed. Instead, use an IRF520 MOSFET Driver Module. It costs about the same, has no moving parts, supports PWM dimming via the Arduino analogWrite function, and draws virtually zero current from your microcontroller's GPIO pin.

Final Recommendation

If you are building a standard home automation node for a resistive AC load like a lamp or a fan, terminate your decision here: buy the 1-Channel Songle SRD-05VDC-SL-C module with optocoupler. It is the industry standard for hobbyist AC switching, costs under $4, and pairs perfectly with the Arduino Uno R3. Do not over-engineer the isolation unless you are switching heavy inductive motors.