40 bright fading multiple LEDs array


I am trying to figure out how to develop my next project. I need 40 white leds to fade in and out using different speeds. I have used different types of arduino before but I can't find anything about how to interface this big number of leds. What would I need?

Thanks a lot in advance.

For the simplest method, you would need an Arduino Mega, 40 LEDs, 40 resistors, and some (a little) port manipulation.

You could do it with a Arduino Uno/Duemilanove/whatever else is based on the ATmega328P if you wanted, but the circuitry would be more complex. And you'd need to multiplex more, which tends to be a more significant programming task. If you want to do that, you'll also need a few transistors.

Too many bright leds attached directly to the micro-controller may cause a current high enough to ruin the microcontroller chip. It may be wise not to let more as 20-30 mA flow per pin and a maximum of less then 200 mA for the total chip.

A shift-register with pwm-possibilities like the TLC5940 is probably nice. One can control 16 leds and it uses no more as 5 pins from the arduino. Since you can daisy chain 'm you can add as much TLCs as you like, all driven by the same 5 pins.


Thanks a lot.

I've got an arduino mega to use, so I wouldn't need to overcomplicate the circuit. I am happy to go for the simplest method, but would it be possible with really bright leds? Have you tried? I was looking into these: http://www.sparkfun.com/products/9850 (20mA, 3.2 V), would they be alright?

About the TLC5940 option, I am not entirely sure I understood everything. Will I have to do this for sure? 200mA will be just 10 leds... If i really need to use this, I guess I will need at least two of them to get 32 leds. How does the daisy chain works? Will the coding get much more complex? I could use 10 pin for two TLC5940, would that change anything? Please tell me a bit more about this, as I've never done it before

thanks again!!

Just to solve a current limit issue the easiest way uln2003. The same time tlc5940 will save 40 resistors and wiring, look in playground/output or: http://tronixstuff.wordpress.com/2010/07/19/review-–-texas-instruments-tlc5940-16-channel-led-driver ic/

You've got several possibilities.

1. Drive all leds directly using quite large resistors. Should you want to turn on all leds at full capacity at the same time in your program, normally 40x20mA will flow. That's too much. By using larger resistors you can limit the current to less then 5 mA per led resulting in less then 40x5mA when software turns on all leds at the same time. You'll probably still see a lot of light, but not as bright as possible.

2. You could... also drive them normally, but you'll have to be very sure your programm doesn't turn on too many leds at the same time. With 800mA flowing, the possibility of smelling magic smoke is quite high. 1 mistake while writing/testing the program can be enough to need a new Mega. Internally the mega uses different ports up to 8 pins per port, you'll also need to check the datasheet to see what a port can handle max.

3. An option I didn't think of yesterday is using transistors. The right ones can handle more current and they hardly put a strain on the Mega. A chip like the ULN2003 houses 7 transistors, so 6 chips would be enough to drive all leds at full capacity at the same time. Its relative the 2803 houses 8, requiring 5 of 'm.

With 40 leds there's one disadvantage using the options above. For fading you'll need PWM. The mega has 14 PWM pins by itself which can easily be controlled by the analogWrite()-function. Other pins can... be used as PWM pins too, but you'll need to write software/use a library to make that possible. You'll need to manipulate ports/pins as Aeturnalus wrote.

An example can be found at http://arduino.cc/playground/Main/PWMallPins

4. A TLC5940 has 16 outputpins and has a PWM-function for each pin. In the example 5 pins are needed to control the chip. 4 of those are used to make sure the transmission of data is done correctly while the remaining one actually is used to transmit the data needed.

Besides having that 1 input pin for data... the chip also has an output pin which makes it possible to daisychain 'm. That pin can be connected to the input pin of the next TLC5940 (which also has an output pin). Although the comparison isn't correct the combination input/output pin makes it possible to use the chip like domino-blocks. By tumbling the first block of 16 all will fall down and by placing another block of 16 behind it, it's possible to let them fall as well by tumbling the first block of the first set. Domino is too simple since all blocks will fall, you can't command one to stay up and the next to fall, something you (more or less) can with a shift register.

The other 4 signals of the second (third/fourth/etc) chip behave exactly the same as those on the first. By connecting each individual pin of those 4 to the same pin on the second/third/... chip, each chip can be controlled and each outputpin can be set to the fade-value you need using just 5 pins of the arduino. There probably will be a limit to the amount of chips you can control this way, but it wouldn't surprise me it's higher as 15-20.

There are a few libraries to drive the chip, it isn't the simplest shift register though. If you would like to experiment with shiftregisters, the 74hc595 is probably one of the easiest to control, but has no PWM-possibilities by itself.

  1. There's much available, it wouldn't surprise me if there are for example chips available controlled by I2C/other protocols that also are intended to create PWM-signals.

