LED Chaser Arcade Game

by 929312 in Circuits > Arduino

120 Views, 1 Favorites, 0 Comments

LED Chaser Arcade Game

IMG_0596.JPG

This LED Chaser Arcade Game project combines Arduino Uno with analog ICs, including NE555 and CD4017. It integrates hardware components such as LEDs, buttons, and score board to create an interactive game. Once initiated the goal is to hit the button when the green LED is on. For every time you hit the green LED you gain one point, for every time you hit a red LED while its on instead you lose -1 point. To win you must reach a score of 5, to lose you must reach a score -5. Using the potentiometer you can speed up or slow down the game.

Supplies

Screenshot 2024-01-24 11.33.19 PM.png
  1.  LCD Display: Price: $10.99/3pcs ($3.66 a piece)
  2. 1 Green LED: Price: $10.99 (pack of 500)
  3. 6 Red LEDs: Price: $10.99 (pack of 500)
  4. Button: Price: $5.99 (pack of 20)
  5. Potentiometer: Price: $7.99 (pack of 10)
  6. Arduino Uno: Price: $27.60
  7. Resistors: Price: $13.99 (pack of 1000 resistors)
  8. Capacitor 10uF: Price: $9.99 (pack of 240)
  9. Jumper Wires: Price: 6.98 (pack of 120)
  10. 555 Timer (NE555): Price: $5.99 (pack of 10)
  11. Johnson Decade Counter (CD4017): Price: $5.10 (pack of 5)

Total Cost: $30.45 (for the individual components within the set required for this project not for the entire set,)

Here is a link to the tinkercad basic circuit outline (without the LCD however)

Astable Mode With 555 Timer:

IMG_0561.JPG
IMG_0555.JPG
IMG_0560.JPG

Wire the 555 timer in astable mode:

  • Connect pins 2 and 6 to each other and to the ground.
  • Connect pins 4 and 8 to Vcc (5V).
  • Connect a resistor from pin 7 to Vcc.
  • Connect a capacitor from pin 6 to the ground.
  • Connect a potentiometer from pin 6 to Vcc for adjustable speed.

The 555 timer is configured in astable mode, generating a continuous square wave output. The potentiometer adjusts the rate of flashing by changing the delay.

Johnson Decade Counter:

IMG_0566.JPG
IMG_0564.JPG
IMG_0565.JPG

The CD4017 is a decade counter that advances one output at a time in response to clock pulses. It's used to sequence the LEDs in the chaser pattern.


Connect the Johnson Decade Counter (CD4017):

  • Wire the 10 outputs to the series of LEDs (Red, Red, Red, Green, Red, Red, Red).
  • In order from left to right the LEDS in the sequence shown above are connected to these corresponding pins on the decade counter in this order, Output 1, 2, 3, 4, 5, 6, 7.

Knight Rider Circuit:

IMG_0567.JPG
IMG_0586.JPG

Connect the 555 Timer with the Johnson Decade Counter:

  • Use the output of the 555 timer to clock the CD4017, creating a Knight Rider circuit effect.
  • (Note: Knight Rider circuit was the one I made on my PCB which this is heavily inspired by)

Button and LCD Display:

IMG_0598.JPG

Place a button on the breadboard:

  • Connect it to pin 4 on the Arduino.
  • Connect the green LED to pin 7.
  • Connect the LCD to A4 and A5. If no LCD is available, the text can be displayed on the serial monitor and be replaced in the code everywhere where it says lcd.print with serial.print.

Code Upload and Explanation

Screenshot 2024-01-24 9.52.11 PM.png
Screenshot 2024-01-24 9.51.56 PM.png
Screenshot 2024-01-24 9.51.33 PM.png
Screenshot 2024-01-24 9.51.12 PM.png

Summary:

This code initializes the necessary components, displays instructions on an I2C-based LCD, tracks the player’s score based on button presses and the state of the green LED, and handles win or lose conditions. The game loop allows continuous play, and the LCD provides feedback to the player throughout the game.



Step by Step how to create the Code


  1. Library Inclusion: #include <LiquidCrystal_I2C.h>: This line includes the LiquidCrystal_I2C library, which allows easy interfacing with the I2C-based LCD.
  2. Object Initialization: LiquidCrystal_I2C lcd(0x27, 16, 2);: Creates an object ‘lcd’ of type LiquidCrystal_I2C with the I2C address 0x27 and dimensions 16x2.
  3. Variable Declaration: int greenLed = 0; and int button = 0;: Declare variables to store the states of the green LED and the button.
  4. Initial Message and Score: int initialMessage = 0; and int score = 0;: Initialize variables for controlling the display of initial messages and tracking the player’s score.
  5. Setup Function: Serial.begin(9600);: Initialize serial communication at 9600 bps. pinMode(7, INPUT);: Set pin 7 as an input for reading the state of the green LED. lcd.init(); and lcd.backlight();: Initialize the LCD and turn on the backlight.
  6. Loop Function: while (initialMessage == 0): Display initial messages on the LCD until the player starts the game. button = digitalRead(4); and greenLed = digitalRead(7);: Read the state of the button and green LED. Check button presses and update the score based on the state of the green LED. Display the score on the LCD.Check for win or lose conditions and display corresponding messages. The loop continues to run, allowing the game to be played continuously.