Mission 25 · Stage 3

Score Keeper

increment with ++ and --

Increment a score variable with a button press and print on Serial.

Score Keeper circuit diagram

Pin connections

Part 1Part 2

Pushbutton

pin 1

Arduino

pin 2

Pushbutton

pin 2

Arduino

GND

See it

Press to score points!

Every button press adds 1 to your score — your first number that grows when you push a button.

Arcade games, quizzes, and sports scoreboards add to a score just like this.

The story

The problem

The board needs to remember how many points you have earned so far.

Think of it like

It's like dropping a marble in a jar each time you score — the jar holds your total.

Meet the parts

It watches the button and keeps your score.

Arduino

The brain

Loading part…

How it works

1

Did you press the button?

The score only changes when you press — no press means no change.

if (digitalRead(BUTTON_PIN) == LOW)
2

Add a point

Take the old score, add 1, and save it back — the box remembers between presses.

score = score + 1;
3

Show the new total

Show the new score, wait for you to let go, then listen again.

Serial.print("Score: ");
Serial.println(score);

Then loop back to step 1

Build the circuit

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

  1. 1

    Place Arduino

    Place the Arduino (uno) on the breadboard.

    Arduino placed — ready to score!

    Loading part…

Try it

  • Tap the button — the screen shows Score: 1, 2, 3…
  • Each press adds exactly one point.

Peek at code

The score box

const int BUTTON_PIN = 2;
int score = 0;

score starts at 0 — a box that grows by 1 each time you press the button.

Get the button ready

  pinMode(BUTTON_PIN, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Score Keeper — press to add a point");
}
void loop() {

setup() sets up the button on pin 2 and opens the message screen.

Add a point on press

    score = score + 1;
    Serial.print("Score: ");
    Serial.println(score);
    while (digitalRead(BUTTON_PIN) == LOW) {
      delay(20);
    }
    delay(150);
  }
  delay(20);
}

Press → add 1 → show the score → wait for release → listen again.

Show full sketch (score-keeper.ino)
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);
}

Quick quiz

Q1. What is a variable?

  • A. A named box that stores a number
  • B. A kind of wire
  • C. Just a wait
Why: Yes! int score = 0; makes a box named score.

Q2. Why keep the score in a box instead of just printing 1 each time?

  • A. So the total grows and is remembered between presses
  • B. Boxes make the light brighter
  • C. The screen only works with boxes
Why: Yes! The box remembers the total even as the loop runs again.

Code lab — try on your own

  1. Start at 10 points — change int score = 0 to int score = 10.

    Hint: Line 2.

  2. Add a note (comment) on the score line that says "add one point".

    Hint: Line 12 inside the if.

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

Each button press adds 1 to a score, and the screen shows the new total.

Tip

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

const int BUTTON_PIN = 2;
int score = 0;

setup()

Big idea

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

In this project

It gets the button on pin 2 ready and opens the message screen.

Why here

Things we do only once go inside setup().

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Score Keeper — press to add a point");
}

loop()

Big idea

loop() runs again and again, forever.

In this project

This is where we watch for the button and add a point each time.

Why here

Things that repeat go inside loop().

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 a number inside loop(), then press Run to see what happens.

pinMode

Big idea

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

In this project

It sets pin 2 to listen for the button press.

Why here

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

  pinMode(BUTTON_PIN, INPUT_PULLUP);

digitalRead

Big idea

digitalRead checks if a pin is ON or OFF.

In this project

It checks if the button is being pressed.

Why here

It goes in loop() so we can react the moment you press.

  if (digitalRead(BUTTON_PIN) == LOW) {

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

A tiny wait helps the button read cleanly.

Why here

Right after we check the button.

      delay(20);

begin

Big idea

Serial.begin opens a message screen so the board can talk to the computer.

In this project

It lets us print the score.

Why here

It goes in setup() once, before we print anything.

  Serial.begin(9600);

print

Big idea

Serial.print writes words or a number on the screen and stays on the same line.

In this project

It writes "Score: " right before the number.

Why here

In loop() so we can see each new score.

    Serial.print("Score: ");

println

Big idea

Serial.println writes on the screen and then jumps to a new line.

In this project

It prints a friendly hello when the board turns on.

Why here

So each message gets its own line.

  Serial.println("Score Keeper — press to add a point");