Go Down

Topic: How many LEDs can I fade using UNO? (Read 5985 times) previous topic - next topic

kraken667

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  :smiley-red:

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
}
}

spoocter

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

udoklein

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 ;) blog.blinkenlight.net
Check out my experiments http://blog.blinkenlight.net

Tom-Kristensen

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 http://arduino.cc/forum/index.php/topic,118230.0.html. 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.


spoocter

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

kraken667

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

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?


Tom Carpenter

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

http://arduino.cc/playground/Learning/TLC5940
https://www.sparkfun.com/products/10136
~Tom~

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.


Tom Carpenter

#8
Aug 18, 2012, 03:10 pm Last Edit: Aug 18, 2012, 03:12 pm by Tom Carpenter Reason: 1

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:
Code: [Select]
LED = LED * spChg;
Should be:
Code: [Select]
LED[i] = LED[i] * spChg[i];

EDIT:
Code: [Select]
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
}
}
~Tom~

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...

kraken667

#10
Aug 18, 2012, 07:45 pm Last Edit: Aug 18, 2012, 07:48 pm by kraken667 Reason: 1

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

http://arduino.cc/playground/Learning/TLC5940
https://www.sparkfun.com/products/10136


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


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.

GoolGaul

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:  http://www.adafruit.com/products/322
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.

kraken667

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.

Tom Carpenter

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.
~Tom~

kraken667

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

Go Up