Arduino LED Chaser Game | Use of 555 Timer & 4017 Counter
by ErtanR in Circuits > Arduino
713 Views, 7 Favorites, 0 Comments
Arduino LED Chaser Game | Use of 555 Timer & 4017 Counter

Welcome to my project! In this tutorial, I'll walk you through building a fun LED chaser game that combines Arduino code with the 555 timer and 4017 decade counter.
The idea behind the game is simple but addictive. A line of LEDs chases in sequence, and a random colour (blue, red, or yellow) lights up on an RGB LED. Your goal? Press the button when the LED on the chaser matches the colour shown on the RGB LED! Sounds easy? Well, a potentiometer controls the speed, so you can make the game harder or easier depending on your reflexes.
You’ll be scored as you play. The Serial Monitor shows your points. Hit the right LED at the right time, and you earn a point. Miss it, and you lose one. Reach 5 points and you win. Drop to -5 and it's game over. The game resets automatically every time you win (or lose), so you can keep playing and challenging yourself!
Now that you know what this project does and what it’s all about, let’s get started with the materials you’ll need.
Supplies

- 1x Arduino Microcontroller
- 1x Breadboard
- Colored Jumper Wires (Red, Black, Blue, Yellow)
- 6x LEDs (2x Blue, 2x Red, 2x Yellow)
- 1x RGB LED (Common Anode)
- 1x Push Button
- 1x 555 Timer
- 1x 4017 Decade Counter
- 1x Potentiometer
- 5x Resistors (2x 330Ω,1x 1KΩ, 2x 10KΩ)
- 1x Capacitor (100µF, 10V)
Research & Creation of Schematic
.jpeg)
As I began researching what to create for my final project, I found inspiration from many Instructables users who had created an LED Chaser game. I specifically took inspiration from this project that I came across.
I loved the idea of building an LED chaser game, which is designed for entertainment purposes and testing reaction time skills. I wanted to put my own twist on it. Instead of using a 4-digit 7-segment display as a score system, I used an RGB LED to show the target colour and kept track of the score through the Serial Monitor instead. I also simplified the layout by using fewer LEDs, making the circuit cleaner (only requiring 1 breadboard) while keeping the gameplay just as fun and addictive in my way.
The image above is the schematic that I created for myself to follow as I built my project. Refer to this schematic if you ever feel stuck or need a quick reference while following the steps!
Red = 5V | Black = GND | Blue = Connections | Yellow = Arduino Pins
Creating the Base

Focus: Building the foundation of the circuit.
By the end of this step, your breadboard should look like the image above!
1) Connect Power & Ground Rails
Connect the 5V pin on your Arduino to the + rail of your breadboard. Connect a GND pin on your Arduino to the – rail of your breadboard. Use jumper wires to extend power and ground rails to both sides of the breadboard.
2) Wire Pushbutton
Insert the pushbutton so that each leg sits on a separate row across the breadboard gap. Connect one leg to the 5V rail. The leg directly across from it should connect to a jumper wire that goes to digital pin 2 on the Arduino. But for now, place a 10kΩ resistor between that same leg connecting to the GND rail.
3) Wire RGB LED
This RGB LED is common anode, which means the longest leg needs to be connected to power, not ground. Insert the RGB LED into the breadboard with each leg on a separate row. Connect a 330Ω resistor from the 5V rail to the longest leg (common anode) to safely supply power. Later, you will need to connect the remaining three legs to their corresponding Arduino pins using jumper wires. (Red - Pin 9, Green - Pin 10, Blue - Pin 11)
4) Wire 6x LEDS
You’ll be using 6 individual LEDs for the LED chaser (2 blue, 2 red, 2 yellow). For now, we’ll wire only their ground side. The signal side will be connected later in the next step. Insert each LED into the breadboard, keeping their legs on separate rows. Make sure the longer leg (anode) is facing toward the side that will later connect to the 4017 counter outputs (leave these unconnected for now). Connect the shorter leg (cathode) of each LED to a row that can be linked to ground. Use jumper wires to connect all cathodes of the LEDs and route them through a single 330Ω resistor going to the GND rail on the breadboard.
5) Wire 555 Timer
Insert the 555 timer IC onto your breadboard. Connect the power pin (pin 8) to the 5V rail and the ground pin (pin 1) to the ground rail. Insert the potentiometer near the 555 timer (this will be used later to adjust the speed of the timer’s output pulse)
6) Wire 4017 Decade Counter
Insert the 4017 decade counter onto the breadboard. Connect the power pin (pin 16) to the 5V rail and the ground pin (pin 8) to the ground rail. Connect the clock enable pin (pin 13) and reset pin (pin 15) to ground to enable normal counting operation.
NOTE: Make sure to refer to the schematic diagram to confirm the correct orientation and pin numbering! Always place the notch or dot on the chips facing forward as shown in the schematic.
Finalizing the Circuit

