Runs your sketch
Arduino
Brain
increment with ++ and --
Increment a score variable with a button press and print on Serial.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Pushbutton pin 1 | → | Arduino pin 2 |
Pushbutton pin 2 | → | Arduino GND |
Press to add points!
Every button press adds 1 to score — your first variable that grows from input.
Arcade games, quiz apps, and sports scoreboards increment a score variable on each event.
The problem
The program must remember how many points you have earned so far.
Think of it like
Like putting a marble in a jar each time you score — the jar holds the total.
Runs your sketch
Arduino
Brain
Watch for button
Only when you press does the score change — no press means no change.
if (digitalRead(BUTTON_PIN) == LOW)
Add a point
Read the old score, add 1, store it back — the variable remembers between presses.
score = score + 1;
Show new total
Print the updated score, wait for release, then loop() listens again.
Serial.print("Score: ");
Serial.println(score);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!
Score variable
const int BUTTON_PIN = 2; int score = 0;
score starts at 0 — an int that grows each time you press the button.
Button setup
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Score Keeper — press to add a point");
}
void loop() {INPUT_PULLUP on the button pin; Serial is ready to print scores.
Increment on press
score = score + 1;
Serial.print("Score: ");
Serial.println(score);
while (digitalRead(BUTTON_PIN) == LOW) {
delay(20);
}
delay(150);
}
delay(20);
}
Press detected → add 1 → print → debounce → loop() waits for next press.
const int BUTTON_PIN = 2;
int score = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Score Keeper — press to add a point");
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
score = score + 1;
Serial.print("Score: ");
Serial.println(score);
while (digitalRead(BUTTON_PIN) == LOW) {
delay(20);
}
delay(150);
}
delay(20);
}
Q1. What is a variable?
Q2. Why store the score in a variable instead of just printing 1 each time?
Start at 10 points — change int score = 0 to int score = 10.
Hint: Line 2.
Add a comment on the score = score + 1 line explaining “add one point”.
Hint: Line 12 inside the if block.
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
Increment a score variable with a button press and print on Serial.
Why here
Read from top to bottom. Hover words or lines for help!
const int BUTTON_PIN = 2; int score = 0;
setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for Score Keeper.
Why here
One-time setup belongs here—not in loop().
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Score Keeper — press to add a point");
}loop()
Technical
Runs again and again after setup() is done.
In this project
This is the main action you see in Score Keeper.
Why here
Repeating work (blink, read sensors) goes here.
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
score = score + 1;
Serial.print("Score: ");
Serial.println(score);
while (digitalRead(BUTTON_PIN) == LOW) {
delay(20);
}
delay(150);
}
delay(20);
}
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 Score Keeper circuit ready in the simulator.
Why here
Goes in setup() because we only set pins once at the start.
pinMode(BUTTON_PIN, INPUT_PULLUP);
digitalRead
Technical
Checks if a pin is ON or OFF.
In this project
Reads buttons or sensors in Score Keeper.
Why here
Goes in loop() so we can react when something changes.
if (digitalRead(BUTTON_PIN) == LOW) {delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see Score Keeper in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(20);
begin
Technical
Starts talking to the computer screen (serial monitor).
In this project
Lets Score Keeper 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 Score Keeper on the screen.
Why here
In loop() or setup() when you want to see what the board is doing.
Serial.print("Score: ");println
Technical
Sends text to the serial monitor and starts a new line.
In this project
Prints one line of output for Score Keeper.
Why here
In loop() when each reading should appear on its own line.
Serial.println("Score Keeper — press to add a point");