ASC!1
Posts: 5
Joined: Sat Jul 06, 2019 12:33 pm

Max current from GPIO and GND

Tue May 11, 2021 11:23 am

Hello everyone I wonder if any one can help me fix the confusion in my head about the RPi 4.

Would i harm the pi if i used the GPIO pin as an output and set it low and used it to complete a external circuit to a relay

so

GPIO ------[RELAY]-------[EXT 5V SUPPLY]

Image

User avatar
joan
Posts: 15616
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Max current from GPIO and GND

Tue May 11, 2021 11:30 am

The Pi GPIO can source/sink of the order of 16 milliamps.

Don't connect a voltage outside the range 0-3V3 to a Pi GPIO.

ASC!1
Posts: 5
Joined: Sat Jul 06, 2019 12:33 pm

Re: Max current from GPIO and GND

Tue May 11, 2021 2:30 pm

joan wrote:
Tue May 11, 2021 11:30 am
The Pi GPIO can source/sink of the order of 16 milliamps.

Don't connect a voltage outside the range 0-3V3 to a Pi GPIO.
So would this Circuit work ? With 12 k resistor ?
I want to make flexible as i don't know the values of the relay yet.

Image

User avatar
neilgl
Posts: 3242
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Max current from GPIO and GND

Tue May 11, 2021 2:45 pm

Have a look at this, as you seem to have an “active low” relay https://www.raspberrypi.org/forums/vie ... 8#p1225448

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

Re: Max current from GPIO and GND

Tue May 11, 2021 3:15 pm

ASC!1 wrote:
Tue May 11, 2021 2:30 pm
joan wrote:
Tue May 11, 2021 11:30 am
The Pi GPIO can source/sink of the order of 16 milliamps.

Don't connect a voltage outside the range 0-3V3 to a Pi GPIO.
So would this Circuit work ? With 12 k resistor ?
I want to make flexible as i don't know the values of the relay yet.

Image
Yes, but for maximum flexibility and reliability use a lower value base resistor (~1K to start).
You should add a back EMF suppression diode across the relay coil, cathode to the +ve side, 1N4001 or similar.
Location: 345th cell on the right of the 210th row of L2 cache

ASC!1
Posts: 5
Joined: Sat Jul 06, 2019 12:33 pm

Re: Max current from GPIO and GND

Tue May 11, 2021 6:38 pm

davidcoton wrote:
Tue May 11, 2021 3:15 pm
ASC!1 wrote:
Tue May 11, 2021 2:30 pm
joan wrote:
Tue May 11, 2021 11:30 am
The Pi GPIO can source/sink of the order of 16 milliamps.

Don't connect a voltage outside the range 0-3V3 to a Pi GPIO.
So would this Circuit work ? With 12 k resistor ?
I want to make flexible as i don't know the values of the relay yet.

Image
Yes, but for maximum flexibility and reliability use a lower value base resistor (~1K to start).
You should add a back EMF suppression diode across the relay coil, cathode to the +ve side, 1N4001 or similar.
Do you mean like this ??

Image

What's the difference ?

Image

boyoh
Posts: 1618
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Max current from GPIO and GND

Tue May 11, 2021 8:03 pm

ASC!1 wrote:
Tue May 11, 2021 2:30 pm
joan wrote:
Tue May 11, 2021 11:30 am
The Pi GPIO can source/sink of the order of 16 milliamps.

Don't connect a voltage outside the range 0-3V3 to a Pi GPIO.
So would this Circuit work ? With 12 k resistor ?
I want to make flexible as i don't know the values of the relay yet.

Image

From BoyOh
I would do a calculation for the Transistor base current to use it as a switch ( Saturation )

Base current some ware in the region of 10ma

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

emma1997
Posts: 1520
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Max current from GPIO and GND

Tue May 11, 2021 9:17 pm

Actually base current for common NPN would usually be in the range of microamps, not milliamps assuming reasonable hfe. 12k probably works with most transistors like 2n3904 and small relays but 1k or even 220r would be better choice. Some get huge kicks out of cackulating values but, not being a big fan of math, at least not unless getting paid to do it, I just stick any ol' low value in junk box and have yet to see a relay that fails to throw.

Using an NFET like 2n7000 would be in the pico- or femto-amp range. Side benefit no resistor needed at all. Another advantage they are now actually cheaper than BJT.

Also note that although official GPIO spec may (or may not, lol) be 16ma the actual max is more than double that. One or two pins may not do harm but too many can definitely shut down the Pi even at 16ma. I have done actual tests demonstrating this.

For hobby use I've driven small relays and motors directly with no transistor. Some of my reed relays and pager motors can do with as little as 15ma. I would not try hooking one up to every pin on the Pi simultaneously as heat quickly goes out of control. Putting cheap logic parts like 74hc244 or 74hc373 in between fixes that and allows driving much higher power coils to boot.

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

Re: Max current from GPIO and GND

Tue May 11, 2021 9:45 pm

ASC!1 wrote:
Tue May 11, 2021 6:38 pm
What's the difference ?
When the transistor switches off, current tries to continue flowing through the relay coil. This results in a very high reverse voltage, which will radiate RF interference and may damage the transistor. The diode provides a current path for the reverse voltage, clamping it to a value that virtually eliminates RF and prevents damage.
Location: 345th cell on the right of the 210th row of L2 cache

dbrion06
Posts: 304
Joined: Tue May 28, 2019 11:57 am

Re: Max current from GPIO and GND

Wed May 12, 2021 7:39 am

Instead of o transistor, you might use ULN2803 darlington array https://www.ti.com/lit/ds/symlink/uln2803a.pdf:
each channel has a bul in resistor, protection diodes (are necessary david cotton reminded you).
Wiring is much simpler (and finding the pins of a transistor is somewhat complicated (like throwing dice: there are 5 potential horrors). An IC is much easier (and, if you need 2... 8 relays, soldering will be less tedious and less horror prone.)

ASC!1
Posts: 5
Joined: Sat Jul 06, 2019 12:33 pm

Re: Max current from GPIO and GND

Wed May 12, 2021 12:35 pm

dbrion06 wrote:
Wed May 12, 2021 7:39 am
Instead of o transistor, you might use ULN2803 darlington array https://www.ti.com/lit/ds/symlink/uln2803a.pdf:
each channel has a bul in resistor, protection diodes (are necessary david cotton reminded you).
Wiring is much simpler (and finding the pins of a transistor is somewhat complicated (like throwing dice: there are 5 potential horrors). An IC is much easier (and, if you need 2... 8 relays, soldering will be less tedious and less horror prone.)
Your link does not work. Its ok i found it anyway
https://www.ti.com/product/ULN2803A?key ... everything

I may have failed to mention i want to build it out of parts i have in parts bin. So most common parts like resistors, diodes and transistors maybe a few mosfets nothing as fancy as ULN2803. :-)

dbrion06
Posts: 304
Joined: Tue May 28, 2019 11:57 am

Re: Max current from GPIO and GND

Wed May 12, 2021 12:49 pm

ULN2803 is very old IC (late 1990s), not a fancy one.
As I am very old, too, it is much easier for me to wire a welll designed darlington array than discrete parts.. (74 xx24x were hinted, too: ULN2803 is very robust, has all diodes you need and can cope with 50v relays)... If you want 4 relays, you might find wiring with discret parts tedious...

Return to “Beginners”