-6

I am very much new to Arduino. I recently bought an adruino uno. i can blink an LED alternately. Such as, 1st blink red, then blink green, then blue like that. once only one LED should blink.

I have provided the code blinking an LED. How to modify this to blink multiple LED one after another.

void setup() {

  pinMode(13, OUTPUT);

}

void loop() {

  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
} 
  • Could you please provide some more details? What are you trying to do? What have you tried so far? Are you trying to control multiple LEDs? – Avamander Sep 4 '15 at 15:19
  • Most newbie problems involve more than code. The problem often lies in the wiring. Please give us some information about your wiring. – Ariser Sep 4 '15 at 17:17
  • i have provided code of blinking one LED. now i just want to blink multiple LED one after another. alternately. – user3099225 Sep 4 '15 at 18:05
  • Who flagged this a "unclear what you are asking"? It's clear. He wants to blink 3 LEDs in sequence. – Nick Gammon Sep 4 '15 at 21:31
  • yes @NickGammon – user3099225 Sep 7 '15 at 11:16
3

You could always copy and paste:

void setup() {

  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

}

void loop() {

  digitalWrite(11, HIGH);
  delay(1000);
  digitalWrite(11, LOW);
  delay(1000);

  digitalWrite(12, HIGH);
  delay(1000);
  digitalWrite(12, LOW);
  delay(1000);

  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
} 

A bit better would be to learn about functions:

void setup() {

  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

}

void blink (const byte which)
  {
  digitalWrite(which, HIGH);
  delay(1000);
  digitalWrite(which, LOW);
  delay(1000);
  }  // end of blink

void loop() {
  blink (11);
  blink (12);
  blink (13);
} 

And you could learn about loops:

void setup() {
  for (int i = 11; i <= 13; i++)
    pinMode(i, OUTPUT);
}

void blink (const byte which)
  {
  digitalWrite(which, HIGH);
  delay(1000);
  digitalWrite(which, LOW);
  delay(1000);
  }  // end of blink

void loop() {
  for (int i = 11; i <= 13; i++)
     blink (i);
} 

There is a whole world of stuff to learn. Enjoy the process!

0

Have you considered connecting another LED and turning one on and the other off sequentially?

void setup() {

  pinMode(13, OUTPUT);
  pinmode(NewLEDPin, OUTPUT);

}

void loop() {
  digitalWrite(NewLEDPin,LOW);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(NewLEDPin,HIGH);
  digitalWrite(13, LOW);
  delay(1000);
} 
  • i'll try , but what is it "NewLEDPin" ,,, there is no PIn no .. – user3099225 Sep 7 '15 at 11:27
  • @user3099225 look, there are two parts to any program, the software and the hardware. The software is in front of you, and the hardware is for you to set up. Connect another led to the board in a similar manner to the way your first led us connected and replace "NewLEDPin" with the pin that the led is connected to – DividedByZero Sep 7 '15 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.