Interfacing 2 Channel Relay with Arduino

2 Channel Relay Module

A 2 Channel Relay Module allows you to control two high-voltage devices using Arduino. It is commonly used in home automation, industrial control, and smart electronics applications where switching devices on/off remotely is essential.

Working Principle of 2 Channel Relay

The 2 Channel Relay works by using a small input current from the Arduino to activate an electromagnetic coil inside the relay. This magnetic field closes or opens a circuit to control connected high-voltage devices.

Types of Relay Modules

Mechanical Relay

  • Receives a control signal from Arduino.
  • Activates an electromagnetic coil to close the switch.
  • Allows current to flow to the connected load.

Solid-State Relay

  • Takes input from microcontroller pins.
  • Uses optocoupler and semiconductor switches.
  • Controls the connected device silently and quickly.

Requirements

1. Arduino

2. 2 Channel Relay Module

3. 100 ohm resistor

4. Jumper wires

Pin Configuration of 2 Channel Relay

Relay Module

  • VCC: Connect to +5V on Arduino.
  • GND: Connect to GND on Arduino.
  • IN1: Control signal for Relay Channel 1.
  • IN2: Control signal for Relay Channel 2.
  • COM: Common terminal for output device.
  • NO/NC: Normally Open / Normally Closed terminal for each channel.

Wiring the 2 Channel Relay to Arduino

To wire the 2 Channel Relay to Arduino, connect VCC and GND to 5V and ground. The IN1 and IN2 pins connect to digital pins on the Arduino to control each relay channel. Connect your output devices to the NO, NC, and COM terminals as needed.

Algorithm

  1. Initialize Components

    • Connect the VCC and GND pins of the relay module to +5V and GND on the Arduino.
    • Connect IN1 and IN2 to digital pins for controlling each relay channel.
  2. Write the Code

    • Set the relay control pins as OUTPUT in the setup() function.
    • Use digitalWrite() in the loop() function to turn the relays ON or OFF.
    • Program logic for triggering based on conditions like sensor input or timing.
  3. Control Connected Devices

    • Use the relay output to switch ON/OFF devices like lights or motors.
    • Monitor feedback using sensors, if applicable, for smart control.
  4. Test the Project

    • Upload the code to the Arduino.
    • Trigger the relay channels and observe the devices switching accordingly.
1// Define pins for the relay channels
2int relay1 = 7;  // IN1 on the Relay Module
3int relay2 = 8;  // IN2 on the Relay Module
4
5void setup() {
6  // Initialize both relay pins as OUTPUT
7  pinMode(relay1, OUTPUT);
8  pinMode(relay2, OUTPUT);
9  
10  Serial.begin(9600);  // Start serial monitor
11
12  // Turn both relays OFF initially
13  digitalWrite(relay1, LOW);  // Some modules use LOW = ON, others HIGH = ON
14  digitalWrite(relay2, LOW); 
15}
16
17void loop() {
18  // Turn ON Relay 1
19  digitalWrite(relay1, HIGH);   // Turns ON device 1
20  Serial.println("Relay 1 ON");
21  delay(2000);                  // Wait 2 seconds
22
23  // Turn OFF Relay 1
24  digitalWrite(relay1, LOW);    // Turns OFF device 1
25  Serial.println("Relay 1 OFF");
26  delay(1000);
27
28  // Turn ON Relay 2
29  digitalWrite(relay2, HIGH);   // Turns ON device 2
30  Serial.println("Relay 2 ON");
31  delay(2000);                  
32
33  // Turn OFF Relay 2
34  digitalWrite(relay2, LOW);    // Turns OFF device 2
35  Serial.println("Relay 2 OFF");
36  delay(1000);
37}
38

Applications of 2 Channel Relay Modules

  • Home automation systems
  • Industrial machinery control
  • Remote light and fan control
  • Smart irrigation systems
  • Automated door or gate systems
  • Power switching for AC appliances

Conclusion

Interfacing a 2 Channel Relay with Arduino enables powerful control over external devices, making it ideal for home automation and IoT projects. With easy wiring and simple code, it offers a solid foundation for building smarter systems.