LED Chaser Game


Hi, my name is karanveer sharma and on this instructable, i will be presenting my final project. This project is an interactive reaction-time game (LED chaser) that combines Arduino programming with digital circuitry. The game begins when a player places their hand in front of the ultrasonic distance sensor, switching the 7-segment display from a blinking pattern to score-counting mode. The LED chasing effect is independently controlled by a 555 timer and decade counter circuit, creating a continuous light sequence. Through the Arduino serial monitor, players receive instructions about which colored LED to target (red, green, or yellow) and must press the button precisely when that color lights up. The Arduino monitors both the LED states and button presses, updating the 7-segment display with the player's score and triggering a victory buzzer tone when they reach the target score.
Supplies

1. 555 Timer x1
2. Johnson's Decade Counter x1
3. Arduino Uno x1
5. Potentiometer (10k) x1
6. Assorted LEDs (Preferably red, green and yellow to make the project easier to complete) x7
7. Pushbutton x1
8. Resistors (3x 330Ohms, x1 10K Ohms)
9. Electrolytic Capacitor (10 uF) x1
10.ultrasonic distance sensor (1x)
11. Wires
12.buzzer (1x)
Research and Inspiration
This LED Chaser game was inspired by a YouTube video titled "LED Chaser circuit using 555 timer + 4017 IC on Breadboard" (https://youtu.be/_sSQuf6JXhk?si=ggzhM-hOCTghf8pj). The video shows a simple LED chaser effect using basic electronics. I used this as a starting point and added more features to make it a game.
For sound effects, I used the classic Mario victory tune from the website princetronics.com as inspiration. I shortened and simplified the tune to fit the game better, making sure it was my own version and not just a copy.
This project helped me learn how to combine sensors, lights, sound, and user input with Arduino to create a fun and interactive game.
Step by Step Physical Build



Power Supply Setup
Begin by establishing the power distribution for your circuit. Connect the Arduino's 5V output to the breadboard's positive rail and the GND pin to the negative rail. Use jumper wires to link both sides of the breadboard, ensuring consistent power and ground access throughout your build. This foundation will power all subsequent components.
555 Timer Configuration
The LED chaser circuit begins with the 555 timer. Insert the IC into your breadboard and connect Pin 1 to ground and Pin 8 to 5V. Link Pins 2 and 6 together, and connect Pin 4 to VCC to keep the timer active. Install a 10kΩ potentiometer between Pins 7 and 8, with its wiper connected to Pin 6 for speed control. Complete the timing circuit by adding a 10μF electrolytic capacitor between Pin 2 and ground. The output signal from Pin 3 will drive our LED sequence.
Decade Counter and LED Array
The 4017 decade counter receives the 555's output at Pin 14 (Clock). Provide power to Pin 16 and ground Pin 8, while connecting Pins 15 (Reset) and 13 (Clock Enable) to ground to enable counting. Wire the first seven outputs (Pins 1-7) to your LED anodes in your chosen color sequence (red, green, yellow, red, green, yellow, red). Install 330Ω current-limiting resistors between each LED cathode and ground to complete the chaser circuit.
Pushbutton Integration
Mount the tactile pushbutton on your breadboard. Connect one side to Arduino Pin 3 through a 10kΩ pull-down resistor to ground, with the opposite side wired to 5V. This configuration ensures clean signal detection when pressed, allowing the Arduino to register your timing attempts during gameplay.
7-Segment Display Implementation
The common anode 7-segment display requires proper power distribution and segment control. The display uses a single current-limiting resistor on its common anode line while each segment connects individually to the Arduino's digital and analog pins. The complete wiring configuration is as follows:
Common Anode → 5V through 330Ω resistor
Segment A → Arduino Pin 5
Segment B → Arduino Pin 4
Segment C → Arduino Analog A2
Segment D → Arduino Analog A1
Segment E → Arduino Analog A0
Segment F → Arduino Pin 6
Segment G → Arduino Analog A3
This setup enables the Arduino to control each segment independently while maintaining safe current levels through the entire display. The seven segments illuminate in specific patterns to clearly show the player's current score from zero to five points.
Ultrasonic Sensor Installation
The HC-SR04 distance sensor connects to both power and signal pins for accurate distance measurement. The sensor's wiring implementation uses the following connections:
VCC → 5V power rail
GND → Shared ground
Trig → Arduino Analog A4
Echo → Arduino Analog A5
This sensor serves as your game starter, detecting when a player's hand comes within 10cm to initiate a new round.
Buzzer Attachment
Complete your feedback system by connecting the piezo buzzer's positive lead to Arduino Pin 2 , with the negative lead to ground. This will provide audible victory feedback when players reach the target score.
In the image below, you can see where the pins are connected. In the connected pins, you might notice that some pins are connected to the output. These pins are connected to the output on the decade counter, to receive a pulse to compare with the button. It's with this that we will be able know when to add the score, by comparing the LEDs and the pushbutton.
Image of Arduino Pin Connections

Coding Part 1 : Variables

In Part 1, we set up all the variables and pin connections needed for the game. We define which Arduino pins are connected to the LEDs, the 7-segment display, the button, the distance sensor, and the buzzer. We also create variables to track the game score, whether the game has started, and which target colour is randomly chosen (Red, Green, or Yellow). At the end, we define the notes for the Mario victory tune using #define, which will be used later when the player wins. The idea and code for the Mario tune were taken from princetronics.com. This setup is like giving the Arduino a map of all the parts it will control during the game.
Part 2 – Setup Function: Preparing the Game

In the setup() function, we prepare everything before the game starts. We begin by starting the Serial Monitor so we can display messages to the player. Then, we set the modes for each pin — the LEDs are set as inputs because we’re checking their state later, and the segments of the 7-segment display are set as outputs so we can light up numbers. The distance sensor’s trigger is set as an output and the echo as an input. The button and buzzer are also set up properly. We also use randomSeed() to make sure the random target color is different each time. Finally, a welcome message is printed to guide the player to place their hand in front of the sensor to start the game.
Part 3 – Game Start Using Distance Sensor

Inside the loop(), the game waits for the player to place their hand close to the distance sensor (within 10 cm). When this happens, a message is printed to tell the player that the game is starting. We use the trigPin and echoPin to measure distance. Once a hand is detected, the score is displayed on the 7-segment display, and an intro message explains how to play. This only happens once using the initialMessage variable. If no hand is detected, the display blinks the score to show that the game is waiting to start.
Part 4 – Button Press and Scoring


When the player presses the button, the game checks if the correct LED (matching the target colour) is lit up at that moment.
- Red LEDs: led1, led4, led7
- Green LEDs: led2, led5
- Yellow LEDs: led3, led6
If the button was pressed when the correct LED was on, the score increases by 1 and a message is shown.
If it was wrong, the score stays the same.
Once the player reaches 5 points, the Mario victory tune plays using the buzzer. After that, the game resets and waits for a new hand to be detected.
To keep the game interesting, the target colour changes after each press, but it’s never the same colour two times in a row.
Part 5 – -Segment Display: Showing the Score


This part of the code controls the single-digit 7-segment display, which shows the current score (from 0 to 5). Each number lights up specific segments to form the correct digit.
Each segment (a to g) is connected to an Arduino pin:
- a = 5
- b = 4
- c = A2
- d = A1
- e = A0
- f = 6
- g = A3
To display numbers, we turn certain segments LOW (on) and others HIGH (off). This is because the display is a common anode, so segments light up when the pin is set to LOW.
Main functions used:
- displayScore(x) chooses which digit to show.
- Functions like zero(), one(), two()... light up the right segments for each number.
- clearDisplay() turns off all segments by setting them HIGH.
The score updates on the display every time you press the button. It also blinks while waiting for your hand to start the game.
Part 6 – Buzzer (Mario Victory Tune)

For the buzzer, i wanted a fun and satisfying sound to play when the player wins. i chose a short version of the Mario victory tune.
Where it came from:
i used the full Super Mario theme code from this website:
👉 https://www.princetronics.com/supermariothemesong/
That code is way longer and includes both the overworld theme and the level complete (victory) tune.
How i simplified it :
- only kept the victory part (not the whole theme).
- removed the intro and extra notes to make it shorter and simpler.
- used only a few important notes that still sound familiar (like E7, C7, G7, G6).
- used a smaller melody[] array and noteDurations[] array.
- kept the basic tone() and noTone() functions but made the timing easier to read.
my version plays when the score reaches 5. It celebrates the win and makes the game more fun and rewarding.
So even though i used the original site for inspiration, i shortened and changed it myself to match my project goals
Full Code
Demonstration
after the game starts by placing the hand in front of the distance sensor , the serial monitor tells you which colour to press on / which LED to chase . And its a different coloured LED everytime. Once you earn 5 points . you win , and a victory music/tone comes from the buzzer. if u want to play again, you simply place your hand in front of the distance sensor again and play :)