LED Chaser Game (Reaction Based Game)

by 1077581 in Circuits > Arduino

32 Views, 0 Favorites, 0 Comments

LED Chaser Game (Reaction Based Game)

IMG_5556.jpeg

Hello, my name is Muhammad Dawood Khan, and for my Computer Engineering class, Taught by Ms.Edwards, I made an LED chaser game. You will initiate the game by hovering your hand over the distance sensor; the LEDs will be flashing from left to right. Using the Serial Monitor, you will be given a colour. With the given colour, you will need to press the button at the same time the LED chaser passes over that colour. For example, if you are given green, you will need to press the pushbutton right as it passes over green. You can set the Difficulty level of the circuit using the potentiometer, which slows down the rhythm of the LED. After achieving 5 points, it plays a victory song using the Buzzer. This circuit works through the usage of a 555 timer, a decade counter(4017 gate), and an Arduino. The 555 timer and 4017 gate counter control the LED chaser, and then the Arduino receives the signal from the LEDs and compares it to the push button. Now that you know how this project works, let's move on to the materials used.

Supplies

IMG_5566.jpeg
IMG_5562.jpeg

These are the supplies you will need:

1. 555 Timer x1

2. Johnson's Decade Counter x1

3. Arduino Uno x1

4. 4-Digit Seven Segment Display x1

5. Potentiometer (10k) x1

6. Assorted LEDs (Preferably 3x red, 2x green and 2x yellow to make the project easier to complete)

7. Pushbutton x1

8. Resistors. 1x 10k and 1x 330 ohm resistor

9. Electrolytic Capacitor (10 uF) x1

10. Wires

11.BreadBoard (of course )

12. Distance Sensor (HC-SR04)

13. Piezo Buzzer

Downloads

Setup (without Wiring)

IMG_5565.jpeg
IMG_5564.jpeg

Gather all the materials listed in the Supplies part and place them on the breadboard accordingly. The Circuit Diagram is a representation of the main components attached, such as the 555 timer, 4017, as well as the LEDs and resistors for a clear understanding of how the project functions.

Wire the Setup

IMG_5555.jpeg
IMG_5557.jpeg
F9SPZJIMBZLGO8G.jpg
494861789_688875287458382_7447882724683051465_n.png

Follow the picture/Tinker Cad Given and ensure all components are properly connected to both VCC (5V) and Ground to function correctly.


To set it up:

Circuit Assembly:


555 Timer:

  1. Connect the Reset pin to VCC (5v)
  2. Wire the Threshold pin to the Trigger pin.
  3. Add a 10 µF capacitor between the Trigger pin and Ground (negative pin to Ground, positive pin to Trigger).


Decade Counter (Johnson’s Decade Counter):

  1. Connect the Output pin of the 555 Timer to the Clock pin of the Decade Counter.
  2. Wire VCC and Ground to the Decade Counter.
  3. Attach your LEDs to the Decade Counter’s Output pins as shown in the image above(each pin will control a different LED).


Arduino Uno:

  1. Set up the Arduino Uno to read inputs from the pushbutton and the Distance sensor.
  2. The Arduino will also monitor the LEDs and check for button presses.


Pushbutton:

  1. Connect the pushbutton to an input pin on the Arduino.

Ultrasonic Distance Sensor:

  1. Attach the TrigPin and EchoPin to the Arduino to detect when your hand is placed near the sensor to trigger the game.

Piezo Buzzer:

  1. Connect the buzzer to an output pin on the Arduino for sound feedback when the game is won.


Code

Screenshot 2025-06-16 at 11.36.05 PM.png
Screenshot 2025-06-16 at 11.41.14 PM.png

Starting off with an important part of the code and it is the variables. Initializing the variables for the Arduino pins is straightforward. Initialize the LEDs, RGB and the Pushbutton to their respective pins.

The score variable keeps track of the player and their progress, while the randColour variable stores the target colour that the player needs to press the button for. The initialMessage makes sure the game instructions are displayed once when the game starts, and gameStarted looks if the game has started or not. Additionally, we introduce flags like correctTurn and buttonPressed to check the button presses at the right time. Finally, we include timing-related variables to control the time for the LEDs to flash during the game, and the level to track the game progress.

Void Loop 🔂

Screenshot 2025-06-16 at 11.44.05 PM.png

In the loop() function, the game runs continuously and checks for various conditions. First, the distance sensor is used to detect if a player is in front of it. If the player is detected (within 10 cm), the game starts, and an initial message is printed.

The button press detection is handled by reading the state of the pushbutton. If the button is pressed, the code checks which LED is currently on (based on randColour), and if the player presses the button when the correct color is lit, the score increases.

The score is updated and displayed on the LEDs (through displayScore()), and when the score reaches 5, a victory tune is played using the playVictoryTune() function. Once the player wins, the game resets, and the process starts again.

Here’s how everything works:

  1. The displayScore() function updates the LEDs to reflect the current score.
  2. The playVictoryTune() function plays a simple melody when the player wins.



Understanding the Code

Screenshot 2025-06-17 at 12.05.02 AM.png
Screenshot 2025-06-17 at 12.05.19 AM.png
Screenshot 2025-06-17 at 12.05.36 AM.png

Finally, to understand the code, each individual function:

The code will return a random value that's either 0-2 ( computers start counting at 0, not 1) each case number represents a colour: 0 is red, 1 is green , and 2 is blue for example,e if 0 is returned, the target colour would be red.


When we declared our variables we had six leds on the breadboard I placed them in a pattern e.g 1 = red , 2 = green , 3 = blue, 4 = red, 5 = green, 6 = blue, basically when the function is called when the button is pressed in the void loop function it'll check in the function whether the targetcolour matches the leds number for example red which is 1 and so and so on.

Demonstration

Below is a video attached to showcasew how the project works

Downloads

Conclusion

Finally! You're all ready to make your game come to life, you can get started by:

  1. Gathering all the Components (links given)
  2. Following the TinkerCad / schematic and placing the components requires
  3. Wiring the breadboard
  4. Coding

And finally, Thanks to this Instructable and the help of Ms.Edwards, your LED Chaser Game has come to Life! 🤗