RGB Leds blinking in sequence first project. Am I on the right track?

Hello, Because this is my first post, first a little intro and after that, my question. Since a few week I joined the wonderful world of Arduino. (I love the little stickersheet that comes with it) I came to know about the Arduino, when i did read a story about a DIY Ambilight for your computer. After reading that story, I became enthousiast and started reading about Arduino. After reading examples, projects etc. I became more and more enthousiast and decidet to step in to the world of Arduino. I have a few goals (projects) in mind like the ambilight, rgb-led-cube, weatherstation and my ultimate goal a like the mars-mission-rover-robot who also can talk. But in order to get those kind of projects working, there are some basics to learn. (In my case a lot i guess :-) )

So after following a few tutorials I did try to make my own first little project, instead of letting 1 led blink I wanted to make 4 RGB Leds blink in sequence looping through the colors. I layed the following out on my breadboard:

And i edit the blink example code in this:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT); 
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT); 
  pinMode(4, OUTPUT); 
  pinMode(5, OUTPUT); 
  pinMode(6, OUTPUT); 
  pinMode(7, OUTPUT); 
  pinMode(8, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(11, OUTPUT); 
}

void loop() {
  digitalWrite(0, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(0, LOW);    // set the LED off
  delay(1000);              // wait for a second
  digitalWrite(1, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(1, LOW);    // set the LED off
  delay(1000);              // wait for a second
  digitalWrite(2, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(2, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(3, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(3, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(4, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(4, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(5, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(5, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(6, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(6, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(7, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(7, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(8, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(8, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(9, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(9, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(10, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(10, LOW);    // set the LED off
  delay(1000);              // wait for a second 
  digitalWrite(11, HIGH);   // set the LED on
  delay(1000);              // wait for a second 
  digitalWrite(11, LOW);    // set the LED off
  delay(1000);              // wait for a second 
}

When I did run the program, it suprised me that all leds where on, every color, so they turned white (that's normal) Than everything worked as what i did have in mind. Led by Led, looping through the colors. So after this experiment I have a few questions:

Did I layout a correct schematic? (the wiring)

I used one resistor (1K Ohm) on the +3,3v is that enough? / correct?

I asume that the reason why all the Leds where on at first, is because I used the +3v.v and not the ground pin?

On the programming part: I understand, this peace of coding could be done in a more effective way, like replacing delay(1000) with delay(TIME) placing the delay(TIME)=1000 with the int statement in the setup?

I do have some more questions, but I think for the moment this is enough. With asking these questions I'm hoping to find out, if i am on the "right" track, that my way of thinking is correct. Thanks for now!

M

You need a resistor per LED, not the whole shebang like you have now. If these are common anode LEDS, you need to put the resistor on each anode leg and then wire them to GND, not the 3V3 pin.

And with that many, while it's perfectly fine to do what you did, you might want to look into at the TLC5940 to drive the LEDs. Look at http://www.arduino.cc/playground/Learning/TLC5940 for more information.

Yeah, all the LEDs were on because you had them connected to 3.3V... meaning that no matter whether you have a HIGH or LOW on the pins, because a HIGH is 5V and a LOW is 0V, you are always going to get a potential drop across the LED, and thus a flow of current.

1k won't break the LEDs, since 5-3.3V/1k = 1.7mA... though given that this is spread across so many LEDs, I'm surprised it was bright enough to see.

Drop the Resistor value to something like 100ohm, and connect the orange lead to ground. Or you could do what KirAsh said... use a resistor on each LED Anode connected to ground. Probably something like 100ohm each should be okay.

EDIT: Actually, disregard my advice... after giving it thought, I think may have oversimplified the problem in trying to do it in my head.

Thank you both for your reply. I rewired it using your tips and it runs fine. Thank you also for pointing me out at the TLC5490. Going to purchase a few of them to use with RGB LEDS. (I have 200 RGB LEDS to play with and 5 meter RGB Ledstrip (300 leds). I also have 4 x ULN2003A for powerconsumption. For first experimenting I also have a Rainbowduino with Leds. You almost would think I like LEDs :-) Thanks again, time for a few other tutorials!

M

LukeTimothy: Drop the Resistor value to something like 100ohm, and connect the orange lead to ground. Or you could do what KirAsh said...

As KirAsh said, you need to provide a separate current-limiting series resister for each LED. LEDs won't spontaneously balance the current between themselves in the way that ordinary incandescent lamps do, so even with the LEDs wired in parallel you'd find that all your current went through one LED, which would then burn out.

Thanks! For pointing me out for what the reason is, you have to use a resistor for every Led and it makes perfect sense to me. I really like doing things the Arduino way, it's a way I understand.

M.

And to explain why everything turns on when you first plug it in, before the program starts running, is because of how it's wired. By default, when an Arduino board comes on, all of its pins are INPUT pins. Since you have them wired to 3V3, as soon as you plug the board in, everything comes on as those pins are sinking current.

Once you wire the LEDs with their own resistors and connected to ground, you will notice it behaves different ... the correct way.