SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By badname
#145094
so i finally decided to learn how to code/build electronics.



i am trying to figure out the best way to do this, as what i am currently doing now isnt working out too well.
this is powered with an arduino nano, got the code all figured out for now, untill i get a microphone so the controller can be sound activated.
the rgb leds i got are common cathode, which it seems right now was a bad move, as they have to be downstream from the transistors.

really i would really like some input on what would be the best way of doing this without using multiplexing. the colors are the same on all leds.
i have the circuit working right now with 9.6 volt supply, but the problem is when the voltage goes down, the leds get dimmer.

basically i have arduino pwm pin > 1k resistor > 2n2222 transistor> 47ohm resisor > 6 leds in parallel(single color)
pretty much that repeated for every 6 leds of one color, so 3 transistors per 6 rgb leds.

my new plan was to rebuild same circuit, but with the power going through a 5 volt regulator, and dropping the supply to 7.2 volts (6 AA cells, would go down to ab out 6volts as batteries die)

any input greatly appreciated

edit: i guess i cant use generic voltage regulators as they wont operate properly below 7 volts, and if i stick with 8 cells (9.6 volts), the regulator will be wasting quite a bit of power(if my understanding of this is correct).
By Duane Degn
#145120
basically i have arduino pwm pin > 1k resistor > 2n2222 transistor> 47ohm resisor > 6 leds in parallel(single color)
Does each LED have it's own resistor? If not, they should. Otherwise more current will go through some LEDs than others and they wont be uniformly bright.

An easy way to do this, which would let you control each LED independently, would be to use a 595 shift register. A 595 chip requires three control lines. These three control lines can in turn control many 595 chips by daisy-chaining the chips together. Each 595 could control eight LEDs so you'd need three of them to control your 6 RGB LEDs.

If you stick with the transistor circuit, don't share a single resistor among multiple LEDs. You'd also want a resistor for each LED if you use a shift register.

How much current do you want the LEDs to receive?

Duane
By badname
#145130
right now i have 1 resistor per 3 leds, the brightness is uniform as far as i can see.
the main problem i have with the circuit is running off a battery due to voltage decrease through the cycle.

at 9.6 volts everything works great (currently using a variable power supply), but as the voltage goes down even .5v they get noticeably dimmer.
this is the main thing i need help with at the moment. As the batteries get depleted, i assume the voltage to go down as far as 8 volts. will be testing this tomorrow.

just to clarify the leds are connected from the emmiter on the transistors, because they are common cathode (so the transistor is sourcing current?). i dont remember exactly but i am dropping about 4 volts across the transistor, so there is only about 5 coming out of the emmiter. does that mean the my transistors are dissipating (4v)x(emmiter current) in heat? that seems quite wasteful. what would be the difference if i had common anode leds and the transistors would sink the current. would it be more efficient to use power transistors so i dont have to have as many of them, or would that be better in some other way?

why would the led brightness be different if the leds are connected to the same resistor?

i will be looking into shift registers, as currently i do not have an understanding of how they control leds.

also i put in 3 rectifier diodes in series to the arduino VIN pin(it was getting pretty warm from 9.6), is this a good practice?

thanks
By rrpilot
#145135
If you want to maintain consistent brightness over a voltage range you need to drive the LEDs with a current source. I had to come up with the following circuit in order to drive some red LEDs over a voltage range of 1.8V to 3.0V (2-AAA cells in series). The circuit uses a current mirror to drive a bunch of LEDs at the same current, each LED operates around 5 mA. Let me know if you're interested and I can explain how it works. You wouldn't necessarily need the weird drive circuitry if you're operating at a higher voltage than I had available to me.
You do not have the required permissions to view the files attached to this post.
By rrpilot
#145136
Note: the circuit I provided can be switched around to source current if required as well but it would use PNP transistors instead of NPN. To answer some of your other questions:
badname wrote:why would the led brightness be different if the leds are connected to the same resistor?
Each LED has a different forward current for the same forward voltage, this is just the reality of the manufacturing process.
By Philba
#145143
I'm not 100% clear on your desired configuration but think you have 6 common cathode RGB LEDs and want to drive each color (6 LEDs) with a single transistor. That makes for 18 LEDs total. Assuming 20 mA per LED, we are talking about 360 mA max. Less if you are are PWMing them. You are right that common cathode isn't the best choice for driving with NPN transistors and you are forced into using them in an emitter follower configuration which has the issues you observed.

Using a 9V battery is bad idea because they have very little capacity. Alkaline typically have ~500 mAHrs (vs 2200 for AAs). So, yes, you will see a fast decline in voltage when you are pulling several hundred mAs. Your AA pack will do much better but you could probably get by with 4 cells. In general, you will have the problem declining voltage and your efficiency is going to be less than 30%. To put it another way, in a 6 AA pack, you are wasting 4 batteries. A constant current approach will work ok but you are still wasting power. I'm not even going into the heat issues.

You could use PNP's (good) or PMOSFETs (better) for control but you still will waste power.

