B3: Alternate Blinking LEDs

AR-B3: Alternate Blinking LEDs

This entry is part 3 of 13 in the series Arduino Basic Circuits

In this code we use 2 LEDs connected on breadboard with 2 resistors of 1kΩ. This code produces the effect of alternately blinking of the 2 LEDs.

Required Material

Arduino UNO Board – 1, data cable – 1, Red LEDs – 2, Jumper wires – 3, 1kΩ resistor (Brown Black Red) – 2.

Working

After uploading the code in Arduino UNO board, the LED1 and LED2 will be ON alternately. This happens because of alternate action written in the code.

The Code

This code is very interesting which glows two LEDs in a group simultaneously. When you upload the code in Arduino UNO you get a pleasant decorative effect of 4 LEDs.

int led1 = 1;
int led2 = 2;
 
void setup()
{
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
}

void loop()
{
  digitalWrite(led1,HIGH); 
  digitalWrite(led2,LOW);
  delay(100);
  
  digitalWrite(led1,LOW);
  digitalWrite(led2,HIGH);
  delay(100);
}


Procedure & Precautions

  1. First type the code correctly in Arduino IDE software.
  2. Then connect the Arduino board to computer through data cable and click on “Tools” menu.
  3. Then select “Arduino board” and respective “COM” Port.
  4. The upload the code in Arduino UNO board.
  5. Observe that the two LEDs – LED1 and LED2 will be ON alternately, at a rate decided by your delay() function value.
  6. Thus the circuit produces decorative effect of the two LEDs.

Circuit Diagram

B3: Alternate Blinking LEDs
Share on your network!
Yash Vidyasagar
Yash Vidyasagar

Professor in Department of CS, Fergusson College, Pune. Researcher in Embedded Systems, Expert in Online/Offline Education, Creator of lots of projects for community solutions... ➤➤

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x