LED Chaser Game

by 772911 in Circuits > Arduino

34 Views, 0 Favorites, 0 Comments

LED Chaser Game

20250616_103815.jpg
Screenshot 2025-06-16 185517.png

Welcome to my project! Today, I will be showing you how to make an LED Chaser Game. In this game, a series of LEDs light up one after another, creating the effect that they're "chasing" each other. Therefore, the name is "LED chaser game."

The main objective is simple: a colour will be displayed on the serial monitor, and your job as a player is to press the button when the LED of that colour lights up. If you press the button at the right moment, you'll gain a point. If you press the button at the wrong time, you'll lose a point.

How to Play:

  1. Adjust the Speed: Turn the potentiometer to set the speed of the LED chaser. Want a challenge? Try increasing the speed each time you play!
  2. Watch the Serial Monitor: A color will appear, wait for the LED of that color to light up.
  3. Press the Button: Press the button only when the correct LED is lit.
  4. Correct Press = +1 point
  5. Incorrect Press = -1 point
  6. Scoring:
  7. Reach 5 points to win (Victory song)
  8. Drop to -5 points to lose ( Lost song)



Supplies

The components you will need for this project are listed below with links, if you need to buy any components. Please click on the link and purchase the items through Amazon.

1x Piezo Buzzer

1x Arduino UNO

1x Breadboard

1x 555 timer

1x 4017 (Decade Counter )

1x Potentiometer

1x Button

1x 330 Ω Resistor

1x 10k Ω Resistor

1x 47k Ω Resistor

1x Polarized Capacitor

6x LEDs (2 Red, 2 Green, 2 Yellow)

Wires

Start Wiring on the Breadboard

20250610_101503.jpg

After gathering all the necessary components needed, start adding them to the breadboard shown in the image, or you can use the reference of the TinkerCAD schematic to help you understand the wiring of the components.

Connection to the Ardiuno

20250616_103815 (1).jpg
20250617_084704.jpg

Since we have completed Step 1, which helps show the basic wiring of the circuit, let's move on to completing the remaining wire towards the Arduino.


1) Push Button

Begin by wiring the push button. Connect the left leg of the button to the positive rail of the breadboard and the right leg of the button to Arduino pin 2. On the opposite side of the button, connect a 10k ohm resistor on the same side of the wire going to pin 2 to limit the current flowing into the Arduino, protecting it from any damage.

2) 555 Timer Setup

Connect the negative side of the capacitor to the ground pinout (pin 1) of the 555 timer, and the positive side of the capacitor should be wired to the trigger pin (pin 2). Provided ground to the 555 timer by connecting pin 1 to the GND and connecting power to the 555 timer by connecting pin 8 to the PWR. Connect the trigger (pin 2) to the threshold (pin 6) and the reset (pin 4) to the power ground (pin 8). Lastly, connect the output pin (pin 3) to the 4017 IC clock (pin 14).

3) Potentiometer Connection

Wire the wiper pin to the threshold of the 555 timer (pin 6) to the potentiometer, and wire terminal 1 to the discharge pin (pin 7) of the 555 timer. This allows the potentiometer to take control of the speed of the LEDs, allowing it to increase or decrease the difficulty of the game.

4) 4017 Decade Counter Wiring

Wire PWR (pin 16) and reset (pin 15) of the decade counter to PWR and GND on the breadboard. Connect the 555 timer’s output (pin 3) to the clock pin (pin 14) of the counter. Wire GND to the 4017 decade counter (pin 8). The clock pin controls the sequential output needed to make the LEDs flash in order. Then, connect Arduino pins 13 through 8 to the output pins of the counter, ensuring the LEDs will light in sequence from left to right.

5) LED Wiring

Connect the LEDs to the 4017 pins 1,2,3,4,5,7. The negative of the LEDs should be connected to 330 ohms, which is connected to ground. The positive side of the LEDs should be connected to the 4017 decade counter.


This finishes the wiring portion of the game. Now let's go to the coding part of the game.


Code

Screenshot 2025-06-16 212211.png

Start by declaring the variables, as this is the most crucial part of the code.

Declare led1-6: All of the LEDs in the circuit

Declare the button: The pin connected to the push button

Declare the score: Tracks the player's score

Declare randColour: Provides the player's random colour selected by the program.

Declare InitialMesssage: Ensure the welcoming message is displayed only once.

Code the Void Setup Function

Screenshot 2025-06-16 212848.png

Set up function

  1. Initialize the serial. begin communication
  2. Initialize the pinMode, allowing the LEDs to be set as input
  3. Initialize the button is configured as INPUT_PULLUP, declaring it as active low
  4. Welcoming message for the players explaining the game's rules and only displaying once on the serial monitor

Set Up Void Loop Function

Screenshot 2025-06-16 213338.png
Screenshot 2025-06-16 213410.png
Screenshot 2025-06-16 213433.png

Set up Void Function:

  1. Button Press: The program waits for the button to be pressed and selects a random color (randColour).
  2. LED Control: Turns off all LEDs, then lights up the LEDs corresponding to the randomly selected color (Red, Green, or Yellow).
  3. Score Calculation: Compares the player's action to the expected color
  4. Win/Lose Conditions: Ends the game if the score reaches 5 (win) or -5 (lose), then resets the score.
  5. Delays and Waiting for Input: Adds short delays to debounce the button and allow time for the player to react.
  6. Buzzer: Depending on your Win/Lose conditions, if you win plays a victory tone, or a loss tone if you lose.


Code

Here is the code all together, just in case if you miss anything.

Tutorial Video

This video showcases how the game should function. Enjoy the game and have fun!