Focus: Getting the LEDs to follow in order & the potentiometer to adjust its speed.
By the end of this step, your circuit will match the video above!
1) Adding the Capacitor
Connect the negative (shorter) leg of the 100µF, 10V capacitor to the ground (GND) rail on your breadboard. Then, connect the positive (longer) leg to pin 2 of the 555 timer.
2) 555 Timer & Resistor Connections
Start by connecting pin 8 of the 555 Timer directly to pin 4 (this ensures the timer is always active). Then connect pin 2 of the 555 Timer directly to pin 6 (allows the 555 timer to operate in astable mode, continuously generating pulses). Connect a 1KΩ resistor to power, and its opposite side to pin 7 of the 555 Timer. Finally, connect one side of a 10KΩ resistor to pin 2, and the other to pin 7 of the chip.
3) Connecting the Potentiometer
Connect the wiper (middle) leg of the potentiometer to pin 6 of the 555 timer. Then, connect one outer terminal (side leg) of the potentiometer to pin 7 of the 555 timer. This configuration allows the potentiometer to control the charging time of the capacitor, which adjusts the LED chaser speed.
4) Connecting the 4017 Decade Counter to the 555 Timer
Connect the output pin 3 of the 555 timer to the clock input pin 14 of the 4017 decade counter.
5) LED Outputs
Connect the anode (positive) leg of each LED to the 4017 counter output pins.
Pin 3 = LED 1 | Pin 2 = LED 2 | Pin 4 = LED 3 | Pin 7 = LED 4 | Pin 10 = LED 5 | Pin 1 = LED 6
(see schematic above for pin numbering and correct orientation)
Wiring Arduino Digital Pins

Focus: Connecting the Arduino Board - To begin coding on Arduino Software
Power & Ground
5V → Breadboard + rail
GND → Breadboard – rail
RGB LED (Common Anode)
Red leg → Pin 9
Green leg → Pin 10
Blue leg → Pin 11
Pushbutton
Opposite / Across from powered leg → Pin 2
4017 Output
Pin 3 (LED1) → Pin 4
Pin 2 (LED2) → Pin 7
Pin 4 (LED3) → Pin 5
Pin 7 (LED4) → Pin 3
Pin 10 (LED5) → Pin 13
Pin 1 (LED6) → Pin 8
Declaring & Initalizing Through Code

At the very top of your code, you will need to initialize all of your variables. By initializing the variables, you’ll be able to control the pins of the Arduino and manage how your components interact in the game. All of the variables with “led” in them are connected to the outputs of the 4017 decade counter (these are the LEDs that will light up in sequence). The variables with “redPin,” “greenPin,” and “bluePin” are used to control the RGB LED colours. The “button” variable is linked to the pushbutton input. The remaining variables are for the game logic. See the image above of all the variables used for your program.
Setup Function

Now that all of your variables are initialized, you need to set them as either inputs or outputs so the Arduino knows how each pin should behave. You can do that using this line of code:
pinMode(variableName, INPUT); or pinMode(variableName, OUTPUT);
In this project, all of the LED variables (led1 to led6) are connected to the outputs of the 4017 decade counter. Since those pins are receiving pulses, they need to be set as inputs. This way, the Arduino can detect when a specific LED is on. Next, you have the RGB LED pins (redPin, greenPin, and bluePin). These pins are sending signals to light up different colours, so they need to be set as outputs. The pushbutton is also receiving input from a press, so that pin (button) should be set as input as well.
At the bottom of the setup() function, you’ll see randomSeed(analogRead(0));
This line ensures the random colour selection later in the game picks different colours each time the game runs. By writing this setup function, you are activating all of your components and getting the game ready to begin. Now that this part is complete, we can move on to the main part of the code, the loop() function.
Main & Looping Function




The loop() function runs continuously while the Arduino is powered on. First, it creates an array with all the LED pins so it can easily check each LED to see which one is currently lit. It does this by reading the state of each LED pin, and when it finds the one that is HIGH (on), it saves that LED’s position in the variable currentLed. Then, it reads the state of the pushbutton to see if it is pressed.
When the button is pressed, the code compares the colour of the currently lit LED to the target colour the player is trying to match on the RGB LED. If the colours match, the player’s score increases by one, and a “Correct! +1” message prints in the Serial Monitor. If the colours don’t match, the score decreases by one, and a “Wrong! -1” message appears. The updated score is then shown on the Serial Monitor. If the player reaches a score of 5, they win, and the game resets. If the score reaches -5, they lose, and the game also resets, generating a new random target colour to display on the RGB LED for the next round.
Beyond the loop(), there are several helpful functions. The setColor() function controls the RGB LED to display the target colour that the player must match. Because it’s a common anode LED, it uses specific values (inverted of common cathode) in analogWrite() to turn the red, green, and blue pins on or off (to show blue, red, or yellow colours).
The pickNewColor() function randomly chooses the next target colour and updates the RGB LED to show that colour. It also prints the chosen colour and instructions to the Serial Monitor, so the player knows what to do next.
The getColorFromIndex() function takes the position of the lit LED and returns its colour as a string, matching specific LED positions to blue, red, or yellow. Similarly, the getTargetColor() function converts the random target colour number into a colour name string for the comparison in the game.
The resetGame() function resets the player’s score to zero, pauses briefly to let the player get ready, and then picks a new target colour to start a fresh round. It also prints messages to the Serial Monitor informing the player about the reset.
Lastly, the welcomeMessage() function runs once at the start to print the game’s instructions and rules to the Serial Monitor, helping the player understand how to play.
A copy of the code is attached for you to download!
Downloads
Demonstration
