1

I would like to control both 120VAC and 24VDC from my RPi 3B+. To make this easy, I'm looking at one of the various 3ch or 4ch relay modules for an RPi 3B+, like this or this. I'm familiar with using both AC and DC relays on past projects. The product pictures sure look like they are three independent relay modules, but I just want to confirm that the relays on these boards are completely independent and shouldn't have any trouble switching both 12VAC and 24VDC

  • Hello, it's going to be tricky to answer with any certainty without knowing some more about the specific relay board's you're thinking about. A schematic would be awesome! – Roger Jones Jul 21 at 20:28
  • 1
    It would, wouldn't it! I'm picking between to popular boards (edited my question to add links) from Amazon in the hopes others have experience with them. I don't see schematics listed in the product pages. Or more generally what the expectation is with these HAT-type modules. – kbyrd Jul 21 at 20:44
  • Ahh, ok. So I need more isolation. So the AC Relay would be controlling PSU to a 3D printer. I could keep a traditional or SS relay over next to that PSU, keeping the Pi 1-2ft away running some wires to just control the relay. I'll need some circuitry to drive the relay, but that shouldn't be difficult. – kbyrd Jul 22 at 2:28
  • @kbyrd, the relay modules you suggested are very good - reliable, guaranteed Rpi compatible, and reasonably priced. WaveShare modules and Panasonic relays, in my opinion are no hobbyist, but almost industry grade stuff. I do use Panasonic relays for my more serious projects: (1) Amazon WaveShare Raspberry Pi Compatible Relay Module with photocoupler - XYG Study US$24 amazon.com/dp/B01G05KLIE (2) Amazon Electronics-Salon RPi Compatible (Panasonic) Relay Module - Electronics-Salon UUS$17 amazon.com/dp/B07CZL2SKN – tlfong01 Jul 22 at 3:22
3

WARNING! NEVER put any kind of switch in the Neutral line (unless using a double pole relay). This would violate electrical wiring regulations.

Putting a switch in the Neutral just makes the other side of the relay (and the rest of the circuitry) live when off.

Go with https://www.amazon.com/dp/B07CZL2SKN/. They've been kind enough to provide the schematics and a picture of the underside of the PCB. My usual concern about these boards is that the common pins on the switch side of the relays may share a ground, but the pictures clearly show that all output pins are isolated and only connect to the screw terminals.

I assume you know this already, but just in case others are reading: when switching AC loads that connect to mains with these sorts of boards, always switch the neutral wire. This way, if you accidentally touch it, or if there is a leak, the results won't be too unpleasant!

Obligatory nitpicking: this is not a HAT (which stands for "Hardware Attached on Top"); nor, of course, is it presented as one. A HAT is a specific kind of RPi add-on board that follows the HAT specification.

  • Buying from them because the included the schematic is the right choice, thanks! Regarding switching neutral, that's exactly the opposite of what I thought. Don't you always switch or fuse the hot or live wire (usually black in the US)? That way, when the switch is open, there's no potential to ground at the device. Regarding "HAT", I did not know that, I'll assumed anything with GPIO passthru and that fits on top was a Pi HAT. I'll update my question. – kbyrd Jul 21 at 22:23
  • Ordinarily, yes, you would switch the live wire, for all the obvious reasons (in addition to complying with the National Electric Code if you are in the USA). Here, however, the danger of touching the exposed wire on the screw terminal is higher than the danger of sticking your finger in the device, hence my advice. Unless, of course, you take proper care to insulate it. Needless to say, if this is a permanent installation rather than a quick experiment, complying with the NEC is a good idea :) – JayEye Jul 21 at 22:32
  • Ahh, ok, I see. It's controlling an AC-DC PSU on a 3D printer, so ya, it's not the same danger as a light socket with a light switch making/breaking neutral. It's going to end up in it custom fit case that screws together, has sockets and a fuse inside. So the terminals aren't going to be normally reachable without taking the case apart (which I wouldn't do unless I unplugged it) – kbyrd Jul 21 at 22:40
0

At least one of the devices linked uses opto-couplers. This is a (common) delusion that this provides additional isolation.

One thing, for sure, opto-couplers require high drive currents (which the Pi is poor at) and many designs (which work on Arduino) don't work on a Pi because they require 5V. Without meaningful specifications this is uncertain.

The device which is mounted on the Pi would NOT comply with electrical isolation requirements for mains powered devices.

Such devices are only safe if mounted in a suitable enclosure with isolation between the mains and control circuitry. This needs to meet double insulation standards OR the enclosure needs correct earthing.

In addition they would only comply with additional mechanical anchoring for mains wiring.

  • I saw in an answer to another question someone (you?) posted some recommendation on relay hardware. IIRC, waveshare module was one of them. Is that safe? – kbyrd Jul 22 at 0:26
  • I don't know what post you are referring to. Both the modules you referenced seem to be well designed and should meet safety requirements, BUT only if suitably isolated - which mounting on top of the Pi is not. They would be OK for ELV or for mains if isolated. Opto-isolators are a waste of time if there is ANY common connection (including Gnd) with the output of the isolator. I use them to provide real isolation between independent systems. – Milliways Jul 22 at 2:15
  • What the optoisolator buys you is that the Pi doesn't have to drive the inductive load of mechanical relay (which the second part, the one I preferred, is using). Note that these are not solid-state relays, and they also get their DC power with which to drive the darlington pairs that drive the relays from the 5V rail. The LED that drives the optoisolator would draw a couple of milliamps at most, which the Pi can safely provide. – JayEye Jul 22 at 3:20
  • As for compliance with code, that would only really matter to the OP if they are making a commercial device. Since no amount of code will prevent you from sticking your finger in a live socket anyway (not that 117V would hurt you, but it's still annoying), assuming the OP knows what they are doing, what the NEC specifies is irrelevant. – JayEye Jul 22 at 3:21
  • @JayEye a transistor or FET is needed to drive the relay. The current transfer ratio of opto-couplers is low, so additional amplification is required - either a Darlington or external transistor. Sharing ANY common connection means there is no additional isolation over that provided by the relay - you might as well just use a transistor. – Milliways Jul 22 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.