Mission 05 · Stage 1

Multiple LED Patterns

nested loops and pattern tables

Show different bar graph patterns stored in tables and loops.

Multiple LED Patterns 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 light shapes!

A row of lights shows stripes, then pairs, then a glowing block — again and again.

Big screens and scoreboards show saved shapes just like this!

The story

The problem

Typing every single light by hand is a lot of work. Let's save the shapes and reuse them.

Think of it like

It's like a coloring book — the shapes are drawn once, and you fill them in again and again.

Meet the parts

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

Breadboard

Our building board

Loading part…

It reads the saved shapes and tells the lights what to do.

Arduino

The brain

Loading part…

Ten little lights in a line that make the shapes.

LED bar graph

The row of lights

Loading part…

How it works

1

Show the stripes

patternA is a list of 1s and 0s. A 1 means a light glows and a 0 means it stays dark — together they make stripes.

showPattern(patternA);
delay(400);
2

Show the pairs

patternB is a different list, so the lights make a different shape — two on, two off.

showPattern(patternB);
delay(400);
3

Show the middle block

patternC lights up the middle lights. Then loop() jumps back to the stripes and does it all again!

showPattern(patternC);
delay(400);

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 — try to name each shape before it changes.
  • The shapes come from the saved lists at the top — not magic!

Peek at code

The saved shapes

const byte patternA[] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
const byte patternB[] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1};
const byte patternC[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};

Each list holds 1s and 0s. A 1 means a light glows and a 0 means it stays dark. A new shape is just a new list!

The showPattern helper

void showPattern(const byte *pat) {
  for (int i = 0; i < NUM_LEDS; i++) {
    digitalWrite(FIRST_PIN + i, pat[i] ? HIGH : LOW);
  }
}

This little helper reads a shape's list and lights each light ON or OFF. We reuse it for every shape.

Play the shapes

void loop() {
  showPattern(patternA);
  delay(400);
  showPattern(patternB);
  delay(400);
  showPattern(patternC);
  delay(400);
}

loop() shows shape A, then B, then C, with a wait between each. That is the whole repeating light show.

Show full sketch (led-patterns.ino)
const int FIRST_PIN = 2;
const int NUM_LEDS = 10;
const byte patternA[] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
const byte patternB[] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1};
const byte patternC[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
void showPattern(const byte *pat) {
  for (int i = 0; i < NUM_LEDS; i++) {
    digitalWrite(FIRST_PIN + i, pat[i] ? HIGH : LOW);
  }
}
void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(FIRST_PIN + i, OUTPUT);
  }
}
void loop() {
  showPattern(patternA);
  delay(400);
  showPattern(patternB);
  delay(400);
  showPattern(patternC);
  delay(400);
}

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. Why do we save the shapes in lists like patternA?

  • A. So we can reuse a shape with one helper ✓
  • B. To make the Arduino faster
  • C. To replace pinMode()
Why: Yes! A saved list plus a helper saves us from typing every light by hand.

Code lab — try on your own

  1. Speed up the show — change all the delay(400) numbers to delay(200).

    Hint: There are three delay(400) lines inside loop().

  2. Change the first shape — flip a 1 to a 0 (or a 0 to a 1) on line 3.

    Hint: Edit the numbers inside the curly braces of patternA.

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

A row of ten lights shows three saved shapes, then starts over.

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;
const byte patternA[] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
const byte patternB[] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1};
const byte patternC[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0};
void showPattern(const byte *pat) {
  for (int i = 0; i < NUM_LEDS; i++) {
    digitalWrite(FIRST_PIN + i, pat[i] ? HIGH : LOW);
  }
}

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 three light shapes take turns on the bar.

Why here

Things that repeat go inside loop().

void loop() {
  showPattern(patternA);
  delay(400);
  showPattern(patternB);
  delay(400);
  showPattern(patternC);
  delay(400);
}

Try this: Change a delay number inside loop(), then press Run to make each shape hold longer.

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

It looks at the shape's list and lights each light ON for a 1 or OFF for a 0.

Why here

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

    digitalWrite(FIRST_PIN + i, pat[i] ? HIGH : LOW);

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

It holds each shape on screen long enough for you to see it.

Why here

Right after we show a shape.

  delay(400);