it wouldn't surprise me if there are for example chips available controlled by I2C

So the PCA9685 16-channel, 12-bit PWM Fm+ I2C-bus LED controller will come as no surprise.


it wouldn't surprise me if there are for example chips available controlled by I2C

So the PCA9685 16-channel, 12-bit PWM Fm+ I2C-bus LED controller will come as no surprise.

That's changing my words, but looking at the sheet it sounds like a good one.

What's this PCA9685? A controller? A chip? Can't find much online.. have you used it?


also thanks a lot Simpson_Jr.. i am gonna read everything slowly trying to get everything right! : )

What's this PCA9685?

It controls LEDs, it is a chip.

Can't find much online

?? top hit for this is the data sheet, there is not a lot more to know than the data sheet.

have you used it


Couldn't find any place where to buy it, I got it on farnell now (http://uk.farnell.com/nxp/pca9685pw/ic-led-driver-rgba-28-tssop/dp/1854074?Ntt=PCA9685). Seems quite cool even if I am not sure wether I'll be able to program something for it, as the datasheet doesn't say much to me.. : (

I would be really interested in understanding more about it as it cost less then the TLC5940.. but as I said I am not sure I know enough..

thanks again to everyone, really appreciate this!

I received both the PCA9685 and the TLC5940, but the first one is def too small for my soldering skills.. i mean it's really fucking tiny, maybe i got the wrong model or something, it looks more to be used on preprinted circuits or similars.

So, following the TLC5940 way as suggest on here: http://tronixstuff.wordpress.com/2010/07/19/review-%E2%80%93-texas-instruments-tlc5940-16-channel-led-driver%C2%A0ic/ I was wondering if, in your opinion, there would be any difference between the leds array they use and the one that I am gonna buy (super bright from sparkfun, 20mA)

thanks to everyone!!

maybe i got the wrong model or something,

No that's the only one they do. It's a surface mount type. I am thinking about getting a few breakout board PCBs made as there might be some demand for this chip and it is hard to work with without some sort of PCB.

If you post a link to the one you are going to buy we could see. But basically if you can get at the individual cathodes and it is 2mA then it should be fine.

Yes I like the PCB idea, let me know I might be interested in doing that together.

What do you mean for getting individual cathodes? I ordered this ones: http://www.sparkfun.com/products/9850

Yes that LED looks fine.

What do you mean for getting individual cathodes?

Some multiple LEDs are common cathode, you can't use those with that chip.

The leds in the Led-bar shown in the first videos probably isn't as bright as the ones you ordered, but that should be no problem.

Several Led-packages exist of multiple leds which can have a common Cathode (-) or a common Anode (+). With a common anode-package you basically attach the common pin to a positive voltage and... turn individual leds on by connecting their specific pins to a negative voltage. With a common Cathode it's the other way around. In your case you're using single leds, each has its own Cathode and Anode, so you could connect them as you want.

It's always good to know what you're ordering, lots of components are available in different packages. By looking at your post you've bought the TSSOP (rectangular)-version which indeed can be tricky to solder. The HVQFN (Square package) version of the PCA9685 is even a lot smaller. Luckily breakout-boards exist.

Most Surface Mount Devices (SMD) are quite small and loads(&loads) of different SMD-packages are available for all kinds of components. If you want the the easiest package to solder, it's best to check whether a chip is available in a Dual In line Package or DIP. The data sheet should tell you which packages are available for a component. THT (Through Hole Technology) is also a term often used to describe "old" larger components with long pins including DIPs.

Cool, thanks a lot for your lessons guys! I am learning so much!

Anyway as my leds are just as single I think I am just going to follow this design: http://students.washington.edu/acleone/codes/tlc5940arduino/img/breadboard-arduino-tlc5940_close.png having all the plus together (as a common anode?) and using the negative voltage to control them. Right?

I will start with one and add the second… I will need an external power supply right? Will 9 Volts be enough?


Will 9 Volts be enough?

It's not the voltage it is the current. You are best with just 5V because in that way the TLC5940 doesn't have to burn the excess voltage off as heat.

Ok, I received everything and I did the first basic tests using the examples from the library (http://code.google.com/p/tlc5940arduino/).. it looks great! But now I have to understand how to make it do what I need. Basically I was thinking to define one basic function that could like like this: http://classes.kumc.edu/sah/resources/sensory_processing/images/bell_curve.gif (just to give an example) and then having each led behaving differently. Still using the same kind of function but changing the speed.. so that the final effect will be a series of different fading in and out depending on my tempo variable.

Do you know how to get started for this? The library seems a bit hard! Thanks again for supporting my silly questions..