LED Chaser Game With 555 & 4017

by adhillon in Circuits > Arduino

23 Views, 1 Favorites, 0 Comments

LED Chaser Game With 555 & 4017

Arv led chaser.png
IMG_1978.jpeg

Welcome to my project! Today I will be showing you how to make a LED Chaser Game, and in this game there will be a line of LED's that flash like they are chasing eachother. This is where the term LED Chaser comes from. The game revolves around a specific color being told, and you have to click the button, when the LED corresponding to the color turns on. This will grant you a point, and if you press the button when the LED is not on, you will lose a point.

How to Play! :

  1. Turn the potentiometer to your desired speed, challenge yourself and try a faster speed each time you win!
  2. On the Serial Monitor, a color will be listed. You need to click the button when the color specified LED is on, if you click it succesfully you will hear a beep. This means you gain a point
  3. If you fail to click the button on the right color, you will lose a point
  4. -5 = Lose & 5 = Win

Supplies

Gather Supplies and Place Them on Breadboard

IMG_1951.jpeg

After you have gathered your supplies, place them on the breadboard in the places that I have shown, you can also use the circuit schematic built on TinkerCAD to help you with the entire process of building the circuit.

Wiring

IMG_1959.jpeg

For my wiring, I like to go from left to right, so that means we are going to begin with the push button.

For the Push Button, make sure that one side is connected to 5V and Arduino Pin 4, but make sure the other side has a resistor opposite to the arduino pin wire, this is because we need to have a resistor to prevent too much current going into the arduino, which can fry it.

For the Buzzer, just wire the GND end to Ground, and the positive side (anode) to the Arduino Pin to pin 2, so we can control when we want it to beep with our code.

Wiring Continued

Arv led chaser_page-0001.jpg

Now that we have completed Step 2, which helps show some of the basic wires, let's move on to completing the circuit wiring. Our goal is to have LEDs flash in sequence, with the speed of the flashes controlled by a potentiometer.

1) Push Button Wiring

Start by connecting the push button to the Arduino. Wire one side of the button to an Arduino input pin and the other side to PWR and GND on the breadboard, using resistors as needed. At this stage, also ensure that both ends of the breadboard have PWR and GND connections to establish full connectivity across the circuit.

2) Capacitor and 555 Timer Setup

Connect the capacitor to the 555 timer. The capacitor's negative pin should be wired to the GND pinout (pin 1) of the timer, while the positive pin connects to the trigger (pin 2). Since the trigger is active low, the timer will start when the voltage on pin 2 drops below 1/3 of the supply voltage.

3) Configuring the 555 Timer

Using the "Astable" 555 timer configuration shown in the diagram, wire PWR and GND to the timer. Connect the trigger (pin 2) to the threshold (pin 6) and the reset (pin 4) to power (pin 8). In this configuration, the timer generates a square wave, with the frequency adjustable using two resistors and a capacitor connected to the chip.

4) Potentiometer Connection

Wire the wiper pin of the potentiometer to the threshold (pin 6) and connect terminal 1 to the discharge pin (pin 7) of the 555 timer. This setup allows you to adjust the speed of the LED flashes, providing control over the difficulty of the game.

5) Connecting the Decade Counter

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. 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.

6) LED Wiring

Connect the counter's output pins to the anodes of the LEDs in order (e.g., output 1 to the Red LED, output 2 to the next, and so on). Use a shared 330-ohm resistor to connect the cathodes of all six LEDs to GND. This completes the LED circuit.

There you go! The circuit wiring is now complete. But we’re not done yet, let’s move on to writing the code to bring it to life!

The Code!

image.png

Let's now begin coding! The Code is a crucial step and the game itself won't even work if we don't have code, so lets start with the Variable Declaration.

led 1-6: All of the Led's in the circuit.

button: The pin connected to the push button.

score: Tracks the player's score.

randColour: Holds the random color selected by the program.

initialMessage: Ensures the welcome message displays only once.

Setup Function Code

image (1).png

Setup Function

  1. Initializes serial communication and configures the pin modes:
  2. LEDs are set as INPUT because they are controlled by the 4017 IC.
  3. The button is configured as INPUT_PULLUP, meaning it is active LOW.
  4. A welcome message explains the game rules and displays once when the program starts.

The Loop Function

image (2).png
image (3).png
  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.

Enjoy!

Engineering Final Evaluation - Arveer

Now from these steps you should be ready to play! Enjoy the game and challenge yourself!

I won't take any more of your time now, have fun!