Runs your sketch
Arduino
Brain
int variable stores a count
Use an int variable to count loop repeats and print the count on Serial.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 13 | → | Resistor pin 2 |
Resistor pin 1 | → | LED anode (+) |
LED cathode (-) | → | Arduino GND |
Variables remember numbers!
loopCount grows by 1 every loop — watch Serial and the LED blink together.
Step counters, scoreboards, and page views all use variables that count up.
The problem
You need the Arduino to remember a number between loop() passes.
Think of it like
Like a tally clicker — each loop adds one tick to the total.
Runs your sketch
Arduino
Brain
Grow the counter
Each time loop() runs, we add 1 to loopCount — the variable remembers the total.
loopCount = loopCount + 1;
Show on Serial
Serial Monitor prints the current value so you can watch it climb.
Serial.print("Count: ");
Serial.println(loopCount);Flash the LED
A quick blink celebrates each new count before loop() starts over.
digitalWrite(LED_PIN, HIGH); delay(200); digitalWrite(LED_PIN, LOW);
Wait and repeat
Pause so you can read the number, then loop() increments again.
delay(800);
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!
Counter variable
const int LED_PIN = 13; int loopCount = 0;
loopCount is an int — a named box that stores a whole number and keeps its value between loops.
Setup pin and Serial
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("LED Counter — watch the count grow!");
}
void loop() {setup() runs once: LED pin becomes an output and Serial is ready to print.
Increment and blink
Serial.print("Count: ");
Serial.println(loopCount);
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(800);
}
loop() adds 1, prints, blinks the LED, waits — then repeats forever.
const int LED_PIN = 13;
int loopCount = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("LED Counter — watch the count grow!");
}
void loop() {
loopCount = loopCount + 1;
Serial.print("Count: ");
Serial.println(loopCount);
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(800);
}
Q1. What is a variable?
Q2. What does loopCount = loopCount + 1 do?
Start counting from 5 — change int loopCount = 0 to int loopCount = 5.
Hint: Line 2 at the top of the sketch.
Blink faster — change delay(800) to delay(400) at the end of loop().
Hint: Last delay in loop(), line 17.
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
Use an int variable to count loop repeats and print the count on Serial.
Why here
Read from top to bottom. Hover words or lines for help!
const int LED_PIN = 13; int loopCount = 0;
setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for LED Counter.
Why here
One-time setup belongs here—not in loop().
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("LED Counter — watch the count grow!");
}loop()
Technical
Runs again and again after setup() is done.
In this project
This is the main action you see in LED Counter.
Why here
Repeating work (blink, read sensors) goes here.
void loop() {
loopCount = loopCount + 1;
Serial.print("Count: ");
Serial.println(loopCount);
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(800);
}
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 Counter circuit ready in the simulator.
Why here
Goes in setup() because we only set pins once at the start.
pinMode(LED_PIN, OUTPUT);
digitalWrite
Technical
Turns a pin ON or OFF.
In this project
Controls lights, motors, or buzzers in LED Counter.
Why here
Goes in loop() so it can keep changing while the program runs.
digitalWrite(LED_PIN, HIGH);
delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see LED Counter in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(200);
begin
Technical
Starts talking to the computer screen (serial monitor).
In this project
Lets LED Counter print debug messages.
Why here
Goes in setup() once before any Serial.print.
Serial.begin(9600);
Technical
Sends text to the serial monitor without a new line.
In this project
Shows values from LED Counter on the screen.
Why here
In loop() or setup() when you want to see what the board is doing.
Serial.print("Count: ");println
Technical
Sends text to the serial monitor and starts a new line.
In this project
Prints one line of output for LED Counter.
Why here
In loop() when each reading should appear on its own line.
Serial.println("LED Counter — watch the count grow!");