Mission 04 · Stage 1

LED Chaser

loop index drives a moving pattern

Light one segment at a time on a bar graph using a loop index.

LED Chaser circuit diagram

Pin connections

Part 1Part 2

LED bar graph

A1

→

Breadboard

12t e

LED bar graph

C1

→

Breadboard

12b h

LED bar graph

A2

→

Breadboard

13t e

LED bar graph

C2

→

Breadboard

13b h

LED bar graph

A3

→

Breadboard

14t e

LED bar graph

C3

→

Breadboard

14b h

LED bar graph

A4

→

Breadboard

15t e

LED bar graph

C4

→

Breadboard

15b h

LED bar graph

A5

→

Breadboard

16t e

LED bar graph

C5

→

Breadboard

16b h

LED bar graph

A6

→

Breadboard

17t e

LED bar graph

C6

→

Breadboard

17b h

LED bar graph

A7

→

Breadboard

18t e

LED bar graph

C7

→

Breadboard

18b h

LED bar graph

A8

→

Breadboard

19t e

LED bar graph

C8

→

Breadboard

19b h

LED bar graph

A9

→

Breadboard

20t e

LED bar graph

C9

→

Breadboard

20b h

LED bar graph

A10

→

Breadboard

21t e

LED bar graph

C10

→

Breadboard

21b h

Arduino

pin 2

→

Breadboard

12t a

Arduino

pin 3

→

Breadboard

13t a

Arduino

pin 4

→

Breadboard

14t a

Arduino

pin 5

→

Breadboard

15t a

Arduino

pin 6

→

Breadboard

16t a

Arduino

pin 7

→

Breadboard

17t a

Arduino

pin 8

→

Breadboard

18t a

Arduino

pin 9

→

Breadboard

19t a

Arduino

pin 10

→

Breadboard

20t a

Arduino

pin 11

→

Breadboard

21t a

Breadboard

12b j

→

Breadboard

bn 12

Breadboard

13b j

→

Breadboard

bn 13

Breadboard

14b j

→

Breadboard

bn 14

Breadboard

15b j

→

Breadboard

bn 15

Breadboard

16b j

→

Breadboard

bn 16

Breadboard

17b j

→

Breadboard

bn 17

Breadboard

18b j

→

Breadboard

bn 18

Breadboard

19b j

→

Breadboard

bn 19

Breadboard

20b j

→

Breadboard

bn 20

Breadboard

21b j

→

Breadboard

bn 21

Breadboard

bn 24

→

Arduino

GND

See it

Let's make a running light!

A bright dot zooms along a row of ten lights, like a tiny race car.

You see this on loading bars, volume meters, and fancy car taillights!

The story

The problem

One blinking light is fun, but a moving dot of light is even cooler.

Think of it like

It's like a spotlight at a show — it shines on one kid, then slides to the next.

Meet the parts

Holds all the parts and joins them, like a LEGO baseplate.

Breadboard

Our building board

Loading part…

It thinks and tells each light when to glow.

Arduino

The brain

Loading part…

Ten little lights in a line that you can switch on one by one.

LED bar graph

The row of lights

Loading part…

How it works

1

Turn them all off

First we turn every light off, so only one light will glow at a time.

digitalWrite(FIRST_PIN + j, LOW);
2

Light up one

The number i picks which light glows. That glowing light is our racing dot!

digitalWrite(FIRST_PIN + i, HIGH);
3

Wait, then move on

A short wait lets us see the dot. Then i goes up by one and the dot jumps to the next light.

delay(100);

Then loop back to step 1

Build the circuit

