Quiz buzzer for three players on an Arduino Uno
Three answer buttons on pins 2, 3 and 4 and a reset button on 9: the first to press lights their LED (pins 6, 7 and 8) and sounds the buzzer on pin 5; the LED on pin 10 shows the round is open. The whole build, an Arduino Uno and 13 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 25 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $33. On Mokxi they're free.
What you'll learn
- Using arrays to handle several buttons and LEDs
- A state flag to lock out later presses
INPUT_PULLUPbuttons that read LOW when pressed- Giving each part of a program one job
- Difficulty: Intermediate
- Time: About 25 minutes
- Board: Arduino Uno R3
- Parts: 15
How it works
Three answer buttons sit on pins 2, 3 and 4. Each connects the pin to ground when pressed, and the sketch uses the internal pull-ups. While a round is open, a ready LED on pin 10 is lit and the sketch checks the three buttons in turn.
The first button found pressed wins. Its LED on pin 6, 7 or 8 lights, the buzzer on pin 5 beeps for 300 ms, and the ready LED goes out. Other buttons are ignored until the reset button on pin 9 is pressed.
Parts list
15 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 4 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 4 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, blueIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × BuzzerIn Starter Kit, Rocket Flight Computer Kit, Parking Assistant Kit.
Kits that can build it
These 9 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Resistor, 220 Ω (4) pin 1 | Arduino Uno R3 pin 10 |
| Pushbutton (4) pin 1a | Arduino Uno R3 pin 9 |
| Resistor, 220 Ω (3) pin 1 | Arduino Uno R3 pin 8 |
| Resistor, 220 Ω (2) pin 1 | Arduino Uno R3 pin 7 |
| Resistor, 220 Ω (1) pin 1 | Arduino Uno R3 pin 6 |
| Buzzer pin 1 | Arduino Uno R3 pin 5 |
| Pushbutton (3) pin 1a | Arduino Uno R3 pin 4 |
| Pushbutton (2) pin 1a | Arduino Uno R3 pin 3 |
| Pushbutton (1) pin 1a | Arduino Uno R3 pin 2 |
| Pushbutton (1) pin 2a | Arduino Uno R3 pin GND |
| Pushbutton (2) pin 2a | Arduino Uno R3 pin GND |
| Pushbutton (3) pin 2a | Arduino Uno R3 pin GND |
| Pushbutton (4) pin 2a | Arduino Uno R3 pin GND |
| LED, red pin C | Arduino Uno R3 pin GND |
| LED, yellow pin C | Arduino Uno R3 pin GND |
| LED, green pin C | Arduino Uno R3 pin GND |
| LED, blue pin C | Arduino Uno R3 pin GND |
| Buzzer pin 2 | Arduino Uno R3 pin GND |
| LED, red pin A | Resistor, 220 Ω (1) pin 2 |
| LED, yellow pin A | Resistor, 220 Ω (2) pin 2 |
| LED, green pin A | Resistor, 220 Ω (3) pin 2 |
| LED, blue pin A | Resistor, 220 Ω (4) pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A quiz buzzer: whoever presses first gets the light and the beep.
//
// answer buttons -> pins 2, 3, 4, reset button -> pin 9 (each to GND,
// read with INPUT_PULLUP)
// player LEDs -> pins 6, 7, 8, through 220 ohm each
// ready LED -> pin 10, through 220 ohm
// buzzer -> pin 5
//
// While the round is open, the ready LED is lit and the sketch watches all
// three answer buttons. The first one pressed wins: its LED lights, the
// buzzer beeps, and the others are ignored until reset is pressed.
const int ANSWER[3] = {2, 3, 4};
const int PLAYER_LED[3] = {6, 7, 8};
const int RESET = 9;
const int READY_LED = 10;
const int BUZZER = 5;
bool open = true;
void startRound() {
open = true;
for (int i = 0; i < 3; i++) digitalWrite(PLAYER_LED[i], LOW);
digitalWrite(READY_LED, HIGH);
Serial.println("ready: first to press wins");
}
void setup() {
for (int i = 0; i < 3; i++) {
pinMode(ANSWER[i], INPUT_PULLUP);
pinMode(PLAYER_LED[i], OUTPUT);
}
pinMode(RESET, INPUT_PULLUP);
pinMode(READY_LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: quiz buzzer");
startRound();
}
void loop() {
if (open) {
for (int i = 0; i < 3; i++) {
if (digitalRead(ANSWER[i]) == LOW) {
open = false;
digitalWrite(READY_LED, LOW);
digitalWrite(PLAYER_LED[i], HIGH);
Serial.print("player ");
Serial.print(i + 1);
Serial.println(" was first");
digitalWrite(BUZZER, HIGH);
delay(300);
digitalWrite(BUZZER, LOW);
break;
}
}
} else if (digitalRead(RESET) == LOW) {
startRound();
delay(200);
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
startRound sketch.ino
Opens a new round. It sets the open flag, turns all three player LEDs off, lights the ready LED and prints a message. It is called once at startup and again after each reset press.
void startRound() {
open = true;
for (int i = 0; i < 3; i++) digitalWrite(PLAYER_LED[i], LOW);
digitalWrite(READY_LED, HIGH);
Serial.println("ready: first to press wins");
}setup sketch.ino
Loops over the three players to set the buttons as INPUT_PULLUP and the LEDs as outputs. Then it sets up the reset button, ready LED and buzzer, opens serial and starts the first round.
void setup() {
for (int i = 0; i < 3; i++) {
pinMode(ANSWER[i], INPUT_PULLUP);
pinMode(PLAYER_LED[i], OUTPUT);
}
pinMode(RESET, INPUT_PULLUP);
pinMode(READY_LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: quiz buzzer");
startRound();
}loop sketch.ino
If the round is open, it checks each answer button. The first LOW wins: it closes the round, lights that player's LED, prints who was first and beeps. If the round is closed, it waits for the reset button and starts a new round.
void loop() {
if (open) {
for (int i = 0; i < 3; i++) {
if (digitalRead(ANSWER[i]) == LOW) {
open = false;
digitalWrite(READY_LED, LOW);
digitalWrite(PLAYER_LED[i], HIGH);
Serial.print("player ");
Serial.print(i + 1);
Serial.println(" was first");
digitalWrite(BUZZER, HIGH);
delay(300);
digitalWrite(BUZZER, LOW);
break;
}
}
} else if (digitalRead(RESET) == LOW) {
startRound();
delay(200);
}
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- A player's LED lights for the wrong button This project
Check that button i goes to the pin inANSWERand that LED i uses the matching pin inPLAYER_LED. - Nothing happens when pressing a button This project
Each button must go between its pin and GND. There is no resistor, since the pull-ups do that job. - The buzzer stays silent This project
It sits on pin 5 with its other pin on GND. Check both. - The input reads random HIGH and LOW when the button is not pressed. Pushbutton
A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW. - The button seems always pressed, or never changes. Pushbutton
A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.