It was Martin Oldfield who clued me up on this - you can get a little relay for about £1 that you can connect to a Raspberry Pi's GPIO pins, and use it to control mains voltage at ten amps.
Here's the relay (you can also get two, four and eight channel relays).
Here's the wiring:
Pi Relay Board
+-------------------------+ Switched
--------+ | | contacts
. o | <-- 5V --------- Vcc -- | o . |
. . | --- IN1 -- | o o | <----
. o | <-- Ground - / - GND -- | o o | <----
. . | / | |
. . | / +-------------------------+
. o | <-- GPIO 18
. . |
. . |
. . |
. . |
. . |
. . |
. . |
|
|
And here's the code to control the relay:
cd /sys/class/gpio
echo 18 > export
cd gpio18
echo out > direction
echo 1 > value
echo 0 > value
Simples! I tried it, and it worked fine.
I think it's pretty obbious how you extend that to control multiple relays.
No comments:
Post a Comment