FnNewGuy
Posts: 5
Joined: Wed Feb 08, 2017 6:08 pm

5V Relay, Power through Pi or with separate source

Wed Feb 08, 2017 6:16 pm

Hi,

I've been trying to research this for some time, and found articles from 2013 to present day and everything seems to conflict, so now I am utterly confused. And I am not an electrical guy so I'm learning as I read.

Basically I'm trying to take a raspberry pi, with a relay board, and open my garage doors.
Relay board: https://www.amazon.com/gp/product/B00E0 ... UTF8&psc=1
Link for additoinal info on relay board: https://www.sunfounder.com/wiki/index.p ... lay_Module
Interfacing with Rasp Pi B+

My main question is, I keep reading that the 5V GPIO pin doesn't have enough current to run the relay board (optocoupler & relay itself), but I see several examples where that's exactly what was done. The DIY'er will leave the jumper that comes on that relay board, connect the 5V GPIO pin from the pi to the VCC of the relay board, and everything seems to function normally. Is this something that shouldn't be done, if so can you explain reasons (keeping in mind I'm not an electrical guy)?

It's essentially what this guy is doing: https://www.geekytidbits.com/open-garag ... pberry-pi/

Then we have this guy that says to remove the jumper and give the relay it's own power source: http://www.matthuisman.nz/2015/09/build ... art-2.html

Thanks guys.

achrn
Posts: 374
Joined: Wed Feb 13, 2013 1:22 pm

Re: 5V Relay, Power through Pi or with separate source

Wed Feb 08, 2017 10:00 pm

From the pictures I get that the relay used is a Songle SRD-05VDC-SL-C. From google I find a data sheet for that, which tells me that the coil draws a nominal 71mA https://www.ghielectronics.com/download ... elayX1.pdf. Actual GPIO pins won't supply that much current.

However, actual GPIO pins don't need to supply that. The relay board will draw that current from a pin on the GPIO header, but that's a power pin, not a GPIO pin. The GPIO signalling pin itself only needs to provide the power to switch the optocoupler (and actually then it's sinking the current, ie, pulling current in, not pushing it out). This is why it works.

However, I wouldn't do that, because with the jumper in place I think the relay board will pull the GPIO up to near 5V when the GPIO is not sinking the current, and the GPIO won't like that (ie, you're risking damage to your Pi). What you should do is remove the jumper, connect the RY-VCC to the 5V pin on the GPIO, connect the VCC pin to a 3.3V on the GPIO header, and the input to whatever GPIO you're using. The potential headache is that the optocoupler might not work at 3.3V (depending on its specs, and I'm not going hunting for data sheets on that just now).

For you, the fastest thing to do is try it - take off the jumper, connect a 5V supply pin to the RY-VCC and a 3.3V supply pin to Vcc, and a ground, and the GPIO controlling signal, and see if it works. If it does work, that's better than leaving the jumper on and risking your pi. (Or you could just try touching a wire between the input pin and the ground pin and see if that makes the relay switch)

If it doesn't work, you could try it with the jumper in place, but you might be putting too high a voltage on the GPIO pin when the relay is not switched on. That would be bad for your Pi. In theory you can calculate what the voltage you're putting on is, but you need to know stuff you don't know. If you can lay your hands on a multimeter it is easier to disconnect the input pins, connect up the power supply and just measure what voltage appears on the input pin - if it's more than 3.3V you shouldn't really hook it up to your pi.

User avatar
davidcoton
Posts: 4153
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 5V Relay, Power through Pi or with separate source

Wed Feb 08, 2017 10:13 pm

There are three related issues.
1) Can the Pi 5V pin on the GPIO provide enough current for the relay coil? YES, the Pi 5V supply is up to it, unless you have a weak PSU, long or thin USB power cable, or very heavy use of USB power for peripherals. RY-Vcc should go to GPIO 5V.
2) Can the Pi GPIO outputs at 3V3 work safely with an opto-coupler connected to 5V? Officially NO, but in practice it seems to work (your risk!). Ideally the Vcc should go to 3V3 on the GPIO, but then you MAY have to reduce the relay board R1/R4 values or short out the relay board indicator LED to make the board work at the lower voltage.
3) Will a GPIO HIGH (3V3) turn off the relay when using 5V Vcc? Probably!
Signature retired

ash73
Posts: 11
Joined: Mon Jan 30, 2017 12:52 pm

Re: 5V Relay, Power through Pi or with separate source

Wed Feb 08, 2017 11:12 pm

Watching this with interest as I need to control a pump and some valves via a 4x relay board. If you haven't got a degree in electronics the simplest approach seems to be buy a cheap Arduino clone off eBay and use the Pi as the brain and the Arduino to handle 5V I/O; you can interface the Pi and Arduino using nanpy.

p.s. or add a logic level converter 3.3V to 5V.

FnNewGuy
Posts: 5
Joined: Wed Feb 08, 2017 6:08 pm

Re: 5V Relay, Power through Pi or with separate source

Thu Feb 09, 2017 1:56 am

@achrn

Thank you for that detailed reply. Your first suggestion worked about removing the jumper. I appreciate it! I apologize for my incorrect terminology of the GPIO vs Power pins.
Last edited by FnNewGuy on Thu Feb 09, 2017 2:15 am, edited 1 time in total.

FnNewGuy
Posts: 5
Joined: Wed Feb 08, 2017 6:08 pm

Re: 5V Relay, Power through Pi or with separate source

Thu Feb 09, 2017 1:58 am

davidcoton wrote:There are three related issues.
1) Can the Pi 5V pin on the GPIO provide enough current for the relay coil? YES, the Pi 5V supply is up to it, unless you have a weak PSU, long or thin USB power cable, or very heavy use of USB power for peripherals. RY-Vcc should go to GPIO 5V.
2) Can the Pi GPIO outputs at 3V3 work safely with an opto-coupler connected to 5V? Officially NO, but in practice it seems to work (your risk!). Ideally the Vcc should go to 3V3 on the GPIO, but then you MAY have to reduce the relay board R1/R4 values or short out the relay board indicator LED to make the board work at the lower voltage.
3) Will a GPIO HIGH (3V3) turn off the relay when using 5V Vcc? Probably!
1) Understood
2) Can you elaborate on the risk? Additionally, do you mean that it is not a good idea to connect the 3.3V power pin (Pin 1) to the VCC of the opto-coupler if the relay is powered by a separate 5V source? I feel like I am not following the scenario you are explaining in #2.
3) Understood

