I think it is better for you to use transistors or a driver I.C. such as a ULN2003 instead of driving the LEDs directly from the Pi, so you don't have to worry about drawing too much current from it. Your circuit with transistors looks allright. I would just lower the base resistors a bit so you guarantee the transistors will be saturated when turned on. To guarantee saturation for any transistor a good rule of thumb is to use a base current around 10% of the desired collector current, so if you have Ic=30mA
then Ib=3mA
. That way, according to ohm's law, Rb
should be:
Rb=(3.3-0.7)/0.003=886.66 ohms
.
If you choose a 1K resistor you should do fine, as it will yield a base current of
(3.3-0.7)/1000 = 2.6mA
.
which is well in the allowed range for the Pi
outputs.
EDIT:
Why force transistor to operate into saturation? To avoid beta
variability. It is well known the beta
parameter can vary in a wide range from transistor to transistor, and with temperature as well. A transistor will be saturated when both its PN junctions are forward-biased, and the effect of this is that its collector current won't rise anymore when its base current rises. See this for some reference about transistor operating regions. I find it easier to understand this when you look at the transistor characteristic curves for its collector circuit, like shown here. Based on that figure, note that when Ib
rises (each blue curve is for a specific base current), the transistor operating point (intersection of the red line with the blue line corresponding to your actual base current) will be getting more and more to the left, to a point where even if you use a higher Ib
curve the operating point can't go up-left anymore, keeping Ic
essentially constant.
When you have enough base current to be on that point, there's no need to increase it anymore, and that rule of thumb of making Ib
10% of Ic
is just a generalization so you saturate any transistor, irrespective of their expected beta
range. Of course, if you know the minimum beta
of a given transistor family you could use smaller Ib
than 10% of Ic
, but that is just to be on the "always right" for any transistor.
beta
value, since it is a parameter that can vary greatly from one transistor to another, even ones from the same manufacturing batch. That means you can't guarantee you will get that exact current with another transistor, and this is why it is better to force the transistor to operate in the saturation region, wherebeta
variability won't be an issue. – Claudio Aug 28 '13 at 12:37