ground_
Posts: 17
Joined: Tue Oct 14, 2014 6:13 am

Connect LED's safely (calculate with current)

Tue Oct 14, 2014 6:40 am

Hello everybody,

This week i will finally receive my raspberry PI. I am hyped for it as I can start some projects which I wanted to test out for now, so I am already made an electrical circuit plan on paper, but it didn't take long to get to my first problem (which after puzzling a day I can't solve).

I want to achieve the following:
- Connect a RGB LED strip (12v) to a raspberry pi (based on this: http://mitchtech.net/raspberry-pi-pwm-rgb-led-strip/ );
- Have a single LED parallel to this system (in such a way, that if for some reason the led strip isn't working, the singe LED will not light up. But when the single LED isn't working, the led strip will still work).

Now I made the setup as seen in the attachment but i still have the following questions:
1) how does the current with the gpio ports of the rpi work?
i know basic stuff about the volt, resistance and current. But i just can't figure out how much the gpio port will provide. I read that it is not safe to draw more than 16mA (and a total of 50mA), but does that mean that one gpio port always output 16mA, or need i set that value somewhere.

2) How does it come that the rgb led strip doesn't have an - point?

I got how the tip120 works and why the tip120 is needed, but why does it come that the led strip doesn't have a - point. (as i am writing it i just started to think that the r,g and be point would be the minus point. and by connecting those you led the electricity run through and complete the "circle" )

anayway, thanks in advance!
Attachments
setuphelpt.png
setuphelpt.png (42.42 KiB) Viewed 2188 times

User avatar
Burngate
Posts: 6303
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connect LED's safely (calculate with current)

Tue Oct 14, 2014 10:43 am

I don't really like that page, for various reasons, but to answer your questions ...

1) When a GPIO output is set to high, it attempts to hold the pin at 3v3. However, if whatever it's connected to tries to draw too much current, the voltage will drop (and the Pi might get damaged)
The same thing happens when it's set to low - it attempts to hold it at 0v, but forcing current in will pull the pin's voltage up (and the Pi might get damaged)

The TIP120, being a bipolar device (actually a darlington pair, so two transistors) has a more-or-less fixed base-emitter voltage of about 1v3 when it's on.
That means that the GPIO is trying to pull it up to 3v3, while the transistor is trying to hold it down to 1v3. One or the other, or both, are going to fail, and excess current will flow.

So there should be a resistor between the GPIO pin and the base of the transistor to control the current. Calculating its value requires knowing how much current the transistor needs to be turned fully on.

2) You're pretty much correct.
Assume the LED strip is just a set of LEDs (and series resistors) connected between the 12v point and the R/G/B points.
Current flows from the 12v supply, through the LEDs, then through the transistor collector, out of its emitter into the ground and back to the 12v supply.

User avatar
Burngate
Posts: 6303
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connect LED's safely (calculate with current)

Tue Oct 14, 2014 10:48 am

Thought I'd put this in a separate post.
I don't like that tutorial because:
1) he hasn't put a resistor between the GPIO and the transistor - see above
2) he doesn't specify which LED strip he's using (there are lots of different ones, and they don't all work the same)
3) as far as I can see, he hasn't replied to any of the questions in the comments.

ground_
Posts: 17
Joined: Tue Oct 14, 2014 6:13 am

Re: Connect LED's safely (calculate with current)

Wed Oct 15, 2014 12:10 am

Thanks for the reaction! it helped me a lot.

I did some more homework today and figured out the following:
The specific properties of the led is still unknown, but it is safe to guess the voltage drop around 1.8. (afterwards i can recorrect it, but with a 220 ohm resister i should be safe for now).

