1. Introduction
A dual channel relay module allows the Raspberry Pi to control two high-voltage devices independently. It is widely used in home automation, IoT, and industrial control systems where multiple loads need switching.
2. Components
- Raspberry Pi 4 Model B
- Dual Channel Relay Module
- Jumper wires
- Breadboard (optional)
- Loads (Bulb, Fan, etc.)
3. Circuit and Connections
| Relay Pin | Raspberry Pi |
|---|---|
| VCC | 5V |
| GND | GND |
| IN1 | GPIO17 |
| IN2 | GPIO27 |
Relay Output Connections
| Relay Channel | Terminals | Connection |
|---|---|---|
| Relay 1 | COM, NO, NC | NC Device 1 |
| Relay 2 | COM, NO, NC | NC Device 2 |
4. Detailed Step By Step Circuit Working
- Raspberry Pi sends control signals to IN1 and IN2.
- Each relay has its own electromagnetic coil.
- When activated, the relay switches from NO to COM.
- Two devices can be controlled independently.
- Provides electrical isolation for safety.
5. Libraries to be Included
pip3 install RPi.GPIO
6. Code (Python)
import RPi.GPIO as GPIO
import time
relay1 = 17
relay2 = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay1, GPIO.OUT)
GPIO.setup(relay2, GPIO.OUT)
try:
while True:
GPIO.output(relay1, GPIO.HIGH)
GPIO.output(relay2, GPIO.LOW)
print("Relay1 ON, Relay2 OFF")
time.sleep(2)
GPIO.output(relay1, GPIO.LOW)
GPIO.output(relay2, GPIO.HIGH)
print("Relay1 OFF, Relay2 ON")
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()
7. Detailed Step By Step Code Working
GPIO.setup()→ Configures relay pins as outputGPIO.output(relay1, HIGH)→ Turns ON relay 1GPIO.output(relay2, HIGH)→ Turns ON relay 2- Each relay works independently
- Loop alternates switching
⚠️ Note: Some modules are active LOW (reverse logic)
8. Tips
- Always check relay logic (LOW trigger / HIGH trigger)
- Use separate power if relay causes Pi reset
- Avoid loose AC wiring
- Use opto-isolated relay modules for safety
- Label connections clearly
9. Uses
- Home automation (2 devices control)
- Smart lighting systems
- Industrial automation
- IoT switching systems
- Appliance control
10. Conclusion
Dual channel relay modules are perfect for controlling multiple high-power devices using Raspberry Pi. They are easy to use, reliable, and essential for automation projects.