Kayleh
Posts: 5
Joined: Sun Jan 03, 2016 1:59 am

Lighting An LED

Sat Jan 09, 2016 2:49 am

Ey, I'm decently new to the Raspberry pi and have a 2 Model B and i'm wanting to light up and led with the GPIO pins. i've lighten LEDs on a breadboard with a 9v battery so i have some experience with LEDs and resistors. i have watched this video https://www.youtube.com/watch?v=lzIDqWp2mdQ and i can't get it to work and the first time i tried it rebooted itself and then i waited a week (with 6 reinstallations of raspbian jessie) and now it doesent do anything. Any replys would be helpful

Heater
Posts: 13878
Joined: Tue Jul 17, 2012 3:02 pm

Re: Lighting An LED

Sat Jan 09, 2016 5:48 am

Did I just watch a video of someone lighting a LED from a Pi pin with no current limiting resistor?

I suspect you blew your Pi up doing that.

Forget the LED, does your Pi even boot up now?
Memory in C++ is a leaky abstraction .

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

Re: Lighting An LED

Sat Jan 09, 2016 5:59 am

Heater wrote:
I suspect you blew your Pi up doing that.
Not even a remote possibility. Do the math. Or actually measure current as I have done. It's called Ohms Law not Ohms Suggestion.

Heater
Posts: 13878
Joined: Tue Jul 17, 2012 3:02 pm

Re: Lighting An LED

Sat Jan 09, 2016 6:22 am

emma1997,
Not even a remote possibility. Do the math. Or actually measure current as I have done. It's called Ohms Law not Ohms Suggestion.
Ohm's Law does not apply to LEDs. LEDs are not resistors. They are very non-linear devices whose characteristics vary greatly. Especially between different colour of LED.

Please show your math workings.

Now, I'm quite aware that one can get away with running a LED with no current limiting resistor in some situations. If one knows what one is doing.

Might this statement from our OP: "...the first time i tried it rebooted itself..." not be a hint that this is a really bad idea?

Assuming the instructions in the vid were followed that is shorting a LED across the 3.3v supply. No wonder it rebooted!
Memory in C++ is a leaky abstraction .

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 7:04 am

It all depends on the led used. Take a look at the datasheet here for example
http://uk.farnell.com/optek-technology/ ... dp/1497975

Some colours will take 20mA at 3.3v others take >100mA (assuming the led can take it without blowing), other models maybe even more. enough to blow a gpio output and possibly pull down the 3.3v supply, l don't know the rating of that.
Last edited by gordon77 on Sat Jan 09, 2016 8:29 am, edited 1 time in total.

Kayleh
Posts: 5
Joined: Sun Jan 03, 2016 1:59 am

Re: Lighting An LED

Sat Jan 09, 2016 8:05 am

lol i step away from the keyboard and go hang with friends and come back and slapped in the face with replys. yeah i boots fine ad i wuz able to light the led not very bright tho

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 8:30 am

Do you have a resistor in series with it?

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Lighting An LED

Sat Jan 09, 2016 10:41 am

The Pi will generally light a single LED without a resistor. It isn't a good idea but it usually doesn't break anything.

If I remember correctly the maximum current from all of the GPIO pins together is 16mA and any one of them can supply that current if none of the others are used.

That's enough to light the LED and the fact that the LED pulls the GPIO pin down to 2V (or whatever the forward voltage is) may stress the GPIO but it doesn't (in my experience) damage it.

But it isn't as safe as doing the same thing on an Arduino. The CPU on an Arduino has protection on its outputs so they will supply no more than 20mA. It is perfectly safe to use an LED without a resistor. The Raspberry Pi's CPU is designed to be used in mobile phones with a lot of other circuitry around it and it doesn't have protection on its GPIO pins. You can damage them if you are not careful.

For example the Arduino can only supply a maximum of 100mA. So if you try to light more than five LEDs (5x20=100) it will not work but you won't break anything (IIRC). If you try to pull more than the 16mA from a Raspberry Pi's GPIO pins it will probably try to do it, overheat the circuitry in the CPU and break permanently. Lighting one LED for a few seconds is probably right on the edge of what is safe.

