Blink LEDs in stack form using Arduino

To blink LEDs in stack form using arduino we first know about stack. Stack is a data structure in which data can be add or remove at only one end called the TOP
Examples of Stack are :
– Stacks of books
– Stack of tray in cafeteria

 

BLINK LEDS IN STACK FORM USING ARDUINO
Books stack

Suppose we have 8 books start keeping books one by one at the top of each other. After placing books take books one by one starting from the top, the book placed by us at the last we will get it first, continuing the process the books placed at first by us we will get it on last, This is stack (LIFO – Last in First out).

Required hardware or components for Lighting up LED in Stack form using Arduino

S.N.ComponentQuantity
1.Arduino Uno1
2.Breadboard1
3.LED4
4.Resistor 220 or 280 ohm4

CIRCUIT DIAGRAM : BLINK LEDS IN STACK FORM USING ARDUINO

Circuit diagram Arduino and many led's
Circuit diagram Arduino and many LEDs

CONNECTION TABLE

S.N.ArduinoLED
1.GNDCathode (-)
2.2LED 1 - Anode (+)
3.3LED 2 - Anode (+)
4.4LED 3 - Anode (+)
5.5LED 4 - Anode (+)

ARDUINO CODE : BLINK LEDS IN STACK FORM USING ARDUINO

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  digitalWrite(2, HIGH);
  delay(500);
  digitalWrite(3, HIGH);
  delay(500);
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(5, HIGH);
  delay(500);
  digitalWrite(5, LOW);
  delay(500);
  digitalWrite(4, LOW);
  delay(500);
  digitalWrite(3, LOW);
  delay(500);
  digitalWrite(2, LOW);
  delay(500);
}

CODE EXPLANATION

Step-1: 

In setup() block we assign pin number 2, 3, 4 & 5 of Arduino as output.

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

Step-2:

In the loop() block, in the first half we first want to turn ON led connected on pin number 2 and then 3, 4 & 5 with a delay of 0.5 seconds (500 milliseconds) to each.

void loop() {
  digitalWrite(2, HIGH);
  delay(500);
  digitalWrite(3, HIGH);
  delay(500);
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(5, HIGH);
  delay(500);

Step-3: 

In the second half, we want to turn OFF the led connected on pin number 5 and then 4, 3, and at last 2 with a delay of 0.5 seconds (500 milliseconds) to each.

  digitalWrite(5, LOW);
  delay(500);
  digitalWrite(4, LOW);
  delay(500);
  digitalWrite(3, LOW);
  delay(500);
  digitalWrite(2, LOW);
  delay(500);
}

And the void loop() gets executed continuously and follows the same pattern. 


READ NEXT
BLINK LED’S IN AN ORDER USING ARDUINO


 

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x