Mission 16 · Stage 2

Quiz Buzzer

multiple inputs and first-wins logic

Two players race — first button press wins and locks out the other.

Quiz Buzzer circuit diagram

Pin connections

Part 1Part 2

Arduino

pin 2

Player A button

pin 1

Player A button

pin 2

Arduino

GND

Arduino

pin 3

Player B button

pin 1

Player B button

pin 2

Arduino

GND

Arduino

pin 12

Resistor A

pin 2

Resistor A

pin 1

Player A LED

anode (+)

Player A LED

cathode (-)

Arduino

GND

Arduino

pin 13

Resistor B

pin 2

Resistor B

pin 1

Player B LED

anode (+)

Player B LED

cathode (-)

Arduino

GND

Arduino

pin 8

Buzzer

pin 1 (+)

Buzzer

pin 2 (-)

Arduino

GND

See it

Let's see who is fastest!

Two players, two buttons — the first to press wins and the other is locked out.

TV quiz shows use this exact "first to buzz wins" idea.

The story

The problem

Two players might press at almost the same time. We need a rule for who wins.

Think of it like

Like slapping the buzzer in a quiz — the first hand down locks the round.

Meet the parts

It decides who pressed first and locks the round.

Arduino

The referee

Loading part…

Press it to buzz in for Player A.

Player A button

Player A's button

Loading part…

Press it to buzz in for Player B.

Player B button

Player B's button

Loading part…

It glows when Player A wins.

Player A LED

Player A's light

Loading part…

It glows when Player B wins.

Player B LED

Player B's light

Loading part…

Slows the power so Player A's light stays safe.

Resistor A

The protector

Loading part…

Slows the power so Player B's light stays safe.

Resistor B

The protector

Loading part…

It beeps to cheer for the winner.

Buzzer

The noise maker

Loading part…

How it works

1

Is the round still open?

We only accept a press while the round is not locked yet.

if (!locked && digitalRead(BTN_A) == LOW)
2

Player A wins

The first press locks the round so Player B cannot win this time.

locked = true;
digitalWrite(LED_A, HIGH);
tone(BUZZER, 523);
3

Start a new round

Once both buttons are let go, the round clears and is ready again.

resetRound();

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 build!

    Loading part…
  2. 2

    Place Player A button

    Place the Player A button (btnA) on the breadboard.

    Loading part…
  3. 3

    Place Player B button

    Place the Player B button (btnB) on the breadboard.

    Loading part…
  4. 4

    Place Player A LED

    Place the Player A LED (ledA) on the breadboard.

    Loading part…
  5. 5

    Place Player B LED

    Place the Player B LED (ledB) on the breadboard.

    Loading part…
  6. 6

    Place Resistor A

    Place the Resistor A (rA) on the breadboard.

    Loading part…
  7. 7

    Place Resistor B

    Place the Resistor B (rB) on the breadboard.

    Loading part…
  8. 8

    Place Buzzer

    Place the Buzzer (bz1) on the breadboard.

    Loading part…
  9. 9

    Connect Arduino pin 2 to Player A button (btnA) 1.l

    Connect Arduino pin 2 to Player A button (btnA) 1.l.

  10. 10

    Connect Player A button (btnA) 2.l to Arduino GND

    Connect Player A button (btnA) 2.l to Arduino GND.

  11. 11

    Connect Arduino pin 3 to Player B button (btnB) 1.l

    Connect Arduino pin 3 to Player B button (btnB) 1.l.

  12. 12

    Connect Player B button (btnB) 2.l to Arduino GND

    Connect Player B button (btnB) 2.l to Arduino GND.

  13. 13

    Connect Arduino pin 12 to Resistor A (rA) 2

    Connect Arduino pin 12 to Resistor A (rA) 2.

  14. 14

    Connect Resistor A (rA) 1 to Player A LED (ledA) anode (+)

    Connect Resistor A (rA) 1 to Player A LED (ledA) anode (+).

  15. 15

    Connect Player A LED (ledA) cathode (-) to Arduino GND

    Connect Player A LED (ledA) cathode (-) to Arduino GND.

  16. 16

    Connect Arduino pin 13 to Resistor B (rB) 2

    Connect Arduino pin 13 to Resistor B (rB) 2.

  17. 17

    Connect Resistor B (rB) 1 to Player B LED (ledB) anode (+)

    Connect Resistor B (rB) 1 to Player B LED (ledB) anode (+).

  18. 18

    Connect Player B LED (ledB) cathode (-) to Arduino GND

    Connect Player B LED (ledB) cathode (-) to Arduino GND.

  19. 19

    Connect Arduino pin 8 to Buzzer (bz1) 1

    Connect Arduino pin 8 to Buzzer (bz1) 1.

  20. 20

    Connect Buzzer (bz1) 2 to Arduino GND

    Connect Buzzer (bz1) 2 to Arduino GND.

Try it

  • Player A uses the red button. Player B uses the blue button.
  • The first press lights that player's LED — the other does nothing until reset.

Peek at code

The lock

bool locked = false;
void resetRound() {
  locked = false;
  digitalWrite(LED_A, LOW);
  digitalWrite(LED_B, LOW);
  noTone(BUZZER);
}

