Page 1 of 1

5V relay - Is this a safe connection?

Posted: Sun Apr 26, 2015 7:19 pm
by d82k
Dear all,

I would like to connect a realy to my RPi.
Having only one working at 5V, here is how I have connected it:

Code: Select all

                5V
                 |
                 |
		          ----
		          |   |
		          |   ----S  Relay
	     Diode	|       S
       1N4004	A   ----S
	          	|   |
          		----
                 |
GPIO             |c
17 ---/\/\/\---|<     Transistor
	     R 1K     |e   2N3904 NPN
                 |
                 |
		      	 GND
Since GPIOs are 3.3V is this a safe connection, can there be any issue having the 5V attached?
Eventually is there a way to have it working using 3.3V instead of 5 V?
Thank you,
dk

Re: 5V relay - Is this a safe connection?

Posted: Sun Apr 26, 2015 8:14 pm
by scotty101
Circuit looks good. Pretty standard relay switching circuit.

Re: 5V relay - Is this a safe connection?

Posted: Sun Apr 26, 2015 8:17 pm
by rpdom
I'd add a 10K resistor between the transistor base and GND to prevent it turning on if the GPIO gets set to Input (whe the Pi is first switched on, for example) and it happens to float high enough.

Re: 5V relay - Is this a safe connection?

Posted: Sun Apr 26, 2015 8:29 pm
by r4049zt
I'm not too happy with only 1k from your gpio control pin to the base of your transistor because the 3mA which it might draw is a bit much for the very tiny system on a chip which drives the gpio. I'd use two of your transistors (look up 'Darlington Pair') and feed one with about 40kOhm from the gpio (an arbitrary 'moderately big' R), expecting to need at least 3mA into the base of the next transistor to get a sensible relaycoil current near to 100mA. You might need to up from 5V to 5.5 to get the relay reliable, but test it as it might work. Don't bother ordering different transistors. Two of the sort which you have already should work.

The other way to do it is to replace 1k into npn transistor(s) with 100k into an nfet, but be careful as some of those don't work with only 3.3V to the gate.

Re: 5V relay - Is this a safe connection?

Posted: Sun Apr 26, 2015 9:06 pm
by rpdom
The GPIO outputs are rated at up to 16mA each. 3mA isn't going to be a problem. :)

Re: 5V relay - Is this a safe connection?

Posted: Thu Apr 30, 2015 5:44 pm
by SteveDee
d82k wrote:Having only one working at 5V....

...eventually is there a way to have it working using 3.3V instead of 5 V?
As you have a test circuit running at 5V, you could take some measurements to assess your chances of running a similar circuit at 3.3V with a 3V relay.

First consider how your circuit is working. The voltage across the 1k base resistor is 3.3V - base-emitter voltage (say, 0.7V). So the transistor base current is (3.3 - 0.7)/1000 = 2.6mA.

The hfe (dc current gain) is quoted at about 30 for a collector current of 100mA. So actual collector current could be 2.6mA x 30 = 78mA approx.

What is the spec of your 5V relay? If it only needs 50mA at 5Volt then the circuit is fine. If it needs 100mA at 5Volts you may not get reliable operation. Also note that the saturation voltage of the transistor (collector-emitter) will reduce the 5Volts to something a little under 5V. You can easily measure this with a cheap multimeter.

Now look for a 3V relay. You need one that will operate reliably on a current less than 78mA.

Final problem is the 3.3V supply from the Pi. If its an old Pi, the maximum available current (I think) is 50mA. For new Pi I'm not sure what the rating is. But if your 3.3V relay supply is from another source/circuit then look at the spec for that.

Do you need a relay for your application (i.e. isolated contacts)? Or is it something that can be switched another way.

Re: 5V relay - Is this a safe connection?

Posted: Fri May 01, 2015 4:04 am
by Tage
rpdom wrote:I'd add a 10K resistor between the transistor base and GND to prevent it turning on if the GPIO gets set to Input (whe the Pi is first switched on, for example) and it happens to float high enough.
if the GPIO pin is floating it should not source any current, so the npn will not turn on

Re: 5V relay - Is this a safe connection?

Posted: Fri May 01, 2015 12:00 pm
by d82k
Dear all,
thank you for your kind replies.

Here some additional details on the relay:
It is a finder 36.11.9.005.4001 (http://gfinder.findernet.com//assets/Se ... /S36EN.pdf)

It says "Minimum switching load mW (V/mA): 500 (5/100)"

Currently it seems working... :|
I did not understand if I have to fix something or if it is just fine...
What I need is just to close the relay for less than a second, I would like to simulate the pressure of a switch.

EDIT: I'm currently using a Model B Revision 2.0 RPi

Thank you,
dk