The Waveshare Relay HAT adds high-voltage switching to Raspberry Pi. With optically isolated relays rated for 250V AC at 5A, you can control lights, fans, and appliances from Python code.
Features
- 2-8 relay channels (most common: 3-channel board)
- 250V AC / 5A or 30V DC / 5A per relay
- Optocoupler isolation
- SPDT contacts (NO, NC, COM)
- Direct GPIO control or I2C
Safe Wiring Guide
Warning: Mains voltage (230V AC in India) is dangerous. Hire a licensed electrician for AC wiring if unsure.
- Disconnect mains power before wiring.
- Connect live wire to COM terminal.
- Connect NO terminal to load’s live input.
- Neutral goes direct to appliance.
- Use 1.5 mm2 minimum wire for 5A loads.
- Insulate all connections with heat shrink.
Python Control
import RPi.GPIO as GPIO
RELAYS = [26, 20, 21]
GPIO.setmode(GPIO.BCM)
for p in RELAYS:
GPIO.setup(p, GPIO.OUT); GPIO.output(p, GPIO.HIGH)
def on(ch): GPIO.output(RELAYS[ch], GPIO.LOW)
def off(ch): GPIO.output(RELAYS[ch], GPIO.HIGH)
on(0) # Light on
import time; time.sleep(10)
off(0) # Light off
Automation Projects
- Scheduled lights: On at sunset, off at bedtime.
- Temperature fan: DHT22 reading triggers fan relay above 30C.
- Water pump timer: 15 minutes every 6 hours.
- Security siren: PIR motion triggers relay + Telegram notification.
Electrical Safety
- Never exceed relay rated current.
- Use MCB for overcurrent protection.
- Enclose high-voltage wiring in IP-rated junction box.
- Use DIN rail case for professional installations.
- Maintain earth/ground connections.
MQTT Integration
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
ch = int(msg.topic.split('/')[-1])
GPIO.output(RELAYS[ch], GPIO.LOW if msg.payload==b"ON" else GPIO.HIGH)
client = mqtt.Client()
client.on_message = on_message
client.connect("localhost", 1883)
client.subscribe("home/relay/#")
client.loop_forever()
Frequently Asked Questions
Can I switch 230V AC?
Yes, rated for 250V AC at 5A. Follow all safety guidelines.
NO vs NC?
NO = off by default (recommended for home automation). NC = on by default.
Interference issues?
Optocoupler prevents it. Add flyback diode for inductive loads.
Works with Pi 5?
Yes. Use gpiozero or lgpio library instead of RPi.GPIO.
Conclusion
The Waveshare Relay HAT bridges low-voltage Pi intelligence with the high-voltage real world. With MQTT and Home Assistant, it becomes a powerful home automation building block.
Browse the full Waveshare collection at Zbotic.in with fast shipping across India.
Add comment