How many LEDs can I fade using UNO?

Hi. First of, I´m a total n00b at both Arduino and general programming.
I while ago a friend helped me out with a simple code for fading 6 LEDs in a sort of organic pulse.
Now I have a similar project, but my friend´s not here anymore and I have to ask around elsewhere.
For my new project I want the same organic fading flow, but with more diodes, maybe up to 24.
Is this possible with the UNO somehow? Help in a language I´ll manage is MUCH appreciated :blush:

This is the original 6-LED code:

/* 6LEDorganic*/

int i; // counter variable
float LED[] = {1,1,1,1,1,1}; // pwm brightness variables
float spChg[] = {1.006, 1.004, 1.008, 1.007, 1.005, 1.009}; // speed varialbes to fade LED's - change these for faster or slower fades
// values should be close to and greater than 1
int pwmPins[] = {3,5,6,9,10,11}; // PWM pins - 3,5,6 won't work on Atmega8
int ud[]={1,1,1,1,1,1}; // up - down multiplier

void setup() {
Serial.begin(9600);
}

void loop() {
for (i=0; i<=5; i++){
if (LED > 255){
_ ud = -3;_
* }*
_ else if(LED < 38){
ud = 1;
}
_

_ if (ud == 1){ // up flag, multiply spChg variable
LED = LED * spChg*; // multiply by a fixed amount - spCh array controls the speed of fade*
* }
else*

* { // down flay, divide spChg variable*
LED = LED / spChg*;*
* }*_

analogWrite(pwmPins_, (int)LED*);
delay(1); // this will interact with the spChg variables to control ultimate fade speed*

}
}_

Uno has only 6 analog outputs so you can control only 6, or you can use a shift register or a multiplexer (as far as i know) to control more leds

  1. learn to put code examples into code tags. This makes them much more readable.
  2. If you want more than 20 LEDs you need additional circuits, e.g. multiplexers.
  3. If 20 LEDs are enough for you have a look at my webpage. Everything about cycling and fading LEDs and much more :wink: blog.blinkenlight.net

I am working on a similar project and I am also a nooby (which means my advice is only semi-reliable). See my post Mini Stage Show x 20 [u]http://arduino.cc/forum/index.php/topic,118230.0.html[/u]. I was lucky enough to be given some beautiful code that will allow you to program fades at any length at any time within the 65 second loop that is set by the Arduino uno counter. At the same time you could switch another 7 channels of lights at any time. So 13 channels all operating independently - pretty organic.

With the Uno board you have only 6 channels of PWM fading but of course each channel can switch more than 1 LED. If you wire up additional LEDs in series you can daisy chain more lights to the circuit, but of course all LEDs on the same circuit will all be doing the same fade. However, they could be different colours and placed in different positions in the display, so they would seem different to each other. If you had six fading channels each with 4 LEDs you would have 24 lights.

The problem with this approach will be the power requirements of the lights versus the power output of the Uno board. Depending on the rating of the LEDs you may need to supply an external power source to your lights. In this case the board will not be powering the lights directly, but switching a transistor that allows current to flow from your power source to the lights. Each circuit will need its own transistor that will need to be rated to the power requirements of the combined set of LEDs - and as always each LED will need a resistor.

If this seems too fiddly, and you want more PWM channels, you can buy a bigger Arduino Mega board that will power more lights. But in the end these boards are not designed to pump out a lot of current unassisted.

