Runs your sketch
Arduino
Brain
loop index drives a moving pattern
Light one segment at a time on a bar graph using a loop index.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 2 | → | LED bar graph A1 |
Arduino pin 3 | → | LED bar graph A2 |
Arduino pin 4 | → | LED bar graph A3 |
Arduino pin 5 | → | LED bar graph A4 |
Arduino pin 6 | → | LED bar graph A5 |
Arduino pin 7 | → | LED bar graph A6 |
Arduino pin 8 | → | LED bar graph A7 |
Arduino pin 9 | → | LED bar graph A8 |
Arduino pin 10 | → | LED bar graph A9 |
Arduino pin 11 | → | LED bar graph A10 |
LED bar graph C10 | → | Arduino GND |
One lit segment at a time!
A loop index picks which LED is ON — the dot runs down the bar.
Loading bars and volume meters chase like this.
The problem
You want a moving pattern, not just one blinking LED.
Think of it like
Like spotlighting one person in a line, then the next.
Runs your sketch
Arduino
Brain
Ten segments you can light up
LED bar graph
Display
Clear the bar
An inner loop sets every segment LOW before lighting the next one.
digitalWrite(FIRST_PIN + j, LOW);
Light segment i
The outer loop variable i picks which bar segment is ON — that is the chase!
digitalWrite(FIRST_PIN + i, HIGH);
Pause and next
A short delay lets you see the dot move; then i increases and the chase continues.
delay(100);
Then loop back to step 1
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed!
Place LED bar graph
Place the LED bar graph (bar1) on the breadboard.
Connect Arduino pin 2 to LED bar graph (bar1) A1
Connect Arduino pin 2 to LED bar graph (bar1) A1.
Connect Arduino pin 3 to LED bar graph (bar1) A2
Connect Arduino pin 3 to LED bar graph (bar1) A2.
Connect Arduino pin 4 to LED bar graph (bar1) A3
Connect Arduino pin 4 to LED bar graph (bar1) A3.
Connect Arduino pin 5 to LED bar graph (bar1) A4
Connect Arduino pin 5 to LED bar graph (bar1) A4.
Connect Arduino pin 6 to LED bar graph (bar1) A5
Connect Arduino pin 6 to LED bar graph (bar1) A5.
Connect Arduino pin 7 to LED bar graph (bar1) A6
Connect Arduino pin 7 to LED bar graph (bar1) A6.
Connect Arduino pin 8 to LED bar graph (bar1) A7
Connect Arduino pin 8 to LED bar graph (bar1) A7.
Connect Arduino pin 9 to LED bar graph (bar1) A8
Connect Arduino pin 9 to LED bar graph (bar1) A8.
Connect Arduino pin 10 to LED bar graph (bar1) A9
Connect Arduino pin 10 to LED bar graph (bar1) A9.
Connect Arduino pin 11 to LED bar graph (bar1) A10
Connect Arduino pin 11 to LED bar graph (bar1) A10.
Connect LED bar graph (bar1) C10 to Arduino GND
Connect LED bar graph (bar1) C10 to Arduino GND.
Pin range
const int FIRST_PIN = 2; const int NUM_LEDS = 10;
FIRST_PIN is the first bar segment; NUM_LEDS is how many segments the loop uses.
Setup all outputs
void setup() {
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(FIRST_PIN + i, OUTPUT);
}
}A for-loop calls pinMode on pins 2 through 11 so each segment can be driven.
Chase 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);
}
}Outer loop picks i; inner loop clears all LEDs; then one segment turns on. That is how the dot runs along the bar.
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);
}
}
Q1. Where does repeating work belong?
Q2. What does the loop variable i control in this sketch?
Make the chase faster — change delay(100) to delay(50).
Hint: There is only one delay() inside loop().
Add a comment on the line that lights one segment (digitalWrite with + i).
Hint: Use // at the end of that line.
A line-by-line tour of the sketch — the same steps as in Robo Gurukul Studio.
Program overview
Technical
Sketches have globals, then setup() once, then loop() forever.
In this project
Light one segment at a time on a bar graph using a loop index.
Why here
Read from top to bottom. Hover words or lines for help!
const int FIRST_PIN = 2; const int NUM_LEDS = 10;
setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for LED Chaser.
Why here
One-time setup belongs here—not in loop().
void setup() {
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(FIRST_PIN + i, OUTPUT);
}
}loop()
Technical
Runs again and again after setup() is done.
In this project
This is the main action you see in LED Chaser.
Why here
Repeating work (blink, read sensors) goes here.
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 numbers in loop(), then compile and run the simulator.
pinMode
Technical
Tells a pin if it listens or drives something.
In this project
Gets the LED Chaser circuit ready in the simulator.
Why here
Goes in setup() because we only set pins once at the start.
pinMode(FIRST_PIN + i, OUTPUT);
digitalWrite
Technical
Turns a pin ON or OFF.
In this project
Controls lights, motors, or buzzers in LED Chaser.
Why here
Goes in loop() so it can keep changing while the program runs.
digitalWrite(FIRST_PIN + j, LOW);
delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see LED Chaser in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(100);