The Dinosaur Game (also known as the Chrome Dino Game) is a simple endless runner game built into Google Chrome. It appears when there is no internet connection and features a pixelated T-Rex dinosaur that runs through a desert landscape, avoiding obstacles like cacti and flying pterodactyls.
Game Concept
The player controls a T-Rex that automatically runs from left to right.
The main objective is to jump over obstacles by pressing the spacebar (or tapping on mobile).
The game gradually increases in speed, making it more challenging over time.
The game ends if the dinosaur collides with an obstacle.
This project replicates the Google Chrome Dinosaur Game using an Arduino UNO, a push button for controls, and a 16x2 LCD I2C screen for the display.
- The LCD screen displays a simplified version of the Dino Game using text-based graphics.
- The dinosaur (Dino) automatically moves forward on the screen.
- Obstacles (cacti) appear randomly and move from right to left.
- The player must press a push button to make the dinosaur jump over obstacles.
- If the dinosaur collides with an obstacle, the game ends, and the score is displayed.
Initialization
The LCD screen is initialized using the I2C interface.
The custom character set is loaded to represent the dinosaur and obstacles in a simple pixel form.
The button pin is set as an input with a pull-down resistor to detect button presses.
The game loop continuously performs the following actions:
Move the obstacles:
Cacti are randomly generated and move from right to left.
If an obstacle reaches the leftmost side of the screen, it disappears.
Check for Jump Input:
If the push button is pressed, the dinosaur jumps.
A simple animation effect moves the dinosaur up and then back down.
Collision Detection:
If the dinosaur is on the ground when an obstacle reaches it, a collision is detected.
The game ends and displays a "Game Over" message.
Score Calculation:
Each successfully avoided obstacle increases the score.
The score is displayed in the top-right corner of the LCD screen.
Arduino UNO
It controls the game logic, reads input from the button, updates the LCD display, and manages the score.
LCD I2C Display
It displays the dinosaur, obstacles, and game score using custom characters.
Push Button
It Allows the player to make the dinosaur jump.
Buzzer
It generates sounds for jumping and collisions.
Jumper Wires
Jumper wires will be used to make connections between the components.
Breadboard:
A breadboard can be used to create a temporary circuit for testing and prototyping.
LCD I2C screen→ Arduino UNO
- SDA → A4 analogic pin
- SCL → A5 analogic pin
- VCC → 5V
- GND → GND
Push Button→ Arduino UNO
- Connect one leg of the push button to pin 5 of the Arduino.
- Connect another leg of the push button to the 5V pin of the Arduino.
- Place a 10k Ohm resistor between the third leg of the push button and the GND pin of the Arduino.
Buzzer → Arduino UNO
- Connect the positive pin to a digital output pin (e.g., D3) on Arduino.
- Connect the negative pin to GND.
Here’s an example Arduino code to implement this game:
You must install this library "LiquidCrystal_I2C".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> #define BUTTON_PIN 2 // Push button on D2 #define BUZZER_PIN 3 // Buzzer on D3 LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD 16x2 with I2C address 0x27 int dinoPosition = 0; // 0 = ground, 1 = jumping int obstaclePosition = 15; // Start obstacle at the rightmost side int score = 0; bool gameOver = false; void setup() { pinMode(BUTTON_PIN, INPUT_PULLDOWN); // Button input with pull-down resistor pinMode(BUZZER_PIN, OUTPUT); lcd.init(); lcd.backlight(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Dino Game Start!"); delay(1000); lcd.clear(); } void loop() { if (!gameOver) { lcd.clear(); // Check for jump input if (digitalRead(BUTTON_PIN) == HIGH && dinoPosition == 0) { dinoPosition = 1; // Jump tone(BUZZER_PIN, 1000, 200); // Play jump sound } // Display dinosaur lcd.setCursor(0, 1 - dinoPosition); lcd.print("D"); // "D" represents the dinosaur // Display obstacle if (obstaclePosition >= 0) { lcd.setCursor(obstaclePosition, 1); lcd.print("C"); // "C" represents the cactus } // Collision detection if (obstaclePosition == 0 && dinoPosition == 0) { lcd.clear(); lcd.setCursor(4, 0); lcd.print("Game Over!"); tone(BUZZER_PIN, 200, 500); // Collision sound gameOver = true; delay(2000); return; } // Move obstacle obstaclePosition--; if (obstaclePosition < 0) { obstaclePosition = 15; // Reset obstacle position score++; // Increase score } // Display score lcd.setCursor(12, 0); lcd.print("Score:"); lcd.print(score); // Dino falls back after jumping if (dinoPosition == 1) { delay(300); dinoPosition = 0; } delay(200 - (score * 5)); // Speed increases with score } } |
How the Code Works
Initialization: Sets up LCD, button, and buzzer.
Game Loop: Moves obstacles, detects jumps, checks collisions, and updates score.
Collision Handling: Ends game if the dinosaur hits an obstacle.
Dynamic Speed: The game becomes harder over time.
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info