Lab set Program-1

Develop a program to blink 5 LEDs back and forth.

Objective

To write an Arduino program that makes 5 LEDs blink one after the other in a back-and-forth pattern, creating a "chasing light" effect.


Learning Outcomes

By the end of this experiment, students will be able to:

  • Connect multiple LEDs to Arduino digital pins.

  • Control LEDs sequentially using for loops.

  • Understand the concept of array indexing for repetitive tasks.

  • Apply logic to reverse direction (back-and-forth movement).


Components (from Tinkercad Palette)

  • Arduino Uno board

  • Breadboard

  • 5 LEDs (any color)

  • 5 Resistors (220Ω each)

  • Jumper wires

  • USB cable


Circuit Wiring

  1. Connect 5 LEDs in a row on the breadboard.

  2. Connect each LED anode (+, long leg) to Arduino digital pins 2, 3, 4, 5, 6 (through a resistor).

  3. Connect all LED cathodes (-, short leg) to Arduino GND.

  4. Power Arduino using USB.

(In Tinkercad, drag 5 LEDs, align resistors, and connect them as shown below.)


Step-by-Step in Tinkercad

  1. Open Tinkercad Circuits.

  2. Create a new circuit.

  3. Place Arduino Uno and a breadboard.

  4. Place 5 LEDs in a row.

  5. Connect each LED’s anode to pins 2–6 through resistors.

  6. Connect cathodes to GND.

  7. Paste the code below into the Arduino editor.

  8. Start simulation → Observe LEDs blinking back and forth.


Arduino Program

// Blink 5 LEDs back and forth
int leds[] = {2, 3, 4, 5, 6};   // LED pins
int numLeds = 5;

void setup() {
  for (int i = 0; i < numLeds; i++) {
    pinMode(leds[i], OUTPUT);
  }
}

void loop() {
  // Forward direction
  for (int i = 0; i < numLeds; i++) {
    digitalWrite(leds[i], HIGH);
    delay(200);
    digitalWrite(leds[i], LOW);
  }
  // Backward direction
  for (int i = numLeds - 2; i > 0; i--) {
    digitalWrite(leds[i], HIGH);
    delay(200);
    digitalWrite(leds[i], LOW);
  }
}

How It Works 

  • The LED pins are stored in an array.

  • In the first for loop, LEDs turn on one by one from left to right, then turn off.

  • In the second for loop, LEDs light up from right to left.

  • The loops repeat endlessly, creating the back-and-forth “chaser” effect.


Common Mistakes & Quick Fixes

  • LED not glowing → Check polarity (long leg = anode).

  • All LEDs glow dimly → Missing resistors (always use 220Ω).

  • Wrong pin numbers → Verify array matches your wiring.

  • Too fast / too slow → Adjust delay(200) value.


Viva / Check-Your-Understanding

  1. Why do we use resistors with LEDs?

  2. What is the role of an array in this program?

  3. How would the circuit change if we used pin 13 instead of pin 2?

  4. Can we make LEDs glow without using delay()? (Hint: millis() function)


Extensions (Mini-Tasks)

  • Add more LEDs (e.g., 8) for a longer chasing pattern.

  • Change delay dynamically using a potentiometer.

  • Make two LEDs chase each other in opposite directions.

  • Try random blinking instead of sequence.


Lab Record 

  1. Experiment Title

  2. Objective

  3. Circuit Diagram

  4. Components Required

  5. Program Code

  6. Output 


Thinkercad Link:

https://www.tinkercad.com/things/2sZP93En56X-labset-prog-1

Comments

Popular posts from this blog