Anatomy of a Standard 5V Relay Module

When integrating a relay module for Arduino into your electronics projects, understanding the internal hardware is critical for preventing microcontroller resets and ensuring long-term reliability. As of 2026, the market is still dominated by modules featuring the Songle SRD-05VDC-SL-C electromechanical relay. These modules typically cost between $2.50 for a single-channel board and $6.50 for a 4-channel optoisolated variant.

A high-quality module contains three primary subsystems:

  • The Electromechanical Relay: The SRD-05VDC-SL-C features a 70-ohm coil requiring approximately 70mA of current to energize. Its contacts are rated for 10A at 120VAC or 28VDC.
  • Optocoupler Isolation: A PC817 optocoupler separates the low-voltage logic side (your microcontroller) from the higher-current relay coil side, preventing noise and voltage spikes from crossing over.
  • Flyback Diode: A 1N4007 diode is wired in reverse bias across the relay coil to safely dissipate the back-EMF (electromotive force) generated when the magnetic field collapses upon de-energizing.

The JD-VCC Jumper: Achieving True Galvanic Isolation

One of the most misunderstood aspects of wiring a relay module for Arduino is the JD-VCC jumper. Many modules ship with a jumper cap connecting VCC and JD-VCC. In this default state, the module shares a common ground with your microcontroller, and the optocoupler is effectively bypassed for power delivery.

Expert Tip: To achieve true galvanic isolation and protect your microcontroller from ground loops and inductive spikes, you must remove the jumper cap. You then power JD-VCC from an independent 5V source (like a dedicated buck converter), while connecting the module's VCC and IN pins to your Arduino's 5V and GPIO pins, respectively. Ensure the independent 5V ground is not tied to the Arduino ground.

Standard Wiring Matrix (Low-Level Trigger)

Most modern modules are configured for low-level triggering, meaning the relay activates when the input pin is pulled to GND (0V). Below is the standard wiring matrix for a fully isolated, low-level trigger setup.

Module Pin Connection Target Function / Notes
JD-VCC Independent 5V PSU (+) Powers the relay coil and optocoupler output side.
VCC Arduino 5V Pin Powers the optocoupler input side (logic).
GND Arduino GND Pin Logic ground reference for the input signal.
IN1 Arduino Digital Pin 8 Control signal. LOW = Relay ON, HIGH = Relay OFF.
COM Load Power Source (+) Common terminal for the switched load circuit.
NO Load Positive Input Normally Open. Connects to COM when relay is energized.
NC Load Positive Input Normally Closed. Connects to COM when relay is de-energized.

Non-Blocking Arduino C++ Implementation

Using the delay() function to control a relay module for Arduino is a common beginner mistake that halts all other microcontroller operations. For robust applications, you should use a non-blocking state machine based on the Arduino millis() reference. This allows your code to read sensors or handle serial communication while timing the relay state.

Furthermore, as noted in the Arduino digital pins documentation, configuring the pin mode correctly and initializing the pin to the safe (OFF) state before switching it to an output prevents the relay from briefly flickering during the microcontroller's boot sequence.

const int RELAY_PIN = 8;
const unsigned long RELAY_INTERVAL = 5000; // 5 seconds
unsigned long previousMillis = 0;
bool relayState = false;

void setup() {
  // Initialize in safe state BEFORE setting as output to prevent boot flicker
  digitalWrite(RELAY_PIN, HIGH); // HIGH = OFF for low-level trigger modules
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  unsigned long currentMillis = millis();
  
  if (currentMillis - previousMillis >= RELAY_INTERVAL) {
    previousMillis = currentMillis;
    relayState = !relayState; // Toggle state
    
    // Write LOW to energize (turn ON), HIGH to de-energize (turn OFF)
    digitalWrite(RELAY_PIN, relayState ? LOW : HIGH);
    Serial.print("Relay State: ");
    Serial.println(relayState ? "ON" : "OFF");
  }
  
  // Other non-blocking code can run here freely
}

Failure Modes & Inductive Load Protection

While the SRD-05VDC-SL-C is rated for 10A, this rating applies strictly to resistive loads (like heating elements or incandescent bulbs). When switching inductive loads (motors, solenoids, transformers), the relay module faces severe failure modes.

Contact Welding and Arcing

Inductive loads resist changes in current. When the relay contacts open, the collapsing magnetic field of the motor generates a massive voltage spike that arcs across the physical gap between the COM and NO contacts. Over time, this arc pits the metal and can literally weld the contacts together, causing the relay to fail in the "ON" position—a catastrophic safety hazard.

The Solution: Install an RC snubber network across the load contacts. A standard snubber consists of a 100Ω resistor in series with a 0.1µF X2-rated capacitor, wired in parallel with the inductive load. This absorbs the transient voltage spike and preserves the relay contacts.

Microcontroller Brownouts

If you power the relay coil directly from the Arduino's onboard 5V regulator, the 70mA current draw when the relay clicks can cause a voltage sag. If the voltage drops below the ATmega328P's brownout detection threshold (typically 4.3V), the microcontroller will instantly reset. Always use an external power supply or a high-quality buck converter capable of delivering at least 500mA to handle the inrush current of multiple relay coils.

Troubleshooting Matrix

Symptom Probable Cause Actionable Fix
Relay clicks, but Arduino resets immediately. 5V rail brownout due to insufficient current from the onboard regulator. Power the relay module's JD-VCC with an external 5V 1A power supply.
Relay LED turns on, but contacts do not click. Optocoupler is passing signal, but coil lacks power or jumper is missing. Check JD-VCC connection. Ensure the jumper cap is either properly placed (shared VCC) or removed (isolated VCC).
Relay stays ON permanently after a few cycles. Contact welding caused by switching an inductive load without a flyback/snubber. Replace the relay. Add an RC snubber or a flyback diode across the load.
Relay triggers randomly during power-up. GPIO pins float during the bootloader sequence before pinMode is set. Wire the GPIO to the IN pin via a 10kΩ pull-up resistor to hold it HIGH during boot.

Mains Voltage Safety and Compliance

When using a relay module for Arduino to switch 120VAC or 240VAC mains voltage, you are no longer just building a hobby project; you are interacting with potentially lethal infrastructure. Exposed solder joints on the underside of cheap relay modules pose a severe shock and fire risk.

Always enclose mains-switching relay modules in a non-conductive, fire-retardant ABS or polycarbonate project box. Wire routing must comply with local electrical codes. In the United States, adherence to the NFPA 70 National Electrical Code is mandatory for permanent installations. This includes maintaining proper creepage and clearance distances between low-voltage DC logic wires and high-voltage AC mains wires. Never route 5V logic wires and 120VAC load wires through the same cable gland or conduit without appropriate dual-insulation ratings.