Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

5v relay grounding

Thu Aug 20, 2015 7:09 pm

I'm using my Pi to control a mains relay through a GPIO output and I have stumbled across something that I just need to check with people who are more familar with the Pi than I am.

Originally I was using the +5v (DC+), Gnd (DC-), and a single 3.3v GPIO pin to trigger the relay, which was all working fine. As I added more components to the project that I am working on I found that I was running out of usable power and it was causing issues at certain points during my program. As I have a 5v AC/DC adaptor around I decided to utilise it to power the relay and ake some of the strain off of the Pi.

Now I have the + and - to their respective points and the relay powers up correctly. To use a 3.3v to trigger the relay I would need to ground it back to the Pi; is it okay to connect the GPIO ground to the same point as the DC- on the AC/DC adaptor on the relay?

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: 5v relay grounding

Thu Aug 20, 2015 10:00 pm

Yes. Not a problem. Just keep the 5v away from your pi
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5v relay grounding

Thu Aug 20, 2015 11:41 pm

Not clear how you have things wired up but I do have some worries.

1. What is the relevance of the 5 volt supply? If the relay is wired between a GPIO and +5v you risk damaging the RPi. The GPIO are not 5 volt tolerant.

2. If the GPIO is connected to the relay, the GPIO may be handling more current than it can safely do so. (RPi at risk of damage, not your safety.)

3. If the GPIO is connected to the relay and the relay is the old-fashioned coil type, the back emf when current in the coil is switched off can damage the GPIO.

There are many tutorials which show how to use a transistor, two resistors and a diode between a GPIO and a relay coil.
Quis custodiet ipsos custodes?

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Fri Aug 21, 2015 3:06 pm

drgeoff wrote:1. What is the relevance of the 5 volt supply? If the relay is wired between a GPIO and +5v you risk damaging the RPi. The GPIO are not 5 volt tolerant.
The 5v DC power supply is for 240v mains relay which requires 5v to power and a Hi or Low input to switch states. I'm not sending 5+ into the GPIO, at least not with purpose. This is exactly why I am asking if there is any risk in sharing the GPIO ground return with the negative of the 5v DC supply as otherwise the GPIO cannot act correctly as a switching signal.
drgeoff wrote:2. If the GPIO is connected to the relay, the GPIO may be handling more current than it can safely do so. (RPi at risk of damage, not your safety.)
GPIO is the switching input for the relay, it's not connected to the 5v+ nor to the 240v+.
drgeoff wrote:3. If the GPIO is connected to the relay and the relay is the old-fashioned coil type, the back emf when current in the coil is switched off can damage the GPIO.
The relay is purpose built for use with micro-computers to control mains power.

I'm at work so here is my quick diagram detailing my setup.

https://drive.google.com/file/d/0ByGKVy ... sp=sharing

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Fri Aug 21, 2015 3:07 pm

scotty101 wrote:Yes. Not a problem. Just keep the 5v away from your pi
Thanks for your reply.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5v relay grounding

Sat Aug 22, 2015 7:58 am

1. The critical point is the relay. What is inside it on the connection that goes to the RPi GPIO?

If the relay has a coil whose other end goes to 5 volts or if there is a pull-up resistor to 5 volts, then you will be putting 5 volts on the GPIO when the GPIO is set high.

2. Irrespective of the above, it will never work if you do not connect the -ve of the 5 volt supply to the RPi -ve (ground).
Quis custodiet ipsos custodes?

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: 5v relay grounding

Sat Aug 22, 2015 8:16 am


drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5v relay grounding

Sat Aug 22, 2015 9:07 am

I wonder what percentage of noobs reading that are going to connect the diode the wrong way. That article uses a pnp transistor and a negative supply.
Quis custodiet ipsos custodes?

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Sat Aug 22, 2015 9:19 am

drgeoff wrote:1. The critical point is the relay. What is inside it on the connection that goes to the RPi GPIO?

If the relay has a coil whose other end goes to 5 volts or if there is a pull-up resistor to 5 volts, then you will be putting 5 volts on the GPIO when the GPIO is set high.

2. Irrespective of the above, it will never work if you do not connect the -ve of the 5 volt supply to the RPi -ve (ground).
Thanks for your input. When I posted this question I was at work and didn't have access to my Pi so I was curious.

When I got home I took some readings and found that I got exactly the same results regardless of if I powered the relay using
5v from the Pi or 5v from the AC/DC mains supply.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5v relay grounding

Sat Aug 22, 2015 11:04 am

Whether the 5 volts comes from the RPi or from somewhere else is not the issue. The issue is whether 5 volts from anywhere can get to the GPIO. I have already explained how that can happen.

As you seem to be unwilling or unable to give any information about the relay you are using, I cannot help you further.
Quis custodiet ipsos custodes?

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Sat Aug 22, 2015 11:39 am

drgeoff wrote:Whether the 5 volts comes from the RPi or from somewhere else is not the issue. The issue is whether 5 volts from anywhere can get to the GPIO. I have already explained how that can happen.

As you seem to be unwilling or unable to give any information about the relay you are using, I cannot help you further.
Not sure if you missed my above post but I have found the answer to my question, I no longer require any assistance on this matter.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5v relay grounding

Sat Aug 22, 2015 11:48 am

You may have a working system this time. But you do not understand why. Next time you try something similar, but not exactly the same, you may be less lucky and have a non-working system and a dead RPi.
Quis custodiet ipsos custodes?

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Sat Aug 22, 2015 12:02 pm

drgeoff wrote:But you do not understand why.
If you say so.

I feel you may have taken my line "got exactly the same results" as "it worked the same". What I meant is that my metered readings produced near identical results, allowing me to conclude that the external supply was not in-fact producing any harmful effects on the RPi.

Have a great weekend!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: 5v relay grounding

Sat Aug 22, 2015 12:10 pm

you may want to read this thread! : viewtopic.php?p=805079#p805079

and yes, you should wire the grounds together.

Robodanjal
Posts: 17
Joined: Tue Aug 11, 2015 8:18 pm

Re: 5v relay grounding

Sat Aug 22, 2015 12:29 pm

mahjongg wrote:you may want to read this thread! : viewtopic.php?p=805079#p805079

and yes, you should wire the grounds together.
Thanks Mahjongg.

Return to “Troubleshooting”