When you use a resistor you put it in series with the LED. The resistor connects to the GPIO, the LED (long leg) connects to the resistor and the LED (short leg) connects to ground. When you turn it on the resistor and the LED share the 3.3V between them. The voltage that the LED takes is its Forward Voltage, which is given in its datasheet. It might be 2.2V, if so the resistor will have 1.1V

The current we want to give the LED has to be under that 16mA and modern LEDs work fine with less than 20mA. We might decide to give this LED 5mA, which will be rather dim but still quite bright enough to see.

So then we have to apply ohms law to the resistor to find out what value it need to be. We know the current (5mA or 0.005A) and the voltage (1.1V), so the resistance is:
V = I x R
R = V / I = 1.1 / 0.005 = 220 ohms.

KeithSloan
Posts: 321
Joined: Tue Dec 27, 2011 9:09 pm

Re: Lighting An LED

Sat Jan 09, 2016 11:11 am

rurwin wrote: If I remember correctly the maximum current from all of the GPIO pins together is 16mA and any one of them can supply that current if none of the others are used.
I believe the correct information is maximum 16ma per pin, but all GPIO pins must not exceed 51 mA so for all data pins that would be an average of 3 mA

Reference http://www.scribd.com/doc/101830961/GPIO-Pads-Control2

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 2:56 pm

"The Pi will generally light a single LED without a resistor. It isn't a good idea but it usually doesn't break anything."

I think you to be careful, look at the datasheet l linked to. Some colours will well exceed the 16mA, and even the 50mA PI MAX, with no resistor, and some leds will exceed their max voltage.

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

Re: Lighting An LED

Sat Jan 09, 2016 3:02 pm

Heater wrote: Ohm's Law does not apply to LEDs. LEDs are not resistors. They are very non-linear devices whose characteristics vary greatly. Please show your math workings.
I asked first and anyway not inclined to do your homework for you ATM. But did take a minute to pull a common LED out of the junk box and connect direct from pin 8 (hard high) to ground and measured 6.9ma. So we are not even close to the pin limit and could hook up quite a few with no resistors at all and still not violate package limit. Or anywhere near over-driving the LEDs themselves.

BTW Ohms law does apply to LEDs and any other device that draws power be it linear or not. It's interesting how people tend to develop belief systems based on zero empirical or even theoretical data.

In any case there is very little need to pull out fancy equations to calculate resistor values. What it boils down to is, with modern devices as efficient as they are, a 1k resistor pretty much lights up the room and even 10k more than enough for visibility. Or no resistor at all if you don't happen to have one handy and are not frightened by bright lights.

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 3:49 pm

Isn't pin 8 the TXD line, not directly connected to 3.3v ?

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

Re: Lighting An LED

Sat Jan 09, 2016 3:55 pm

To be honest I am not sure of the inner details. In direct to ground tests (thread locked now due to hysteria) I measured the same draw as pushing other pins high with PiGIO library. So since 8 always goes high by default on all the distributions I no longer bother running special programs. "Path of Least Resistance" is my middle name (excuse the pun).

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 3:57 pm

What led do you use ? It's characteristics will determine the current drawn.

i took a selection I have to hand

across 3.3v no resistor

Blue 8.5mA
Green 80mA
Red 164mA
Yellow 192mA
Last edited by gordon77 on Sat Jan 09, 2016 4:12 pm, edited 1 time in total.

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

Re: Lighting An LED

Sat Jan 09, 2016 4:06 pm

It was a generic white which happens to be the most common type in the world now according to a yahoo thread. I have also tried red and green which results in slightly more draw but still well within safety spec. The difference in Vf among other colors is mv not volts so variations are not expected to be huge.

No matter what I am convinced there is no violation of spec and certainly little chance of shorting the supply or even reboot. That comment about 100ma makes no sense to me. Personally OPs mention of 9v is much more concerning and if anything most likely reason for dead Pi.

User avatar
rpdom
Posts: 15575
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Lighting An LED