achrn
Posts: 374
Joined: Wed Feb 13, 2013 1:22 pm

Re: 5V Relay, Power through Pi or with separate source

Thu Feb 09, 2017 6:29 am

DavidCoton and I have said the same thing differnet ways.

His point 1 is the same as my discussion of power pins - the 5V supply pin is capable of driving the relay. (Don't worry about terminology - the power pin on the GPIO header would still generally be called a 'GPIO pin', it's just not a pin that's actually connected to a GPIO, but there isn't a generally-accepted good alternative name for it.)

His point 2 is the same as my 'I wouldn't do that' point - it might work if you leave the jumper in place, but it might damage your Pi. The last part of that point is saying the other way is safer (for you pi - it's not dangerous for you).

His point 3 is the same as my 'fastest thing to do is try it' - it might work if you take the jumper off and run the isolator from 3.3v.

In summary - it might work either way (with or wthout jumper), but the 'without jumper' option is the way that if it doesn't work, it won't damage your pi.

If you take off the jumper and use a 5V supply for relay and 3.3V for the optoisolator, it might just not work, because the relay board was expecting 5V for the optoisolator supply, so if you give ist 3.3V, it might just not work. If it doesn't there are modifications you can make to the board that might help.

If you leave the jumper on, the optoisolator gets the 5V it wants, so will work, but it might feed too much voltage into the pi, which might damage the pi. That is, this way round, the 'might not work' for the whole system is because it might damage your pi.

User avatar
davidcoton
Posts: 4153
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 5V Relay, Power through Pi or with separate source

Thu Feb 09, 2017 9:34 am

+1, exactly

In a bit more detail, when the GPIO is HIGH (3V3), it is connected via two LEDs and a resistor to Vcc. If that is 5V, there is a possibility of damage to the Pi. There is also a possibility (unlikely) that the opto-isolator will be passing enough current to switch the relay on, when it should be off.

However if Vcc is 3V3, and the GPIO is LOW (0V), there may not be enough current to switch the opto-isolator ( and therefore the relay) on, when it should be on. In that case modify the relat board as in my earlier post.
Signature retired

User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Re: 5V Relay, Power through Pi or with separate source

Thu Feb 09, 2017 11:17 am

I try from different source and it works.
But, I did with 5V Raspberry Pi pin.
Se my link about my connection:viewtopic.php?f=63&t=151148&p=992304&hi ... on#p992304 and this works for a long time. Relay gets a correct signal from transistor even if GPIO falls to minimal current (it happens to me sometime and I didn't realized when and why).

Faramon

Return to “General discussion”