Follow these steps in order. Match the wires to the colors shown.

  1. 1

    Place Breadboard

    Place the Breadboard (bb1) on the breadboard.

    Breadboard placed — build like the real world!

    Loading part…
  2. 2

    Place Arduino

    Place the Arduino (uno) on the breadboard.

    Arduino placed — ready to build!

    Loading part…
  3. 3

    Place LED bar graph

    Place the LED bar graph (bar1) on the breadboard.

    Row of ten lights plugged into columns 12 to 21!

    Loading part…
  4. 4

    Connect Arduino pin 2 to Breadboard (bb1) anode (+)

    Arduino pin 2 to 12 a — any hole in column 12 (the bar graph is plugged into 12 e)

    Tip: Arduino pin 2 to 12 a — any hole in column 12 (the bar graph is plugged into 12 e)

    Signal reaches column 12 — same strip as the first light!

  5. 5

    Connect Arduino pin 3 to Breadboard (bb1) anode (+)

    Arduino pin 3 to 13 a — any hole in column 13 (the bar graph is plugged into 13 e)

    Tip: Arduino pin 3 to 13 a — any hole in column 13 (the bar graph is plugged into 13 e)

    Light 2 signal on column 13!

  6. 6

    Connect Arduino pin 4 to Breadboard (bb1) anode (+)

    Arduino pin 4 to 14 a — any hole in column 14 (the bar graph is plugged into 14 e)

    Tip: Arduino pin 4 to 14 a — any hole in column 14 (the bar graph is plugged into 14 e)

    Light 3 signal on column 14!

  7. 7

    Connect Arduino pin 5 to Breadboard (bb1) anode (+)

    Arduino pin 5 to 15 a — any hole in column 15 (the bar graph is plugged into 15 e)

    Tip: Arduino pin 5 to 15 a — any hole in column 15 (the bar graph is plugged into 15 e)

    Light 4 signal on column 15!

  8. 8

    Connect Arduino pin 6 to Breadboard (bb1) anode (+)

    Arduino pin 6 to 16 a — any hole in column 16 (the bar graph is plugged into 16 e)

    Tip: Arduino pin 6 to 16 a — any hole in column 16 (the bar graph is plugged into 16 e)

    Light 5 signal on column 16!

  9. 9

    Connect Arduino pin 7 to Breadboard (bb1) anode (+)

    Arduino pin 7 to 17 a — any hole in column 17 (the bar graph is plugged into 17 e)

    Tip: Arduino pin 7 to 17 a — any hole in column 17 (the bar graph is plugged into 17 e)

    Light 6 signal on column 17!

  10. 10

    Connect Arduino pin 8 to Breadboard (bb1) anode (+)

    Arduino pin 8 to 18 a — any hole in column 18 (the bar graph is plugged into 18 e)

    Tip: Arduino pin 8 to 18 a — any hole in column 18 (the bar graph is plugged into 18 e)

    Light 7 signal on column 18!

  11. 11

    Connect Arduino pin 9 to Breadboard (bb1) anode (+)

    Arduino pin 9 to 19 a — any hole in column 19 (the bar graph is plugged into 19 e)

    Tip: Arduino pin 9 to 19 a — any hole in column 19 (the bar graph is plugged into 19 e)

    Light 8 signal on column 19!

  12. 12

    Connect Arduino pin 10 to Breadboard (bb1) anode (+)

    Arduino pin 10 to 20 a — any hole in column 20 (the bar graph is plugged into 20 e)

    Tip: Arduino pin 10 to 20 a — any hole in column 20 (the bar graph is plugged into 20 e)

    Light 9 signal on column 20!

  13. 13

    Connect Arduino pin 11 to Breadboard (bb1) anode (+)

    Arduino pin 11 to 21 a — any hole in column 21 (the bar graph is plugged into 21 e)

    Tip: Arduino pin 11 to 21 a — any hole in column 21 (the bar graph is plugged into 21 e)

    All ten lights have a signal!

  14. 14

    Connect Breadboard (bb1) 12b.j to Breadboard (bb1) bn.12

    Column 12 to the blue ground line. This ties light 1 to the shared ground.

    Tip: Column 12 to the blue ground line. This ties light 1 to the shared ground.

    First cathode grounded!

  15. 15

    Connect Breadboard (bb1) 13b.j to Breadboard (bb1) bn.13

    Column 13 to the blue ground line. This ties light 2 to the shared ground.

    Tip: Column 13 to the blue ground line. This ties light 2 to the shared ground.

    Light 2 has a path to ground!

  16. 16

    Connect Breadboard (bb1) 14b.j to Breadboard (bb1) bn.14

    Column 14 to the blue ground line. This ties light 3 to the shared ground.

    Tip: Column 14 to the blue ground line. This ties light 3 to the shared ground.

    Light 3 has a path to ground!

  17. 17

    Connect Breadboard (bb1) 15b.j to Breadboard (bb1) bn.15

    Column 15 to the blue ground line. This ties light 4 to the shared ground.

    Tip: Column 15 to the blue ground line. This ties light 4 to the shared ground.

    Light 4 has a path to ground!

  18. 18

    Connect Breadboard (bb1) 16b.j to Breadboard (bb1) bn.16

    Column 16 to the blue ground line. This ties light 5 to the shared ground.

    Tip: Column 16 to the blue ground line. This ties light 5 to the shared ground.

    Light 5 has a path to ground!

  19. 19

    Connect Breadboard (bb1) 17b.j to Breadboard (bb1) bn.17

    Column 17 to the blue ground line. This ties light 6 to the shared ground.

    Tip: Column 17 to the blue ground line. This ties light 6 to the shared ground.

    Light 6 has a path to ground!

  20. 20

    Connect Breadboard (bb1) 18b.j to Breadboard (bb1) bn.18

    Column 18 to the blue ground line. This ties light 7 to the shared ground.

    Tip: Column 18 to the blue ground line. This ties light 7 to the shared ground.

    Light 7 has a path to ground!

  21. 21

    Connect Breadboard (bb1) 19b.j to Breadboard (bb1) bn.19

    Column 19 to the blue ground line. This ties light 8 to the shared ground.

    Tip: Column 19 to the blue ground line. This ties light 8 to the shared ground.

    Light 8 has a path to ground!

  22. 22

    Connect Breadboard (bb1) 20b.j to Breadboard (bb1) bn.20

    Column 20 to the blue ground line. This ties light 9 to the shared ground.

    Tip: Column 20 to the blue ground line. This ties light 9 to the shared ground.

    Light 9 has a path to ground!

  23. 23

    Connect Breadboard (bb1) 21b.j to Breadboard (bb1) bn.21

    Column 21 to the blue ground line. This ties light 10 to the shared ground.

    Tip: Column 21 to the blue ground line. This ties light 10 to the shared ground.

    Light 10 is on the blue line.

  24. 24

    Connect Breadboard (bb1) bn.24 to Arduino GND

    Blue ground line to Arduino ground. One wire grounds every light.

    Tip: Blue ground line to Arduino ground. One wire grounds every light.

    The blue line is connected to Arduino ground.

