The Problem with Relays

Why is it hard to find relay boards that are designed to work specifically with the Raspberry Pi? After all, they’re pretty simple devices, right? Well, we can think of three reasons to start:


We can also think of two more reasons:


Let’s tackle the first topic since it’s really the meat of the issue. What are relays good for? Relays are excellent for switching high voltage / high current loads with low voltage devices like a Raspberry Pi. The most typical application is to switch AC line voltages which are 120V in the U.S. and 240V in the EU. Since the coils in most relays require more current that the RPI can provide, it is common practice to drive them with a transistor as shown in the schematic below. When the GPIO signal to the left of R1 goes high, the transistor switches on and pulls current from the +5V supply through the relay coil. That, in turn, produces a magnetic field that pulls an armature into contact with a normally open terminal thus closing the switch. The coil in the relay is electrically isolated from the contacts with breakdown voltages typically around 3000VAC. Therefore, relays are an ideal component for using a low voltage drive to control a high energy load.


So, what are the safety issues? The primary safety standard in the U.S. for IT equipment is called UL60950. Among other things it prescribes the rules for the design of devices that connect to hazardous voltages.

  1. When connected to line voltages, some of the leads and pins on the relay are at lethal potentials and the user should not be able to touch any of these points. The solution here is an enclosure or a layer of insulation that is either permanent or requires a tool to remove. The UL standard goes so far as to include the design of a “finger” that is used for testing access to traces and pins that may be at high potential:
  2. In the event that the relay breaks, high voltages can cross over onto the low voltage side and destroy your Raspberry Pi as well as putting those lethal voltages on all of your wires and traces. UL 60950 states that a design should continue to be safe after a “single point failure.” Therefore, a safe design requires an extra layer of electrical isolation such as an opto-isolator between the RPI and the relay coil and an isolated power supply for driving the relay coils. In the event of a single point failure, these components may have hazardous voltages on them and so they also have to be covered and made inaccessible to the user.
  3. When using high voltages on a printed circuit board, attention has to paid to the distances between the low voltage traces and the high voltage traces. Specifically, the PCB designer has to be cognizant of what is called creepage and clearance. The following diagram explains these two terms:expeltec-creepage
    These parameters also apply to the traces between adjoining relays if more than one is in use. There is a website called where you can calculate these values based on the voltages you are designing for as well as your pollution class. If we select 120VAC, reinforced insulation, and pollution degree 2, we see that we need 2mm of clearance and 3mm of creepage for a FR4 circuit board.

And those other two reasons?

  1. Cost: a) All components that can energize the low voltage side of a relay circuit with hazardous voltages after a single point failure have to be electrically isolated. This requires the addition of opto-isolators and isolated power supplies for the relay coils. b) To make a safe relay board, all exposed pins and traces that can be at a hazardous potential have to be enclosed or covered. This also includes any pins and traces that can be hazardous after a single point failure.
  2. Power: this is an often overlooked issue but relay coils are not low power devices. A moderately powered one can pull 40mA at 5VDC. If you have 8 of those on a single board you’re pulling 320mA when they’re all on. If you’re driving the coil power supply with the 5VDC from your Raspberry Pi you have to make sure that your power source can handle the additional load. And if you have more than 8 relays, you may have to use a dedicated supply.

Let’s take what we’ve discussed and examine a popular relay board that is sometimes connected to the Raspberry Pi: the SainSmart 5V Relay Module. This board is available at Amazon Prime for $10.19 and there’s quite a bit of documentation for it. Here’s pictures of the top and bottom:


The first thing we see is that there’s obviously no enclosure or cover over the bottom of the board. So, all those exposed terminal block and relay pins on the bottom will potentially be “live”  when the board is in use. There are U shaped slots between the middle relay contact and the ground to satisfy the creepage requirement. Looking at the top of the board we see that there’s no cover over the screw heads on the terminal blocks and these too may be at a hazardous voltage. Now let’s look at the schematic and discuss protection against single point failures:


SainSmart does isolate the relay coils from low voltage side through opto-isolators (U1, U3, U5, and U7). And it even appears that if you choose, you can drive the relay coils with an isolated power supply attached to pin 2 of J? (<– that’s not a typo) called “JD-VCC”. The problem is that everything is operating from a common, non-isolated ground. In the event of a single point failure that ground will float up to a hazardous voltage potential which pretty much makes the opto-isolators nothing more than a decoration in this design. So, if you choose to purchase and use this board, all we can say is: BEWARE.



  1. Which relay board do you prefer to use? Have you found one with isolated grounds?

    • We never found one that was acceptable so we’re in the process of designing our own. It will have 7 relays and is designed to meet the UL 60950 standards. We should have these for sale in about six weeks.

  2. Excellent. I ordered one of the cheap ones to experiment with. I look forward to seeing your relay board.

  3. Hi, excellent article! We are also making a consumer device which incorporates relay modules. I was digging for safety information about these relays and ended up here. Did you guys have finished your design?

    • Yes, they are available for purchase here on the site.

    • Yes, they are available for purchase here on the site.

  4. what is the value of Transistor and diode.
    PLease reply

    • The components would have to be selected based on the the amount of current that the relay coil requires. But let’s say it needs something like 100mA. Then the transistor could be a PN2222A, and the diode could be a 1N4001. You could also use a MOSFET instead of a bipolar transistor.

      • Hi Thankyou for the reply.
        The relay I’m using is 7A 250V, 10A 24VDC,
        so which transistor & diode should I use
        Relay name is HL JQC-3FC(T73) DC 5V

        • The components I called out should work with that relay assuming you’re driving it with 5 volts DC.

Leave a Reply

Der Glaube an eine vom wahrnehmenden Subjekt unabhängige Außenwelt liegt aller Naturwissenschaft zugrunde. Albert Einstein