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

First press wins!

Two players, one buzzer — locked stops the other from scoring.

Quiz shows use exactly this “first valid input wins” logic.

The story

The problem

Two inputs can fire at once — you need rules for who wins.

Think of it like

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

Meet the parts

Runs your sketch

Arduino

Brain

Loading part…

First press wins

Player A button

Input

Loading part…

Second player buzzes in

Player B button

Input

Loading part…

Shows A won the round

Player A LED

Output

Loading part…

Shows B won the round

Player B LED

Output

Loading part…

Protects A LED

Resistor A

Safety

Loading part…

Protects B LED

Resistor B

Safety

Loading part…

Celebrates the winner

Buzzer

Sound

Loading part…

How it works

1

Still open?

Only accept input while locked is false.

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

Player A wins

First valid press sets locked so B cannot win this round.

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

Reset round

After both buttons release, locked clears for the next question.

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!

    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: red button. Player B: blue button.
  • First press lights their LED — second press should do nothing until reset.

Peek at code

Lock flag

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

locked is a boolean game rule — once true, other presses are ignored.

First-wins logic

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);
}

if / else if checks A then B; resetRound() clears LEDs and locked.

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 repeating work belong?

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

Q2. What does locked = true prevent?

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

Code lab — try on your own

  1. Shorten between rounds — change delay(1500) to delay(800).

    Hint: Line 32.

  2. Comment line 23: // Player A wins first

    Hint: Inside the first if block.

Code walkthrough

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

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

Why here

Read from top to bottom. Hover words or lines for 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()

Technical

Runs one time when the board turns on.

In this project

Sets up pins and libraries for Quiz Buzzer.

Why here

One-time setup belongs here—not in loop().

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()

Technical

Runs again and again after setup() is done.

In this project

This is the main action you see in Quiz Buzzer.

Why here

Repeating work (blink, read sensors) goes here.

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 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 Quiz Buzzer circuit ready in the simulator.

Why here

Goes in setup() because we only set pins once at the start.

  pinMode(BTN_A, INPUT_PULLUP);

digitalWrite

Technical

Turns a pin ON or OFF.

In this project

Controls lights, motors, or buzzers in Quiz Buzzer.

Why here

Goes in loop() so it can keep changing while the program runs.

  digitalWrite(LED_A, LOW);

digitalRead

Technical

Checks if a pin is ON or OFF.

In this project

Reads buttons or sensors in Quiz Buzzer.

Why here

Goes in loop() so we can react when something changes.

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

tone

Technical

Plays a beep on a buzzer pin at a chosen pitch.

In this project

Makes sounds in Quiz Buzzer.

Why here

Goes in loop() when you want notes or alarms.

    tone(BUZZER, 523, 500);

noTone

Technical

Stops the buzzer sound on that pin.

In this project

Turns off the sound in Quiz Buzzer.

Why here

After tone() or before a pause so the buzzer is silent.

  noTone(BUZZER);

delay

Technical

Waits for some time. Nothing else runs during the wait.

In this project

Controls speed so you can see Quiz Buzzer in the simulator.

Why here

Right after an action that should stay the same for a moment.

    delay(1500);