1. Introduction
A relay module allows the Raspberry Pi to control high-voltage devices like bulbs, fans, and appliances safely. A single-channel relay module acts as an electrically operated switch, making it ideal for automation and IoT projects.
2. Components
- Raspberry Pi 4 Model B
- Single Channel Relay Module
- Jumper wires
- Breadboard (optional)
- AC/DC load (Bulb, Fan, etc.)
3. Circuit and Connections

Pinout Diagram of Single Channel Relay Module
Relay Module to Raspberry Pi
| Relay Pin | Raspberry Pi |
|---|---|
| VCC | 5V |
| Ground | GND |
| Input | GPIO17 |
Relay Output Connections
| Relay Terminal | Connection |
|---|---|
| COM | Power source |
| NO (Normally Open) | Load (e.g., bulb) |
| NC (Normally Closed) | Optional |
4. Detailed Step By Step Circuit Working
- Raspberry Pi sends HIGH/LOW signal to relay input pin.
- Relay module uses internal transistor to drive coil.
- Electromagnetic coil switches internal contacts.
- Load connected to COM and NO turns ON/OFF.
- Provides isolation between low voltage and high voltage.
5. Libraries to be Included
pip3 install RPi.GPIO
6. Code (Python)
import RPi.GPIO as GPIO
import time
relay = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay, GPIO.OUT)
try:
while True:
GPIO.output(relay, GPIO.HIGH) # Turn ON relay
print("Relay ON")
time.sleep(2)
GPIO.output(relay, GPIO.LOW) # Turn OFF relay
print("Relay OFF")
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()
7. Detailed Step By Step Code Working
GPIO.setmode(GPIO.BCM)→ Uses BCM pin numberingGPIO.setup()→ Sets relay pin as outputGPIO.output(HIGH)→ Activates relayGPIO.output(LOW)→ Deactivates relay- Loop continuously switches relay ON/OFF
⚠️ Note: Some relay modules are active LOW (reverse logic).
8. Tips
- Check if relay is active LOW or HIGH
- Never touch live AC connections
- Use proper insulation
- Prefer opto-isolated relay modules
- Test with LED before connecting high voltage
9. Uses
- Home automation (light/fan control)
- Smart switches
- Industrial automation
- IoT-based appliance control
- Security systems
10. Conclusion
A single-channel relay module is an essential component for controlling high-power devices using Raspberry Pi. It enables safe and reliable switching, making it perfect for automation and real-world applications.