Fareed Mohmed← Project library

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.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Quiz buzzer for two teams: the board, its power supply and the parts wired to the 40-pin header

Parts in this circuit

PartType
Player 1Push button
Player 2Push button
ResetPush button
Player 1 lampLED
Player 2 lampLED
HornBuzzer

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.

#ColourFrom (part and leg)To (header pin)
1ColouredPlayer 1 - SignalPin 29 (GPIO5)
2BlackPlayer 1 - GNDPin 6 (GND)
3ColouredPlayer 2 - SignalPin 31 (GPIO6)
4BlackPlayer 2 - GNDPin 9 (GND)
5ColouredReset - SignalPin 33 (GPIO13)
6BlackReset - GNDPin 14 (GND)
7ColouredPlayer 1 lamp - anode +Pin 11 (GPIO17)
8BlackPlayer 1 lamp - cathode -Pin 20 (GND)
9ColouredPlayer 2 lamp - anode +Pin 13 (GPIO27)
10BlackPlayer 2 lamp - cathode -Pin 25 (GND)
11ColouredHorn - +Pin 15 (GPIO22)
12BlackHorn - -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

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.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
45 mm LED, red1Robu.in Amazon.in ThinkRobotics
55 mm LED, blue1Robu.in Amazon.in ThinkRobotics
6330 ohm resistor, 1/4 W
One per LED
2Robu.in Amazon.in ThinkRobotics
7Tactile push button (12 mm, with cap)3Robu.in Amazon.in ThinkRobotics
8Active buzzer, 5 V1Robu.in Amazon.in ThinkRobotics
9Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
10Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 37. Simon memory gameAll projects39. Electronic dice on an LED bar →

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.