I’ve been playing with the new ModMyPi PiOT Relay Board over the last few days, and as you’ll guess from the name, it includes relays.
Relays allow you to switch (turn on/off) higher voltages than the device you’re using. I use the Raspberry Pi for example, which offers 5V at the very most. But what if I wanted to use my Pi to turn on/off a 20V motor or another device higher than its limit? That’s where relays come in.
But what kind of voltages can you safely tinker with? For amateurs like us, certain sources say up to 50V is fine, and ideally won’t cause us to be the guy laying down at a funeral.
I’m not really up for testing that out on my own body, but it did raise a good point – despite some products being rated at 240V or higher, you really REALLY don’t want to go there.
Let me explain in this post…
The PiOT Relay Board
First, let me show you around my new toy this week – the PiOT relay board from ModMyPi.
This unconventionally shaped add-on board for the Pi is designed to take the hassle away from using these little clicking boxes of fun. The large shape and header position holds a Pi Zero very well, but for other Pis it’s a tad clunky. Where possible, I personally prefer the HAT format:
Ignoring the layout, the PiOT relay board is quite a smart little chap.
The 4 relays are connected to the Pi through the clever use of a PIC micro-controller. The PIC is the brain behind all the annoying stuff you just don’t want to waste your precious time with as a weekend coding warrior – voltage dividers, transistors, diodes, wires, jumpers and more.
You’ll also notice a 7-segment display at the front, and some buttons next to each relay. This is what you use to set the GPIO pin for each relay, and because of the clever PIC business, you don’t have to fumble about with jumper wires to do this.
It’s certainly a lot simpler than it looks. I was originally a bit tentative as I hadn’t used relays previously, and all the display/PIC/button business looked a bit beyond me – but it’s super simple once you’ve spent 3 minutes reading the guide.
This is another handy board that requires almost no setup. Most of that is covered by the pre-configured PIC controller, meaning all you have to do is plug your wires, tie the GPIOs to the relays using the buttons, and then simply set GPIOs high or low to switch the relays.
If you want fancy on-screen button controls, ModMyPi have made a Tkinter GUI for the board as well.
How A Relay Works
Seeing 3 terminals for each relay confused me, so let me explain it.
Firstly, all the relay is doing is ‘making or breaking’ your circuit. If you had a simple LED circuit, you’d chop the 5v line and chuck the 2 chopped ends into the relay. That’s all you’re doing here, so don’t let it confuse you.
Secondly, you’re only wiring into 2 of these terminals at any one time, and you always put one wire in the ‘COM’ (common) terminal.
You then have to decide where to put the other wire – in the NC (Normally Closed) or NO (Normally Open) terminal:
- NO – Normally Open – this means when the relay is off, the circuit is broken and your device is off too. This feels like the safer option to me.
- NC – Normally Closed – this means the connection is usually on/connected even when the relay is off, and is only broken when you turn the relay on.
Here you can see me using the NC terminals, which I quickly changed afterwards to NO – I didn’t want things to be turning on from boot without me saying so!
Figured I'd put the GND lines into a 2nd relay and tie it to the same GPIO, saves me insulating wires and generally doing it properly 😂 pic.twitter.com/c3HjubCXB7
— Average Maker (@Average_Maker) September 30, 2016
Dangerous First Run
Let’s cut to the chase – check out this tweet I posted after setting up my PiOT:
Oh yeah, I'm converted. Relays are my new thing! Got a PiZero under that ModMyPi board, controlling a cheapo Dremel on GPIO15 vis SSH. 240V! pic.twitter.com/YRelMzAUG7
— Average Maker (@Average_Maker) September 30, 2016
What followed was a lot of concern from the more qualified members of the community. Electricians, engineers and the odd troll weighed-in to inform me that I was putting my life at risk.
My response? “But the relays are rated to 240V 10A?” – pity me, the almost-dead fool.
Here’s the deal. Whilst the relays are rated that high, and whilst it did work, it seems most professionals would advise us regular folk to keep any ‘maker’ voltages below 50V (and some will say lower than that) – relays or no relays.
We made a new term today – ‘Maker Voltages”. Maybe it’ll catch on and save some lives.
Relays vs Mains
Looking at relay boards specifically, the advice I’ve seen suggests that, to work with relays at high ‘mains’ voltages, you should take a number of measures including:
- Having the relays on a completely separate board to the low voltage controller
- Keeping the separate relay board away from the low voltage controller
- Relays being fixed to a proper ‘relay base’ (I’m guessing this is a type of PCB?)
- Wires from the low voltage controller to the relay board being mains rated
- …being qualified and knowing what you’re doing!
So Avoid Relays?
No. Relays are cool. Really cool.
I think the problem here is taking the ratings for face value. Yes the relays are rated to 240V, but in this specific board, used with these specific components in this specific layout – don’t even think about it.
The fact that they’re rated high means they’ll perform well with whatever ‘maker’ voltages you want to throw at them, but keep away from the mains my friends – it just ain’t worth it! Even taking the board out of the equation still means that you’re fiddling with bare wires that, with one mistake, could send you across the room.
What About Transistors?
Whilst writing this I thought “Don’t transistors do the same thing?”. I hadn’t used a transistor before so I did some reading.
I understand that transistors can be used to do the same job (switching higher voltages), but from my limited research here’s why you may want to use a relay over a transistor:
- Relays (generally) can switch higher currents
- Relays isolate the controlling circuit and the load (transistors can do, but often don’t)
- Relays can switch AC or DC, and can be activated by both too
- They have that lovely little ‘click’ that gives you an indication of what’s going on
- Relays are generally more robust
Despite nearly ending up like the big fish in Jaws 2, I’m actually a big fan of the PiOT relay board.
The shape and size isn’t my personal taste, and the guide could do more to deter us average folk from any temptation to chew on mains power cables, but looking past that – it’s really neat.
Setup is a 3 minute job, there aren’t any libraries or software to worry about and all the annoying fiddly parts have been taken care of.
Now that I have my sights on lower voltage devices to switch, I think this is going to end up on my Raspberry Pi media centre – turning my noisy external hard drive on or off via my phone. I’ll post that project shortly.
I’d love to hear your thoughts on the subject. Perhaps you’re qualified in this field? Maybe you’ve got a great idea for a use for this board? Add a comment and join the discussion.
Until next time…