Relay Module Interfacing Raspberry Pi

 Relay Module Raspberry Pi1. 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

Raspbery Pi
Raspberry Pi Pinout Diagram

Pinout Diagram of Single Channel Relay Module
Pinout Diagram of Single Channel Relay Module

Relay Module to Raspberry Pi

Relay PinRaspberry Pi
VCC5V
GroundGND
InputGPIO17

Relay Output Connections

Relay TerminalConnection
COMPower source
NO (Normally Open)Load (e.g., bulb)
NC (Normally Closed)Optional

4. Detailed Step By Step Circuit Working

  1. Raspberry Pi sends HIGH/LOW signal to relay input pin.
  2. Relay module uses internal transistor to drive coil.
  3. Electromagnetic coil switches internal contacts.
  4. Load connected to COM and NO turns ON/OFF.
  5. 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 numbering
  • GPIO.setup() → Sets relay pin as output
  • GPIO.output(HIGH) → Activates relay
  • GPIO.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.

തുടക്കക്കാർക്കായുള്ള ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.