Need advice on Common Anode RGB Led and Transistor

Hi All,

Im slowly and surely learning electronics and c programming, and ive hit a stumbling block while planing my first real-life project.

I have an arduino + wifi + Common anode RGB leds

i want to wire a strip of 20 RGB leds together so that i can add mood lighting behind coving) to a new tv installation .

I am figuring out best way to wire the leds up and how to drive the current drawn by 20leds and where to use resistors.

Now ive come to the conclusion i will need a transistor for each color, and i will send a pwm output to the corresponding tranny for colour brightness. Is this best way to go?

Next, if using my idea, if i wire the common anodes to a 5v rail, then each colour to a rail from its correspsonding transistor emitter, will this work. Im new to transistors and wondering how i would "pull down" the line to light the led up. Would i use a NPN and the more current i apply at the Base, the dimmer the colour? so to have the LED off i would apply full power to the Tranny?

I hope this makes sense and hope someone can help me help myself

Good question. I'm giving you a very rough answer here.

Basically a transistor can be used as a switch where its off (also called cutoff) and fully on (also called saturation). It can also be used as a variable resistor that can be varied between off and on (also sometimes called active or linear mode). Its not really a true variable resistor for various reasons. What you want to do is use it in saturation mode.

The current gain specified as Hfe or sometimes beta gives you an indication of what the collector current should be in relation to the base current. In other words you multiply the base current by the Hfe (or beta) value and you have the collector current ( this is where the ability of a transistor to "amplify" is apparent). This works when the transistor is in active mode.

If you apply a big enough base current you effectively reduce the "resistance" of the transistor to zero, bringing it close to a short circuit. This is called saturation when the transistor acts like a closed switch.

You can think of it as the collector current being made to reach its maximum limit. This current depends on the resistance of the circuit in which the collector and emitter are in.

The higher the resistance the more base current required to drive the transistor into saturation and vice versa.

What you can do is tie the anodes to +5V and then put a resistor between the cathode and the collector of an NPN. Then ground the emitter and hook up the base to the output through a resistor.

The higher the resistor the less base current needed. The lower the resistor the more base current drive needed.

Remember the outputs can only output a few tens of milliamps. Since the Led only needs like 10-20ma usually your base current is then usually in the microamp range, needing a fairly large resistor. As a rough approximation the base resistor can be the output voltage of the Arduino which is 5V minus 0.7 volts(voltage across base emitter needed to turn transistor on) all divided by the base current

Rbase = 4.3/base current

Since base current = collector current / hfe

Using estimates ( usualy Hfe is close to 100) I can say

base current = 20ma/100 = 200microamps

This gives an Rbase of approximately 22K.

Make it 10K just as a good margin.

Since base current is

Its best to play around but be careful.

I did a google search now for "driving led with transistor" heres a link to the second result I got which showed something similar to what I said. I didnt bother reading through it though, maybe it explains it better than my wobbly explanation