Arduino Code and Video for a Dual-Channel 5V Relay
In this tutorial, we will learn how to control AC and DC loads using a dual-channel 5V relay with an Arduino. The relay allows you to switch between two different loads, such as an AC bulb and a DC motor, providing flexibility for various applications. By the end of this guide, you'll be able to set up your own relay system and control it through simple Arduino code.

Throughout the process, we'll cover the necessary components, wiring instructions, and a walkthrough of the Arduino code used to control the relay. This project is perfect for beginners looking to explore the world of electronics and automation. For a visual guide, be sure to watch the associated video (in video at 00:00).
Hardware Explained
The main component in this project is the dual-channel 5V relay. This relay consists of two independent switches that can control separate loads. Each relay has three contacts: Normally Closed (NC), Normally Open (NO), and Common (COM). When the relay is activated, the NO contact connects, allowing current to flow through the load.
Other essential components include the Arduino board, which will control the relay through its digital pins. The relay module also features indicator LEDs that light up when the relay is activated. Additionally, the relay is optically isolated, providing safety by separating the control circuit from the load circuit.
Datasheet Details
| Manufacturer | Songle |
|---|---|
| Part number | SRD-05VDC-SL-C |
| Logic/IO voltage | 5 V |
| Supply voltage | 5 V |
| Output current (per channel) | 10 A |
| Peak current (per channel) | 10 A |
| PWM frequency guidance | N/A |
| Input logic thresholds | 2.5 V min |
| Voltage drop / RDS(on) / saturation | 80 mΩ |
| Thermal limits | 70 °C |
| Package | Module |
| Notes / variants | Optically isolated |
- Ensure proper isolation when connecting AC loads.
- Use appropriate fuses for safety with high loads.
- Keep the relay module away from moisture.
- Consider heatsinking for high-power applications.
- Verify wiring before powering on to avoid damage.
- Use separate power supplies for high-current devices if necessary.
Wiring Instructions

To wire the dual-channel relay to the Arduino, start by connecting the VCC pin of the relay module to the 5V pin on the Arduino. Connect the GND pin of the relay to the GND pin on the Arduino. This provides power to the relay module.
Next, connect the control pins: link the IN1 pin of the relay to digital pin 7 on the Arduino and the IN2 pin to digital pin 8. This setup will allow you to control both relays independently. Finally, connect your AC or DC loads to the relay contacts according to your needs, ensuring proper safety precautions are followed when dealing with AC voltage.
Code Examples & Walkthrough
In the Arduino code, we begin by initializing the serial communication and setting the pin modes for the relay control pins. The variables relay1Pin and relay2Pin are defined to represent the pins connected to each relay. The output states of these pins are then toggled in the loop.
const int relay1Pin = 7; // define pin for relay 1
const int relay2Pin = 8; // define pin for relay 2
void setup() {
Serial.begin(9600); // setup Serial Monitor to display information
pinMode(relay1Pin, OUTPUT); // connected to Relay 1
pinMode(relay2Pin, OUTPUT); // connected to Relay 2
}
This excerpt initializes the serial monitor to output debug information and sets the relay control pins as outputs. This is crucial for ensuring the relays can be turned on and off as needed.
void loop() {
digitalWrite(relay2Pin, LOW); // turn relay 2 OFF
Serial.print("Pin 8 LOW");
digitalWrite(relay1Pin, HIGH); // turn relay 1 ON
Serial.println(" Pin 7 HIGH");
delay(3000); // keep in relay 2 OFF and relay 1 On for 3 seconds
digitalWrite(relay1Pin, LOW); // turn relay 1 OFF
digitalWrite(relay2Pin, HIGH); // turn relay 2 ON
Serial.print("Pin 7 LOW");
Serial.println(" Pin 8 HIGH");
delay(3000); // keep in relay 1 OFF and relay 2 On for 3 seconds
}
This code toggles the relays every three seconds, turning one on while turning the other off. The serial monitor outputs the state of the pins, which helps in debugging and understanding the relay operations.
Demonstration / What to Expect
When the setup is complete, you should see the relay switching between the connected loads every three seconds. The relay will activate the connected AC bulb or DC motor alternately. Be cautious when working with AC loads, as improper handling can lead to dangerous situations (in video at 12:34).
Video Timestamps
- 00:00 - Introduction to the dual-channel relay
- 04:15 - Wiring instructions
- 08:30 - Code explanation
- 10:45 - Demonstration of the relay
Things you might need
-
AliExpressPurchase 5v 12v 1 2 4 6 8 channel channel relay moduls.click.aliexpress.com
Resources & references
No resources yet.
Files📁
No files available.