locked is the game rule — once it is true, other presses are ignored.

First press wins

void loop() {
  if (!locked && digitalRead(BTN_A) == LOW) {
    locked = true;
    digitalWrite(LED_A, HIGH);
    tone(BUZZER, 523, 500);
  } else if (!locked && digitalRead(BTN_B) == LOW) {
    locked = true;
    digitalWrite(LED_B, HIGH);
    tone(BUZZER, 440, 500);
  }
  if (locked && digitalRead(BTN_A) == HIGH && digitalRead(BTN_B) == HIGH) {
    delay(1500);
    resetRound();
  }
  delay(20);
}

We check Player A, then Player B. resetRound() clears the lights and the lock.

Show full sketch (quiz-buzzer.ino)
const int BTN_A = 2;
const int BTN_B = 3;
const int LED_A = 12;
const int LED_B = 13;
const int BUZZER = 8;
bool locked = false;
void resetRound() {
  locked = false;
  digitalWrite(LED_A, LOW);
  digitalWrite(LED_B, LOW);
  noTone(BUZZER);
}
void setup() {
  pinMode(BTN_A, INPUT_PULLUP);
  pinMode(BTN_B, INPUT_PULLUP);
  pinMode(LED_A, OUTPUT);
  pinMode(LED_B, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  resetRound();
}
void loop() {
  if (!locked && digitalRead(BTN_A) == LOW) {
    locked = true;
    digitalWrite(LED_A, HIGH);
    tone(BUZZER, 523, 500);
  } else if (!locked && digitalRead(BTN_B) == LOW) {
    locked = true;
    digitalWrite(LED_B, HIGH);
    tone(BUZZER, 440, 500);
  }
  if (locked && digitalRead(BTN_A) == HIGH && digitalRead(BTN_B) == HIGH) {
    delay(1500);
    resetRound();
  }
  delay(20);
}

Quick quiz

Q1. Where does work that repeats go?

  • A. loop()
  • B. setup()
  • C. pinMode only
Why: Yes! loop() runs again and again.

Q2. What does locked = true stop?

  • A. The other player winning after the first press
  • B. The buzzer from ever working
  • C. setup() from running
Why: Yes! The first press locks the round for that player.

Code lab — try on your own

  1. Make rounds start sooner — change delay(1500) to delay(800).

    Hint: That's line 32.

  2. Add a note (comment) on line 23: // Player A wins first

    Hint: It's inside the first if block.

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

Two players race. The first to press lights their LED and beeps — the other is locked out.

Tip

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

const int BTN_A = 2;
const int BTN_B = 3;
const int LED_A = 12;
const int LED_B = 13;
const int BUZZER = 8;
bool locked = false;
void resetRound() {
  locked = false;
  digitalWrite(LED_A, LOW);
  digitalWrite(LED_B, LOW);
  noTone(BUZZER);
}

setup()

Big idea

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

In this project

It gets both buttons, both lights, and the buzzer ready, then starts a fresh round.

Why here

Things we do only once go inside setup().

void setup() {
  pinMode(BTN_A, INPUT_PULLUP);
  pinMode(BTN_B, INPUT_PULLUP);
  pinMode(LED_A, OUTPUT);
  pinMode(LED_B, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  resetRound();
}

loop()

Big idea

loop() runs again and again, forever.

In this project

It listens for the first press and locks the round for that player.

Why here

Things that repeat go inside loop().

void loop() {
  if (!locked && digitalRead(BTN_A) == LOW) {
    locked = true;
    digitalWrite(LED_A, HIGH);
    tone(BUZZER, 523, 500);
  } else if (!locked && digitalRead(BTN_B) == LOW) {
    locked = true;
    digitalWrite(LED_B, HIGH);
    tone(BUZZER, 440, 500);
  }
  if (locked && digitalRead(BTN_A) == HIGH && digitalRead(BTN_B) == HIGH) {
    delay(1500);
    resetRound();
  }
  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 the button pins to listen and the LED and buzzer pins to push power out.

Why here

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

  pinMode(BTN_A, INPUT_PULLUP);

digitalWrite

Big idea

digitalWrite turns a pin ON or OFF.

In this project

It turns the winner's light on, and turns lights off at reset.

Why here

It is used when a player wins or the round resets.

  digitalWrite(LED_A, LOW);

digitalRead

Big idea

digitalRead checks if a pin is ON or OFF.

In this project

It checks which player pressed their button.

Why here

It goes in loop() so we can catch the first press.

  if (!locked && digitalRead(BTN_A) == LOW) {

tone

Big idea

tone makes a buzzer play a beep at a chosen pitch.

In this project

It plays a beep to celebrate the player who pressed first.

Why here

It goes in loop() when a player wins.

    tone(BUZZER, 523, 500);

noTone

Big idea

noTone stops the buzzer so it goes quiet.

In this project

It silences the buzzer when the round resets.

Why here

It is used while clearing the round.

  noTone(BUZZER);

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

It pauses before clearing the round so everyone sees the winner.

Why here

Right before the round resets.

    delay(1500);