As far as i know you can only read from multiplexers (potentiometers, sensors) and you cant write to them (turn on-off LED's)
For that you need a shift register

Thanks for replies, though it´s all very complicated for me who´s neveer been into programing. :blush:

UDO: Sorry, I´ll use code tag next time. But yes, 20 LEDs would be enough. And the Blinkenlight will let you controll 20 LEDs individually? I didn´t find any experiment regarding LEDs "glowing at different speeds individually" on your blog. Do you have any ideas, or a code I could work with? I dont mean to be impatient, I just don´t have the time to learn all about coding right now. Thanks /

Tom: Thanks for the reply, seems like a similar idea. I´ve thought about using additional LEDs in series for the increase, but I want them all working their own "glow" so that idea isn´t organic enough for me. Hmm... The arduino Mega can control 15 PWM-channels with a similar code to the original that I was given?

You could use two TLC5940's. That would give you 32 individually controllable PWM outputs.

http://arduino.cc/playground/Learning/TLC5940

Hey kraken, I thought I would try running your code to see what it looks like but my compiler was not happy. In the loop I get the message ISO C++ forbids comparison between pointer and integer. As a novice I have no idea what to do to correct the code, but you might want to check that the code as posted works for you.

Tom-Kristensen:
Hey kraken, I thought I would try running your code to see what it looks like but my compiler was not happy. In the loop I get the message ISO C++ forbids comparison between pointer and integer. As a novice I have no idea what to do to correct the code, but you might want to check that the code as posted works for you.

It's because spChg and LED are arrays and are not being used as such. ud and pwmPins are also declared as arrays.

For example:

LED = LED * spChg;

Should be:

LED[i] = LED[i] * spChg[i];

EDIT:

void loop() { 
 for (i=0; i<=5; i++){
   if (LED[i] > 255){
     ud[i] = -3; 
   } else if(LED[i] < 38){
     ud[i] = 1;   
   }
   
   if (ud[i] == 1){       // up flag, multiply spChg variable
     LED[i] = LED[i] * spChg[i];    // multiply by a fixed amount - spCh array controls the speed of fade
   } else {                     // down flay,  divide spChg variable
     LED[i] = LED[i] / spChg[i]; 
   }
   
   analogWrite(pwmPins[i], (int)LED[i]); 
   delay(1);        // this will interact with the spChg variables to control ultimate fade speed
 }
}

Hey Tom carpenter, nice work. I have my little breadboard up and running with that fix. The LEDs are kind of pulsing, not together but at a similar rate, never fading to zero and seemingly never reaching full brightness. It's nice but...

This sounds like a nice idea... Is this circuit schematic right? I probably need help with the code though.

Tom-Kristensen:
Hey Tom carpenter, nice work. I have my little breadboard up and running with that fix. The LEDs are kind of pulsing, not together but at a similar rate, never fading to zero and seemingly never reaching full brightness. It's nice but...

Yeah, you can probably get a more organic pulse somehow. I don´t mind never reaching zero, but a more "breathing" pulse would be nice ofcourse.

There's always the LED Pixel strings/strips.

As for wiring, it's Ground, 5V or 12V, Data, and Clock. You should use a decent power supply, > 1 amp.
There are full libraries supporting most chips out there (FastSPI is what I use), and that makes communicating with your LEDs a breeze.

My project is an 80x LED clock, 60x on clockface and 4x as quarter marks, and 16x as a pendulum. Rather than concerning myself with hardware that already exists, and is cost-effective (if you consider the parts, assembly time, and re-assembly time ;-), I'd be able to focus on the sketch.

I use LPD6803 based individual pixels, they come pre-wired with about 4" of wire between,
similar to these: 12mm Diffused Thin Digital RGB LED Pixels (Strand of 25) [WS2801] : ID 322 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits
the best thing about these (and all the other PWM controllers) is that they only take up 2 pins on your arduino. The rest of the pins are available, including all interrupts.

I fade seconds and minutes, and the pendulum is continuously "swinging", running through an array of different values. All of the timing for the fades is using 'blink without delay' - which if you are looking to get fades to run at differing times and rates, will be your best friend.

The libraries have excellent examples that you can both tweak for your needs and learn from, enabling you to write your own.

Good luck and have fun - I did.

Thanks for the tip, but I´m also looking for a cheap option... and I want regular diodes, no striped. It sounds interesting though. I think I´ll go with two TLC5940's.

That circuit diagram should work fine. I think there are some examples with the TLC5940 library that I posted a link to which may be of use to you. If you search there Arduino forum there are lots of people using this part so you may also find something useful in one those threads.

Thank you! I´ll look it up as soon as my components arrive.

Btw, if I go with this diagram, I´ll still need resistors for each individual diod, right?

Nope, you only need one as shown in that diagram.
The TLC5940 outputs have a built in constant current source. There is a single resistor connected to IREF (pin 20) which sets the current for all output.

For the TLC5940
Iout = 39.06/Rref

That diagram shows a 2k resistor being used for Rref, so that gives:
Iout = 39.06/2000 = 19.5mA for each pin, which is pretty standard for an LED.

Oh, great... What about that fading SIN wire at the top of the diagram? Is that for additional TLC5940s or something?

SIN is where the serial data goes in to the chip (pin 26).
If you want to use more than one chip then the SOUT (pin 17) would connect to the next chip in line on it's SIN pin.

SIN PIN :astonished:

]:smiley:

I believe that is the Serial out pin of the top TLC5940. It would connect to the Serial in pin of another one if you wanted to use more than two. Essentially they have built in shift registers and you are daisy chaining the shift registers of each IC.