The most efficient way to drive is to use a switcher based LED driver chip but I don't know of any that support CC RGB LEDs (though would love to know of any). Maybe your best bet is to have a buck switcher that outputs something a little (transistor drop + 200 mV?) above your highest Vf. Use a resistor to limit current for each LED (as was explained earlier). This way you will get efficiency at least above 50%, maybe something close to 75%. Doubling your battery life a good thing.

Edit: if you don't want to go with constant current and don't care about efficiency, use a linear regulator (like a LM317 adjustable set to something like 4V), then use resistors to set the current for each LED. This will at least give you constant brightness until the batteries are sucked dry. You could get by with 4 AAs and maybe 3 if you played with the adjustable voltage a bit (you want it as low as possible to have the longest run time).
Last edited by Philba on Tue May 29, 2012 1:16 pm, edited 2 times in total.
By rrpilot
#145144
Is there a specific reason you need to run the supply voltage with 6-AA cells in series? Why not just run 2 in series for a supply voltage of 1.8V to 3.0V? I'm not sure about the AVR chips if they can run on that, but that's what I did for mine and ran the PIC microcontroller straight from the battery voltage. Not much power wasted in driving the LEDs at this voltage either, although I don't think you'll be able to turn on some colors at 1.8V. Just a thought though.
By badname
#145191
awesome info everyone.

i am using AA nimh cells, 2600mah each, the total circuit will have 36 rgb leds, efficiency is really important, and they are going to be on pwm but i would like this to be as bright as possible, will tweak the pwm code to increase efficiency if necessary.

how will using pnps instead of npns be an advantage (will the leds work out to be before the transistor voltage drop?)
from my understanding mosfets have lower collector-emmiter voltage drop, and pmosfet is to mosfet as pnp is to npn?
the choice for the cells is because it all has to fit into a 3/4 inch tube.
i am using an arduino nano, it needs 5 volts, but the spec for the regulated pin is 4v-20v(6-14 recommended).
each cell at full charge is 1.38 volts
By Philba
#145194
PNP is better suited as a high-side driver though you will have to raise the base voltage to what ever the emitter is in order to turn it off. Using a 5V regulator to power the LEDs will make PNPs work. I'm not sure why you say PWM will increase efficiency. It will increase battery life but efficiency won't change.

But, if you don't use some sort of switching regulator, you will suffer poor efficiency. No matter what kind of driver you use. Assuming your NiMH pack is 7.2V nominal and further assuming that your RGBs have Vfs of something like 2.2, 3.2, 3.2, then you are likely to see efficiency of about 40%. With a buck switcher that outputs around 3.7V, you should see efficiency in the 60-70% range. With MOSFET drivers, you could crank the voltage down to something like 3.3V and get even better efficiency. The goal is to waste as little power in your LED current limiting resistors and driver transistors. Remember that power is current times voltage (drop, in the this case). You can't change the current you need for a given brightness level so the less voltage drop, the better.
By Philba
#145207
More thoughts on this. This switcher module would work pretty well for you. It looks falling-off-a-log easy to use. http://www.ti.com/lit/ds/symlink/lmz12001.pdf It could have better than 90% efficiency on the switching conversion for your application. Taking off the losses of the resistors/transistors and you are probably at about 80%. Not bad at all.

That's the good news. The bad news - it costs $10. There is this bob from SF - http://www.sparkfun.com/products/10104 that uses a higher input voltage version of the chip. More bad news, it's $30. You could easily tweak it to output what ever specific voltage you want (change one resistor). But if it gives you 8 hrs of run time vs 4, it might well be worth it.
By rrpilot
#145209
If you're willing to go for the complexity of a switching topology you would be much better off getting one that is specifically designed to drive LEDs. These switchers use a topology that regulates output current rather than voltage. All you need is one that has a PWM input so you can turn it on or off (or anywhere in between), AL8805 from Diodes Inc is one such example. The AL8805 claims 98% efficiency but I wouldn't bank on it being quite that high. Keep in mind though that you still need one of these for each LED. However if you do some more digging, there are LED drivers that allow multiple LEDs in parallel (on separate pins).
By Philba
#145214
The problem for him is that he is using common cathode RGB LEDs. Like I said earlier, the best approach is an LED driver chip but I don't know of any that would work with CC RGB. That's still true.
By rrpilot
#145220
He would need a separate LED driver for each individual LED, other than that I don't know why it wouldn't work. Unless I'm completely missing something??
By Philba
#145223
OK, let's say we got 3 AL8805s and wired them up per the data sheet. Looking at the circuit, the RGB LED elements' cathodes would be connected to all three inductors. Maybe that could work but I'd be surprised. I'm not sure what would happen. Maybe the current through the inductors would be split evenly, thus driving the LEDs to the same current? Of course, you couldn't support strings of them so if it works he will need 108 chips/inductors/caps/resistors.

Now, if he decided to get separate LEDs (36 R, 36 G, 36 B) then it makes total sense to use switcher drivers. though, more than 3, I would bet.