Try it

  • Press the green Run button — follow the bright dot from one end to the other.
  • Only one light should glow at a time!

Peek at code

How many lights and where

const int FIRST_PIN = 2;
const int NUM_LEDS = 10;

FIRST_PIN is the first light (pin 2) and NUM_LEDS is how many lights there are (10).

Get all the lights ready

void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(FIRST_PIN + i, OUTPUT);
  }
}

This loop gets every light pin ready, one after another, so they can all glow.

The chasing dot

void loop() {
  for (int i = 0; i < NUM_LEDS; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      digitalWrite(FIRST_PIN + j, LOW);
    }
    digitalWrite(FIRST_PIN + i, HIGH);
    delay(100);
  }
}

First all the lights turn off, then one turns on. Doing this over and over makes the dot race along the row.

Show full sketch (led-chaser.ino)
const int FIRST_PIN = 2;
const int NUM_LEDS = 10;
void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(FIRST_PIN + i, OUTPUT);
  }
}
void loop() {
  for (int i = 0; i < NUM_LEDS; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      digitalWrite(FIRST_PIN + j, LOW);
    }
    digitalWrite(FIRST_PIN + i, HIGH);
    delay(100);
  }
}

Quick quiz

Q1. Which part runs again and again?

  • A. loop() ✓
  • B. setup()
  • C. pinMode only
Why: Yes! loop() runs again and again, forever.

Q2. What does the number i pick in this program?

  • A. Which light is glowing ✓
  • B. How bright the row is
  • C. A random number
Why: Yes! i is the number that picks which light glows right now.

Code lab — try on your own

  1. Make the dot race faster — change delay(100) to delay(50).

    Hint: There is only one delay() inside loop().

  2. Add a little note (comment) on the line that lights one light up.

    Hint: Type // and your words at the end of the line with + i.

Code walkthrough

A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.

Program overview

Big idea

Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.

In this project

One light at a time glows and the bright dot runs along a bar of ten lights.

Tip

Read from the top to the bottom. Tap any word or line if you need help!

const int FIRST_PIN = 2;
const int NUM_LEDS = 10;

setup()

Big idea

setup() runs one time when the board turns on.

In this project

It gets all ten light pins (starting at pin 2) ready.

Why here

Things we do only once go inside setup().

void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(FIRST_PIN + i, OUTPUT);
  }
}

loop()

Big idea

loop() runs again and again, forever.

In this project

This is where the glowing dot moves from one light to the next.

Why here

Things that repeat go inside loop().

void loop() {
  for (int i = 0; i < NUM_LEDS; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      digitalWrite(FIRST_PIN + j, LOW);
    }
    digitalWrite(FIRST_PIN + i, HIGH);
    delay(100);
  }
}

Try this: Change the delay number inside loop(), then press Run to make the dot race faster or slower.

pinMode

Big idea

pinMode tells a pin if it will listen or push power out.

In this project

It makes each light pin ready to push power to a light.

Why here

It goes in setup() because we only set it once.

    pinMode(FIRST_PIN + i, OUTPUT);

digitalWrite

Big idea

digitalWrite turns a pin ON or OFF.

In this project

ON lights up one little light, OFF turns it dark.

Why here

It goes in loop() so the lights can keep changing.

      digitalWrite(FIRST_PIN + j, LOW);

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

A short wait lets you see the dot before it jumps to the next light.

Why here

Right after we light up a light.

    delay(100);