Driving 5v relay coil using GPIO


5 posts
by jp314159265 » Mon Mar 20, 2017 2:36 am
Hello. I have a Mondial RPC-120 remote power controller that has a 5 volt input to an internal relay. I can't find specs on the coil. I want to control its relay using the GPIO port of my Raspberry Pi Zero. I'm confused if I can drive the 5 volt coil directly with the 3.3 volt GPIO pin or should I use an optoisolator? My gut tells me I should use an optoisolator. Then my question is, can the GPIO pin drive the LED directly or do I need a current limiting resistor? I don't have a particular optoisolator in mind so please recommend one. I also don't know if the relay has a protection diode but assume it does. Can I use the 5 volt on the board or should I provide an external 5 volt supply?
Thank you.
Posts: 2
Joined: Mon Mar 20, 2017 2:28 am
by ghp » Mon Mar 20, 2017 7:00 am
Hello,
difficult to give advice for devices where no datasheet is available.
There are multiple things to consider
- level: usually a 5V logic input can be driven also by 3.3V as logic high is as low as > 2V and GPIO deliver almost 3.3V when no current needed.
- current: is crucial. GPIO can not deliver more than 16mA from a Pi
- isolation: Just connecting grounds together from various systems can be a problem.
- reverse voltage: Could be that the remote system feeds back more than 3.3V into the Pi which will not like this.
- security: whenever unknown devices are connected, it should be considered that unwanted connections to mains could be made. Which is a serious risk.

With unknown devices an opto isolator is useful to avoid all sort of isolation problems. 4N25 or 4N28. But then spend also a separate 5V-supply for the transistor side of the isolator and do not connect raspberry gnd with the remote system in any way.
Be careful and set up this interface as it would carry mains signal (I assume that the RPC-120 is a mains switch for audio).

For the LED, the typical usage pattern is to have a resistor. When driving from GPIO, values are 220 Ohm to 1k.

Hope this helps.
Gerhard
Posts: 1104
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by Grumpy Mike » Mon Mar 20, 2017 6:12 pm
My gut tells me I should use an optoisolator.

Ignore it, it is wrong.
I want to control its relay using the GPIO port of my Raspberry Pi Zero. I'm confused if I can drive the 5 volt coil directly with the 3.3 volt GPIO pin

No you can't. You will need a transistor to drive the relay from the signal given by the GPIO pins. Connect a 1K resistor to the GPIO pin with the other end of the resistor to the base of a transistor (NPN type). Connect the emitter to ground and the collector to one end of the relay. Connect the other end to the 5V line. NOW connect a diode ( 1N4001 will do ) with the anode to the 5V side of the relay and the cathode to the other side of the coil. If you do not use a diode you can damage your Pi.

Then my question is, can the GPIO pin drive the LED directly or do I need a current limiting resistor?

You ALWAYS need a current limiting device when driving an LED, a resistor is the simplest example of a current limiting device.
User avatar
Posts: 867
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by jp314159265 » Mon Mar 20, 2017 7:02 pm
Thank you very much!
Posts: 2
Joined: Mon Mar 20, 2017 2:28 am
by RareHare » Mon Mar 20, 2017 10:23 pm
If you want to avoid using the 2.7 mA from the GPIO pin when the BJT is on, you can use a FET instead of the BJT, as described on this page about low-side switches.
Posts: 82
Joined: Thu Jun 20, 2013 7:17 pm