Intermediate
• ~12 min read
Relay Control
Set up relay modules to control pumps, valves, and other devices.
Understanding Relays
A relay is an electrically operated switch. MudPi uses relays to control higher-power devices like water pumps and solenoid valves from the low-voltage GPIO pins of your Raspberry Pi.
Relay Terminals
COM (Common) — Connect to one side of your load's power supply
NO (Normally Open) — Circuit is open when relay is off. Use this for devices that should be off by default.
NC (Normally Closed) — Circuit is closed when relay is off. Use for fail-safe scenarios where the device should run unless explicitly stopped.
Wiring a Relay Module
| Relay Pin | Raspberry Pi | Notes |
|---|---|---|
| VCC | 5V | Relay modules typically need 5V |
| GND | Ground | — |
| IN1 | GPIO pin | Your choice of available GPIO |
Configuration for a single relay:
JSON
{
"pin": 17,
"type": "relay",
"name": "Main Water Valve",
"default_state": "off"
}
Safety Considerations
Electrical Safety
Relays can switch mains voltage. If you're working with anything above 12V DC, ensure you understand electrical safety or consult a qualified electrician.
- Never work on live electrical circuits — always disconnect power before wiring
- Use appropriately rated relays — check the voltage and current ratings match your load
- Add a flyback diode across inductive loads (motors, solenoids) to protect the relay contacts
- Use weatherproof enclosures for outdoor installations
- Label all wires clearly for future maintenance
Multi-Channel Relays
For systems controlling multiple zones, use a multi-channel relay board. MudPi supports controlling each channel independently:
mudpi.config.json
{
"controls": [
{
"pin": 17,
"type": "relay",
"name": "Zone A - Front Garden",
"default_state": "off"
},
{
"pin": 27,
"type": "relay",
"name": "Zone B - Raised Beds",
"default_state": "off"
},
{
"pin": 22,
"type": "relay",
"name": "Zone C - Greenhouse",
"default_state": "off"
}
]
}
Click to expand code…