Relay Module for Arduino: A Complete Guide

A relay module allows an Arduino to control high-voltage devices like lights, fans, motors, or home appliances. Since Arduino operates at low voltage (3.3V/5V) and cannot directly switch high-power loads, a relay acts as an electrically isolated switch.


๐Ÿ”น 1. How a Relay Module Works

A relay module consists of:

  1. Electromagnetic Relay โ€“ A switch that opens or closes when powered.
  2. Optocoupler (for isolation) โ€“ Prevents high-voltage backflow to Arduino.
  3. Transistor (Driver Circuit) โ€“ Controls the relay using a small current.
  4. Diode (Flyback Protection) โ€“ Prevents voltage spikes when turning off the coil.
  5. Indicator LED โ€“ Shows relay status.

๐Ÿ“Œ Function:

  • When the Arduino sends a signal (HIGH or LOW), the relay activates or deactivates.
  • The relay can switch AC (110V/220V) or DC (12V/24V) loads.

๐Ÿ”น 2. Relay Module Types

Relay TypeDescription
Single-Channel RelayControls one high-power device
2/4/8-Channel RelayControls multiple devices
Mechanical RelayStandard electromechanical switch
Solid-State Relay (SSR)Faster, silent switching (no mechanical parts)

๐Ÿ”น 3. Relay Module Pinout

A typical relay module has 5 pins:

Relay PinFunction
VCCPower (5V)
GNDGround
INControl pin (Arduino Digital Output)
COM (Common)Shared terminal
NO (Normally Open)Open when relay is OFF, closed when ON
NC (Normally Closed)Closed when relay is OFF, open when ON

๐Ÿ“Œ “Normally Open” (NO) โ†’ Device is OFF by default, turns ON when relay is activated.
๐Ÿ“Œ “Normally Closed” (NC) โ†’ Device is ON by default, turns OFF when relay is activated.


๐Ÿ”น 4. Connecting a Relay Module to Arduino

๐Ÿ›  Required Components

  • 1x Arduino Board (Uno, Mega, Nano, etc.)
  • 1x Relay Module (5V)
  • 1x 220V Lamp (or 12V DC Motor)
  • Jumper Wires
  • External Power Source (if needed)

๐Ÿ›  Wiring Diagram

Relay PinArduino Pin
VCC5V
GNDGND
IND7

High-Voltage Load Connection (AC Example):

  • COM โ†’ Live Wire (from Power Source)
  • NO โ†’ Load (Lamp, Fan, Motor)
  • Neutral Wire โ†’ Directly to Load

๐Ÿ”น 5. Arduino Code for Relay Control

This basic example turns a relay ON for 5 seconds, then turns it OFF for 5 seconds.

#define RELAY_PIN 7  // Relay connected to Digital Pin 7

void setup() {
    pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
    digitalWrite(RELAY_PIN, HIGH); // Turn ON Relay
    delay(5000);                   // Wait 5 seconds
    digitalWrite(RELAY_PIN, LOW);  // Turn OFF Relay
    delay(5000);                   // Wait 5 seconds
}

๐Ÿ“Œ For Active-Low Relays (some modules work in reverse):

  • Use LOW to turn ON and HIGH to turn OFF.

๐Ÿ”น 6. Controlling a Relay with a Sensor

Example: Turn on a light when itโ€™s dark (using LDR sensor).

#define RELAY_PIN 7
#define LDR_PIN A0

void setup() {
    pinMode(RELAY_PIN, OUTPUT);
    pinMode(LDR_PIN, INPUT);
}

void loop() {
    int lightValue = analogRead(LDR_PIN);  // Read LDR sensor
    if (lightValue < 500) {  // If it's dark
        digitalWrite(RELAY_PIN, HIGH);  // Turn ON relay
    } else {
        digitalWrite(RELAY_PIN, LOW);  // Turn OFF relay
    }
}

๐Ÿ“Œ Other Relay Applications:
โœ… Temperature-Based Control (DHT11 + Relay for Fan).
โœ… Motion Detection (PIR Sensor + Relay for Security Light).
โœ… Wi-Fi Home Automation (ESP8266 + Relay).


๐Ÿ”น 7. Safety Precautions When Using Relays

โš ๏ธ Avoid Directly Touching High-Voltage Wires.
โš ๏ธ Use Relays with Optocouplers for Electrical Isolation.
โš ๏ธ Do Not Exceed the Relay’s Rated Voltage/Current.
โš ๏ธ For AC Loads, Use Proper Insulation & Fuse Protection.


๐ŸŽฏ Conclusion

  • A relay module allows Arduino to control high-voltage appliances.
  • It works by switching AC or DC loads using a small control signal.
  • Can be used for home automation, security, and industrial applications.
  • Always follow safety guidelines when working with high voltage.
๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply