This is a simple obstacle avoidance game based on Arduino. The game features a player (represented by 'P') that can jump between the first and second row of an LCD screen, and obstacles (represented by 'O') that move from right to left on the screen. The objective is to avoid collisions with the obstacles.
- Arduino UNO board
- LCD1602 display or HD44780
- Push button
- 2、10kΩ resistor
- Breadboard and jumper wires
- USB cable to connect Arduino to a computer
- Connect the LCD1602 or HD44780 Display:
- Connect the VSS pin to Arduino GND.
- Connect the VDD pin to Arduino 5V.
- Connect the VO pin to the A0 pin through a 2kΩ potentiometer to adjust contrast.
- Connect the RS pin to Arduino pin 12.
- Connect the RW pin to Arduino GND.
- Connect the EN pin to Arduino pin 11.
- Connect the D4 to D7 pins to Arduino pins 5, 4, 3, and 2 respectively.
- Connect the A pin to Arduino 5V and the K pin to Arduino GND to light the backlight.
- Connect the Push Button:
- Connect one end of the button to Arduino pin 7.
- Connect the other end to Arduino 5V through a 10kΩ resistor.
- Connect the middle terminal of the button to Arduino GND.
Programming the Arduino:
The provided code handles the game logic, player movement, and obstacle generation. To upload the code to your Arduino board, follow these steps:
- Open the Arduino IDE on your computer.
- Copy the provided code and paste it into a new sketch.
- Select the correct Arduino board and port in the IDE.
- Click the "Upload" button to compile and upload the code to the Arduino board.
- Power On:
- Connect the Arduino board to your computer via the USB cable and power it on.
- Game Initialization:
- The LCD will display "Avoid Obstacles!" for 2 seconds before clearing the screen.
- Playing the Game:
- Press and hold the button to make the player jump to the opposite row.
- Release the button to return the player to the original row.
- Obstacles will appear randomly in the rightmost columns of the first and second rows and will move leftward.
- The game ends if the player and an obstacle occupy the same column.
- Game Over:
- If a collision occurs, the LCD will display "Game Over!" for 2 seconds before resetting the game.
- Restarting the Game:
- After the game is over screen, the game will automatically reset, and you can start playing again.
Simulate Online- https://www.pcbx.com/sim?id=581b7cb04f9f4aa8a5f8ddfc04efdf5c&type=share
Learn more free online simulation projects at PCBX- https://www.pcbx.com/forum?mtm_campaign=E&mtm_kwd=hack
Comments
Please log in or sign up to comment.