Engineering · Raspberry Pi · Project 38 of 47 · Games and logic · Beginner
Quiz buzzer for two teams
Two players, one buzzer each. The first one to press wins: their lamp lights, a beep sounds and the other player is locked out until you reset.

Parts in this circuit
| Part | Type |
|---|---|
| Player 1 | Push button |
| Player 2 | Push button |
| Reset | Push button |
| Player 1 lamp | LED |
| Player 2 lamp | LED |
| Horn | Buzzer |
Wiring, pin by pin
Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.
| # | Colour | From (part and leg) | To (header pin) |
|---|---|---|---|
| 1 | Coloured | Player 1 - Signal | Pin 29 (GPIO5) |
| 2 | Black | Player 1 - GND | Pin 6 (GND) |
| 3 | Coloured | Player 2 - Signal | Pin 31 (GPIO6) |
| 4 | Black | Player 2 - GND | Pin 9 (GND) |
| 5 | Coloured | Reset - Signal | Pin 33 (GPIO13) |
| 6 | Black | Reset - GND | Pin 14 (GND) |
| 7 | Coloured | Player 1 lamp - anode + | Pin 11 (GPIO17) |
| 8 | Black | Player 1 lamp - cathode - | Pin 20 (GND) |
| 9 | Coloured | Player 2 lamp - anode + | Pin 13 (GPIO27) |
| 10 | Black | Player 2 lamp - cathode - | Pin 25 (GND) |
| 11 | Coloured | Horn - + | Pin 15 (GPIO22) |
| 12 | Black | Horn - - | Pin 30 (GND) |
Python code (gpiozero)
from gpiozero import Button, LED, Buzzer
from time import sleep
p1 = Button(5)
p2 = Button(6)
reset = Button(13)
lamp1 = LED(17)
lamp2 = LED(27)
horn = Buzzer(22)
while True:
lamp1.off()
lamp2.off()
print("Ready. Who is first?")
while not (p1.is_pressed or p2.is_pressed):
sleep(0.005) # check very often
if p1.is_pressed:
lamp1.on()
print("Player 1 was first!")
else:
lamp2.on()
print("Player 2 was first!")
horn.beep(0.2, 0.1, n=2)
reset.wait_for_press()
reset.wait_for_release()
How the code works
- The while not (...) loop waits until at least one button is pressed.
- The first if decides the winner. After that the program stops reading the buttons, so the second player is locked out.
- The reset button sends the program back to the start of the outer loop.
You will learn
- Waiting for either of two buttons
- First-past-the-post logic
- Locking the other input
Try this
- Hold Player 2 and then Player 1. Who wins?
- Add a third player.
- Add a 10 second timer that shows time-up with the horn.
On a real Pi
- Use big arcade buttons with long wires. Add a resistor in series with each LED.
- Two presses at the same millisecond are very rare, but the code gives Player 1 the win in a tie. Say this in the rules.
- Add a speaker or an MP3 player module for a louder sound.
Parts to buy
The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.
| # | Item | Qty | Buy / compare |
|---|---|---|---|
| 1 | Raspberry Pi 4 Model B about 4000 to 9000 INR | 1 | Robu.in Amazon.in ThinkRobotics |
| 2 | Official 15 W USB-C power supply (5.1 V, 3 A) Do not use an old phone charger | 1 | Robu.in Amazon.in ThinkRobotics |
| 3 | microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS) And a card reader to write it | 1 | Robu.in Amazon.in ThinkRobotics |
| 4 | 5 mm LED, red | 1 | Robu.in Amazon.in ThinkRobotics |
| 5 | 5 mm LED, blue | 1 | Robu.in Amazon.in ThinkRobotics |
| 6 | 330 ohm resistor, 1/4 W One per LED | 2 | Robu.in Amazon.in ThinkRobotics |
| 7 | Tactile push button (12 mm, with cap) | 3 | Robu.in Amazon.in ThinkRobotics |
| 8 | Active buzzer, 5 V | 1 | Robu.in Amazon.in ThinkRobotics |
| 9 | Dupont jumper wires, male-to-female, 20 cm (pack of 40) | 1 | Robu.in Amazon.in ThinkRobotics |
| 10 | Breadboard 830 points For resistors and shared GND / 5 V | 1 | Robu.in Amazon.in ThinkRobotics |
This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.