Hollys Reaction Game

by hollllew in Circuits > Raspberry Pi

17 Views, 0 Favorites, 0 Comments

Hollys Reaction Game

Screenshot 2025-05-29 at 6.32.43 pm.png

This project is a memory reaction game where you have to push the buttons that correspond with a lit up coloured led in the correct order

Supplies

Materials

Arcade Button (Built in LED) x 4

Raspberry Pi Pico x 1

Hookup Wire

3D printer (for the outer casing)


Tools

Soldering Iron

Wire Strippers

Side cutters

Wiring Diagram

Screenshot 2025-05-29 at 6.29.19 pm.png

The first step is to hook up the wires; attached is the wiring diagram. This diagram includes 4 LEDS, the buttons that I am using have built in LEDS so adding those won't be necessary.

Connect the Wires to the Buttons

Screenshot 2025-05-29 at 6.32.24 pm.png

I first soldered all the wires to the buttons (by tinning all the parts with solder and soldering them together). The black wires are the ground so I daisy chained them (connected them all together) so it was easier to attach them to a ground pin on the pico, like the diagram. I also daisy chained the black wires on the two different pins seperate from each other. Make sure to not daisy chain the red wires, for the LEDS to the white wires, for the buttons.

Connect to the Pico

Screenshot 2025-05-29 at 6.32.33 pm.png

Once all four of your buttons have the wires soldered on I connected them to the pico, the two black wires must go on the ground pins and the other wires can go on any GPIO pins. I used pins 0, 1, 3, 4 for the white wires, button pins and pins 4, 5, 6, 7 for the red wires, LED pins.

Note: if you put any wires on different pins don't forget to change it in the code.

Cod:

Once it is all connected you can paste this code into Thonny. Or just download the code through the link:

import machine

import time

import random


# Pin setup

button_pins = [0, 1, 2, 3]

led_pins = [4, 5, 6, 7]


buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins]

leds = [machine.Pin(pin, machine.Pin.OUT) for pin in led_pins]


def flash_led(index, duration=0.5):

leds[index].value(1)

time.sleep(duration)

leds[index].value(0)

time.sleep(0.2)


def show_sequence(sequence):

for i in sequence:

flash_led(i)


def get_button_press():

while True:

for i, button in enumerate(buttons):

if not button.value(): # Button is pressed (active LOW)

while not button.value(): # Wait for release

time.sleep(0.01)

print(f"Button {i} pressed")

flash_led(i, 0.2)

return i


def play_game():

sequence = [] # ✅ RESET the sequence here

level = 1


while True:

print(f"\nLevel {level}")

sequence.append(random.randint(0, 3))

print(f"Sequence: {sequence}")

show_sequence(sequence)


for expected in sequence:

pressed = get_button_press()

print(f"Expected: {expected}, Got: {pressed}")

if pressed != expected:

print("Wrong button! Game Over.")

for _ in range(3):

for led in leds:

led.value(1)

time.sleep(0.2)

for led in leds:

led.value(0)

time.sleep(0.2)

return # ✅ Exit play_game and start over

level += 1

time.sleep(0.5)


# Main loop

while True:

print("\nPress any button to start...")

while all(button.value() for button in buttons):

time.sleep(0.1)

play_game() # This now resets the sequence every time

Downloads

Casing

The final step is to add a case to the build. Attached is a file for one to be 3D printed.

Downloads

Other Helpful Projects to Look At

These are some other projects that are helpful to look at for inspiration and are the links that I used:

https://www.instructables.com/Reaction-Game-1/

https://www.instructables.com/Arduino-Music-and-Game-Box/

https://www.instructables.com/Arduino-Arcade-Lego-Games-Box/

https://www.instructables.com/How-Good-Is-Your-Memory-Geocache-Simon-Says-GC9GNK/

https://www.instructables.com/Arduino-LED-Memory-Game-in-a-Simple-Way/

https://www.instructables.com/search/?q=simple+memory+game&projects=featured

https://www.instructables.com/Bakers-Demo-Project/