B4: Running Effect of LEDs & B5: Chasing Effect of LEDs

AR-B5: Chasing Effect of LEDs

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

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

Required Material

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

Working

After uploading the code in Arduino UNO board, LED1, LED2, LED3 and LED4 will be ON. Thus all LEDs will be ON in sequence and then all OFF.

The Code

With this code you can create the effect of following each LED with the next LED. It is called chasing effect. It looks very nice during actual working. Upload the following code to get beautiful decorative effect.

 int led1 = 1;
 int led2 = 2;
 int led3 = 3;
 int led4 = 4;
  void setup()
 {
   pinMode(led1,OUTPUT);
   pinMode(led2,OUTPUT);
   pinMode(led3,OUTPUT);
   pinMode(led4,OUTPUT);
 }
 void loop()
 {
   digitalWrite(led1,HIGH); // 1st
   digitalWrite(led2,LOW);
   digitalWrite(led3,LOW);
   digitalWrite(led4,LOW);
   delay(100);
   digitalWrite(led1,HIGH); // 2nd
   digitalWrite(led2,HIGH);
   digitalWrite(led3,LOW);
   digitalWrite(led4,LOW);
   delay(100);
   digitalWrite(led1,HIGH); // 3rd
   digitalWrite(led2,HIGH);
   digitalWrite(led3,HIGH);
   digitalWrite(led4,LOW);
   delay(100);
   digitalWrite(led1,HIGH); // 4th
   digitalWrite(led2,HIGH);
   digitalWrite(led3,HIGH);
   digitalWrite(led4,HIGH);
   delay(100);
   digitalWrite(led1,LOW); // all off
   digitalWrite(led2,LOW);
   digitalWrite(led3,LOW);
   digitalWrite(led4,LOW);
   delay(100);
}


Circuit Diagram

B4: Running Effect of LEDs & B5: Chasing Effect of LEDs
Share on your network!
Prof. Dattaraj Vidyasagar
Prof. Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

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