Sat Jan 09, 2016 4:14 pm

I think it is rather difficult to sink or source too much current from a GPIO as there is configurable internal current limiting on each pin. A dead short might damage it though. I don't intend to try and find out.

Overvoltage, however, is pretty much a certain way to cause damage to some extent or other.

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

Re: Lighting An LED

Sat Jan 09, 2016 4:30 pm

gordon77 wrote:i took a selection I have to hand

across 3.3v no resistor

Blue 8.5mA
Green 80mA
Red 164mA
Yellow 192mA
After your edit I see now where you pulled the100ma number from (except for yellow which is anomalous) but it's unrelated to the subject at hand involving connecting across I/O not across power supplies. It would be amazing if you could really draw even 1/10th that. Weird how many think you can draw amps from an MCU pin.

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 4:39 pm

You can't draw amps from a gpio pin, it may fail if you try to draw more than 16mA.

If you watch the video linked by the OP you will see its across the supply not a gpio pin.

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

Re: Lighting An LED

Sat Jan 09, 2016 5:40 pm

Alexandra seems to be the quintessential Pi-moron-i think. I laughed so hard almost fell off my chair. IMO that short was best work of art since "Look Around You" series (IMO greatest UK production EVER).

Unless RPF scrambled RPi pins recently her negative was actually positive and versa visa. The only reason that LED lit at all was because she plugged it in backwards, calling the short lead "positive". A case where two (or more) wrongs do make a right. I knew we were in for a treat starting out with that claim "Raspberry Pi only emits 5 volts" and that hooking up a "higher voltage LED will fry it". LOL

Most amusing of all is the air of conviction and expertise she "emits". Not that unusual considering this seems to be the norm on internet, specially some forums. The real problem is noobs can't tell the difference between jokers like her and those with real knowledge and experience. Tendency is to follow lock step with the ones they like rather than those who know.

Anyway the OPs subject matter is LED on I/O, not across power supplies.

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 5:47 pm

Unless the pi has some kind of internal current limit or internal resistance in the GPIO source then l still say you risk the GPIOS failing by running an led with no resistor.

You may have got away with the leds you use with it but others may not.

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

Re: Lighting An LED

Sat Jan 09, 2016 6:00 pm

It ain't just me and my mad scientist experiments, it's the math and the specs too. If 6-7ma will fry a pin then there are a lot more dead Pi out there than imagined. Of course you are entitled to your belief system just as I am mine.

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 6:19 pm

Worth a read..http://www.thebox.myzen.co.uk/Raspberry ... tputs.html

There maybe no immediate failure but increased risk of premature failures.

Why risk it for the cost of a resistor?

I don't know where you thought l said 7mA will fail a gpio output, maybe you don't understand the specs l've been quoting.

I looked up white leds and they shouldn't be a problem as they operate normally with vf >3v
http://uk.farnell.com/cree/c535a-wjn-cs ... dp/1855545

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

Re: Lighting An LED

Sat Jan 09, 2016 6:43 pm


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

Re: Lighting An LED

Sat Jan 09, 2016 6:53 pm

Yes, similar results to what I got shorting pins. But LED Vf coupled with pin impedance, which is what we are talking about here, is not shorting pins or power supplies so draws far less. Not even close to violating spec limits.

Gordon, it true I do not understand some statements. For example:
gordon77 wrote:Unless the pi has some kind of internal current limit or internal resistance in the GPIO source then l still say you risk the GPIOS failing by running an led with no resistor.
Duh... Of course these pins have internal limit. Exactly my point. In fact all power supplies and batteries (even car/Pb) have internal resistance. The question is how much and what is the resulting current allowed. Both math and experiments back up what I say about Pi pin current into an LED. Which is more than enough so time to move on to other subjects.

gordon77
Posts: 4294
Joined: Sun Aug 05, 2012 3:12 pm

Re: Lighting An LED

Sat Jan 09, 2016 7:22 pm

Violating limits is clearly different in my book than yours. 16mA per pin / 50mA all pins recommended.

End.

Return to “General discussion”