Introduction: Constant Current LED (Arduino)
You probably have had that problem. You want to put lots of LED's on an output, but you don't really know how...
Avery simple solution may be that you put all your LED's parallel to each another. Then, you calculate the resistor of them, and of you go. Or, if your Voltage is high enough, you can put some in series.
In the second image, I did show those possibilities in a little schematic.
It works, yes it does.
Until... you want to put different colours in one line. Or different sizes, or...
Then those simple serial and parallel bits might cause some problems...
Step 1: Calculating LEDs.
In this schematic, the serial and parallel one, there are different values for resistors.
For those who struggle: how to calculate them.
Most (normal 5mm) LEDs are very happy with 30mA currents.
Let's say the Forward voltage of the LEDs is 1.7 Volts. (Vled)
In the serial example, we take our Vcc, the voltage we get from our power supply (or battery, or...), subtract the Vled from it, and divide that by the current of the LED (30mA or 0.03 A)
In our case it gives us: (9V-1.7V)/0.03 A= 273.3333 Ohm. I use the 5% range of resistors (E12 range), so I take the closest value that is LARGER then the one I calculate, in this case: 330 Ohm.
In parallel, we have 3 LEDs, thus we have (9V-5.1V)/0.03 A= 130 Ohm. Again the closest value= 150 Ohm.
But hang on a sec...
We use a constant for the current... It is always 30mA!
What if we make a small circuit that provides us those 30mA, and at least our 1.7V (plus some more)? Would be quite easy... We put no matter how many LEDs in serial or parallel, and feed them their 30mA.
Step 2: Constant Current
This is the Constant Current schematic. It works quite simple: the current flowing from the Vcc through the transistor Q1 is limited by the value of R2. In such a way, that, if we would put a current meter in the Vcc line to the transistor (very low input resistance), it wouldn't blow, but it would show the current we calculate for R2.
If we would use only 1 LED, the tension over the LED would be 1.7V, with 2 LEDs, it would be 3.4, and so on. So the number of LEDs you can use in this circuit, depends on the Vcc you use.
How does this circuit works?
We give an input on R1, lets say from an Arduino-pin. Q1 conducts, which means there is a current flowing from the collector to the emitter. If the current exceeds a certain value through R2, Q2's base gets more positive, and it slowly starts to "steal" from the base of Q1. The higher the current that is drawn from the load (in our example the LEDs), the harder Q2 starts to steal the tension (Vbe) of Q1. Q1 starts to be less conductive, so the current through our LEDs is limited.
And simple: how to calculate R2, the one that configures our circuit?
Very simple... Ohm's law say that R = V/I. V is the offset voltage of the transistor Q2, and for most silicon transistors (there are still germanium transistors... But these are used for amplification of very weak signals) Vbe = 0.7V
So our resistors' value = 0.7v / current we want.
If we want 30mA, we have R2 to be 22 Ohm. (22R).
You can use this circuit everywhere, The only thing you have to watch out for, is the maximum current and maximum voltage for the transistors you use. And... When you want to make this circuit to deliver 5A, that is possible, with the right transistors. But also take care about the dissipated power of the resistor.
Step 3: Expanding It.
Hang on a second...
Since our constant current circuit has an ON/OFF input, we might also use that input for "fast switching". In other words: we could use it for PWM, and in that case, we can use it for dimming LEDs!
So... I made a little pcb.
For this one I used our current circuit, used it 8 times.
I used pins 3,4,5,6,8,9,10,11 as inputs, so it is compatible with Arduino UNO and Arduino MEGA, both boards which I use a lot.
An extra connector for external power with his accompanying LED finishes the board. Of course the groundpin of the external power is connected with the Arduino GND.
Step 4: Putting It All Together.
And this is how it looks like.
When using one of the outputs, you connect the negative (in this case of the LED) to one of the first 8 screw-connections (I do make my own English terminology, as you probably see), and the positive to the ones on the right side, the positive of the external power supply.
The particular transistor I used here, is quite common, fast switching. It can be used for a Vce (collector-emitter voltage), thus the max external power input of 60V, and has a maximum dissipation of 1W.
That means, in the case where we use them for a 30mA constant current source, we can apply 1W/30ma= 33V maximum as our external power supply.
I hope you like this little instructable!
Participated in the
Arduino All The Things! Contest
7 years ago
It's not advised to put leds in parallel and only one resistor to limit current through the entire branch. It can so happen that one of the leds will switch on a fraction of a second sooner than the others and the entire current that was supposed to be divided into all the branches will flow through this one led and either blow it or considerably reduce its life. Say you put a resistor to send 150 mA through the loop which will be divided into 5 branches for 5 leds giving each 30mA.. But if one of them switches on slightly sooner 150mA flows through that one led.
Reply 7 years ago
150mA for "a fraction of a second" won't really hurt an LED and besides the capacity of the LEDs, which won't make any noticeable difference between the LEDs turning on (nanoseconds or low numbers of microseconds), I don't see why they shouldn't turn on concurrently.
The reason NOT to run them in parallel, is due to their slight differences in voltage drop (and hence current), which will (over time) weaken some of them more than others - like in cheap multi-LED flashlights with a single resistor feeding a parallel LED setup - they usually go sour in a short while.
LED's from the same batch are close enough in voltage drop, that I occasionally run them in two's, like a 6-LED laptop lamp I made today with 3 pairs each with 2 LEDs and a 47 Ohm resistor for 40mA into two LEDs - Yay, now I can see my keyboard at night :)
Reply 7 years ago
True, Tehemton, that's why I work with the Constant Current circuit.