It decides who pressed first and locks the round.
Arduino
The referee
multiple inputs and first-wins logic
Two players race — first button press wins and locks out the other.

Pin connections
| Part 1 | Part 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 |
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 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.
It decides who pressed first and locks the round.
Arduino
The referee
Press it to buzz in for Player A.
Player A button
Player A's button
Press it to buzz in for Player B.
Player B button
Player B's button
It glows when Player A wins.
Player A LED
Player A's light
It glows when Player B wins.
Player B LED
Player B's light
Slows the power so Player A's light stays safe.
Resistor A
The protector
Slows the power so Player B's light stays safe.
Resistor B
The protector
It beeps to cheer for the winner.
Buzzer
The noise maker
Is the round still open?
We only accept a press while the round is not locked yet.
if (!locked && digitalRead(BTN_A) == LOW)
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);
Start a new round
Once both buttons are let go, the round clears and is ready again.
resetRound();
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 — ready to build!
Place Player A button
Place the Player A button (btnA) on the breadboard.
Place Player B button
Place the Player B button (btnB) on the breadboard.
Place Player A LED
Place the Player A LED (ledA) on the breadboard.
Place Player B LED
Place the Player B LED (ledB) on the breadboard.
Place Resistor A
Place the Resistor A (rA) on the breadboard.
Place Resistor B
Place the Resistor B (rB) on the breadboard.
Place Buzzer
Place the Buzzer (bz1) on the breadboard.
Connect Arduino pin 2 to Player A button (btnA) 1.l
Connect Arduino pin 2 to Player A button (btnA) 1.l.
Connect Player A button (btnA) 2.l to Arduino GND
Connect Player A button (btnA) 2.l to Arduino GND.
Connect Arduino pin 3 to Player B button (btnB) 1.l
Connect Arduino pin 3 to Player B button (btnB) 1.l.
Connect Player B button (btnB) 2.l to Arduino GND
Connect Player B button (btnB) 2.l to Arduino GND.
Connect Arduino pin 12 to Resistor A (rA) 2
Connect Arduino pin 12 to Resistor A (rA) 2.
Connect Resistor A (rA) 1 to Player A LED (ledA) anode (+)
Connect Resistor A (rA) 1 to Player A LED (ledA) anode (+).
Connect Player A LED (ledA) cathode (-) to Arduino GND
Connect Player A LED (ledA) cathode (-) to Arduino GND.
Connect Arduino pin 13 to Resistor B (rB) 2
Connect Arduino pin 13 to Resistor B (rB) 2.
Connect Resistor B (rB) 1 to Player B LED (ledB) anode (+)
Connect Resistor B (rB) 1 to Player B LED (ledB) anode (+).
Connect Player B LED (ledB) cathode (-) to Arduino GND
Connect Player B LED (ledB) cathode (-) to Arduino GND.
Connect Arduino pin 8 to Buzzer (bz1) 1
Connect Arduino pin 8 to Buzzer (bz1) 1.
Connect Buzzer (bz1) 2 to Arduino GND
Connect Buzzer (bz1) 2 to Arduino GND.
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.
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);
}
Q1. Where does work that repeats go?
Q2. What does locked = true stop?
Make rounds start sooner — change delay(1500) to delay(800).
Hint: That's line 32.
Add a note (comment) on line 23: // Player A wins first
Hint: It's inside the first if block.
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);