I still wonder how you found out the base-emitter voltage. As it says 5v in some documents (http://www.adafruit.com/datasheets/TIP120.pdf), and other web sites are talking about 2.5.

anyway i updated my circuit, buit i still dont feel confident about it as a 13 ohm resister doesn't seem right at all. So i wonder what i am doing wrong?

edit: obviously i am doing something wrong, drawing 120 mA from my rpi will bake it :P

edit 2 (with a second correction updated):
ok i think i figured it out:

my led uses between 2 and 3 Ampere. And the Hfe of the tip120 is 1000.
So i want to input 3mA. the voltage drop seems to be common knowledge and 0.7 V per transistor. As the tip 120 is a double transistor the voltage drop will be 1.4
This gives that i want to use a resisitor which outputs 0.003A at 1.9V, so 633 Ohm.

now i have a choiche between 620 ohm or 680 ohm, which should i take (if my theory and calculations are correct)?
Attachments
circuithelp.png
updated with corrections
circuithelp.png (62.07 KiB) Viewed 2083 times

User avatar
Burngate
Posts: 6303
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connect LED's safely (calculate with current)

Wed Oct 15, 2014 9:44 am

One thing that frustrates me: something might appear to me to be so simple as to not require any discussion, but when I try to put it into English, it turns into a mish-mash of gibberish. A generation of students was saved from a life of utter bewilderment when I decided not to be a teacher.

So I can do no better than to quote from another thread:
mahjongg wrote:... an average transistor, used a a switch has a far lower "current gain", than what is stated in the data sheet as "gain" or "Hfe". a simple BC547B may have a Hfe of say 300x, but when used as switch the current gain will be closer to 20x.
In your case, the gain of the TIP120 may well be quoted as 1000 in the datasheet, but don't take that at face-value.
Further down in the datasheet, there's a nice graph:
Untitled.png
Untitled.png (25.47 KiB) Viewed 2061 times
Notice, at the top right, it says Ic=250Ib - that means the manufacturer doesn't expect the gain to be greater than 250!

A nice mental picture: when you put current into a transistor base, lots of electrons enter its emitter, and most of them scootle straight into the collector, dragged by the Vce
If you put more current into the base than is strictly necessary, and Vce is small, those electrons will just hang around in a sort of puddle, waiting to go out of the collector.

So recalculate the base current using about 250 for hfe, and then choose a resistor that will give more than that but less than the current the GPIO can supply.

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

Re: Connect LED's safely (calculate with current)

Wed Oct 15, 2014 11:07 pm

ground_ wrote:Hello everybody,

This week i will finally receive my raspberry PI. I am hyped for it as I can start some projects which I wanted to test out for now, so I am already made an electrical circuit plan on paper, but it didn't take long to get to my first problem (which after puzzling a day I can't solve).

I want to achieve the following:
- Connect a RGB LED strip (12v) to a raspberry pi (based on this: http://mitchtech.net/raspberry-pi-pwm-rgb-led-strip/ );
- Have a single LED parallel to this system (in such a way, that if for some reason the led strip isn't working, the singe LED will not light up. But when the single LED isn't working, the led strip will still work).

Now I made the setup as seen in the attachment but i still have the following questions:
1) how does the current with the gpio ports of the rpi work?
i know basic stuff about the volt, resistance and current. But i just can't figure out how much the gpio port will provide. I read that it is not safe to draw more than 16mA (and a total of 50mA), but does that mean that one gpio port always output 16mA, or need i set that value somewhere.

2) How does it come that the rgb led strip doesn't have an - point?

I got how the tip120 works and why the tip120 is needed, but why does it come that the led strip doesn't have a - point. (as i am writing it i just started to think that the r,g and be point would be the minus point. and by connecting those you led the electricity run through and complete the "circle" )

anayway, thanks in advance!

You need a little bit of bread Board work to do.
You said you know about Volt / Resistance / Current
But do you know how to applie Ohms Law to them
Then you will know how to calculate the right resistance
Do this before connecting to the RPi, When you do a
circuit diagram put your component values in, if you
the forum to check it
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

ground_
Posts: 17
Joined: Tue Oct 14, 2014 6:13 am

Re: Connect LED's safely (calculate with current)

Thu Oct 16, 2014 5:04 am

Yes i know that, i already ordered a breadboard with it ( and multimeter) ;) and i can apply the ohms law ( as wel measuring amps and voltage), as that is one of things i know with electricity.

Return to “Beginners”