T – REX DINOSAUR GAME
Mini Project Preliminary Report
submitted by
ADARSH K (MAC19EC005)
AKSHARA RAMESAN (MAC19EC011)
SARATH PRABHAKARAN (MAC19EC101)
TOM K MANGATTU (MAC19EC115)
to
APJ Abdul Kalam Technological University
in partial fulfillment of the requirements for the award of the Degree of
Bachelor of Technology
in Electronics and Communication
Department of Electronics and Communication Engineering
Mar Athanasius College of Engineering
Kothamangalam, Kerala, India 686 666
June 2022
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
ENGINEERING
MAR ATHANASIUS COLLEGE OF ENGINEERING
KOTHAMANGALAM
CERTIFICATE
This is to certify that the Project preliminary report entitled “T – REX DINOSAUR
GAME” submitted by Adarsh K (MAC19EC005), Akshara Ramesan
(MAC19EC011), Sarath Prabhakaran (MAC19EC101) and Tom K Mangattu
(MAC19EC115) to the APJ Abdul Kalam Technological University in partial
fulfillment of the requirements for the award of the Degree of Bachelor of
Technology in Electronics & Communication Engineering is a bonafide record of
the project preliminary work carried out. This report in any form has not been
submitted to any other University or Institute for any purpose.
Dr. Jinsa Kuruvilla Dr. Thomas George
Project Coordinator HOD, ECE Department
Date:
ACKNOWLEDGEMENT
In successfully completing this project, many people have helped us. We would
like to thank all those who are related to this project.
Primarily, we would thank God for being able to complete this project with
success. Then we thank Dr. Jinsa Kuruvilla, under whose guidance we learned a lot
about this project. Her suggestions and directions have helped in the completion of
this project.
Finally, we would like to thank our parents and friends who have helped me with
their valuable suggestions and guidance and have been very helpful in various
stages of project completion.
ADARSH K
AKSHARA RAMESAN
SARATH PRABHAKARAN
TOM K MANGATTU
1
CONTENTS
Sections Page No.
ACKNOWLEDGEMENT 1
ABSTRACT 5
LIST OF FIGURES 4
ABBREVIATIONS 5
CHAPTER 1 INTRODUCTION 7
CHAPTER 2 LITERATURE SURVEY 8
CHAPTER 3 METHODOLOGY 9
3.1 PROCEDURE ......................................... 9
3.1.1 DISPLAYING T-REX GAME ON OLED ................. 9
3.1.2 DETECTING THE HAND MOVEMENT . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1.3 WORKING OF THE GAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
CHAPTER 4 IMPLEMENTATION 10
4.1 BLOCK DIAGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 COMPONENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.1 ARDUINO UNO ................................... 11
4.2.2 OLED ..................................... 12
4.2.3 MPU6050 ..................................... 13
4.3 CIRCUIT DIAGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4 PCB SCHEMATIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.5 PCB LAYOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
CHAPTER 5 SOFTWARE DESCRIPTION 17
5.1 ARDUINO IDE ........................................... 17
5.2 ALTIUM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2
CHAPTER 6 RESULTS 19
CHAPTER 7 FUTURE SCOPE 20
CHAPTER 8 CONCLUSION 21
REFERENCES 22
APPENDIX A CODE 23
3
LIST OF FIGURES
No. Title Page No.
4.1 T – REX Game Image ............................. 7
4.2 Arduino Uno R3 ............................. 11
4.3 Oled Display ............................. 12
4.4 MPU6050 ............................. 13
4.4 Circuit Diagram .................................... 14
4.5 PCB Schematic .................................... 15
4.6 PCB layout ...................................... 16
6.10 PCB of our Project ................................ 19
6.11 Prototype of our Project .................................. 19
4
ABSTRACT
We created the famous dinosaur game in chrome using Arduino, oled display, and
mpu6050. The project requires images of dinosaur and tree. Convert the images to
byte array.
We display the dinosaur at center of the oled screen, tree is placed on right side.
One tree in placed at right outside the screen. We decrement the position of tree on
every loop, so the tree moves from left to right. When one tree reaches at left end
new tree is created at right end beyond the screen.
Dinosaur jumps when we tilt our hand. The mpu6050 contains of 3 – axis
accelerometer and 3 – axis gyroscope. We measure orientation in x axis if the
orientation change is greater than threshold we implements dinosaur jump.
If the x positon of any one tree and dinosaur is equal we check whether the
dinosaur is in jump state or not. If the dinosaur is in jump state we increment the
score else we exit the game
5
ABBREVIATIONS
Oled Organic Light Emitting diodes
I2C Inter-Integrated Circuit
6
CHAPTER 1
INTRODUCTION
T-REX DINOSAUR GAME is a browser game developed by Google and built
into the Google Chrome web browser. When a user attempts to navigate to a web
page on Google Chrome while being offline, the browser notifies the user that they
are not connected to the Internet, with an illustration of a pixelated Tyrannosaurus
rex shown on the page. The game can then be launched either by pressing space or
up arrow on desktop, or by tapping the dinosaur on Android or iOS mobile
devices.
We created T-REX game using Arduino, mpu6050, and oled display. We can
control the jump of the dinosaur by tilting out left hand.
T – REX Game Image
7
CHAPTER 2
LITERATURE SURVEY
[1] The T – Rex Game Chrome dino in Arduino using Oled Display by Harsh
Mittal
This article gives us information about working of the game. Article showed as
way how to convert png image to byte array for Arduino. We learned that the
dinosaur stays in same position and tree moves backward in the game.
[2] MPU 6050 Tutorial | How to Program MPU 6050 with Arduino by Mission
Critical
From this Blog, we learned how to wire and code MPU 6050 which is a 6 axis
Accelerometer, with Arduino Board. This paper contains detailed description about
MPU 6050 and about its pins. We figured out the connection with MPU6050 and
Arduino Uno from the Blog.
[3] 0.96 inch OLED Getting Started Guide by Arnov Sharma
The blog gives us idea about connection of oled display and Arduino Uno. Showed
us the wiring and the library to be used for oled display. We have to first find the
i2c address of oled display by using i2c scanner of Arduino.
8
CHAPTER 3
METHODOLOGY
3.1 PROCEDURE
3.1.1 DISPLAYING T – REX GAME ON OLED
Arduino can only read byte array not images. So to convert png image of
dinosaur to byte array we made use of online services (imagetocpp). Address
of Oled display is found using i2cscanner code. We added the image byte
array. Place the dinosaur on the center of the oled screen. Now place two
dinosaur on the oled screen, one on the right most side and other beyond the
oled screen. Make variables to store the position of two trees and the height
from base line of dinosaur. On each loop decrement the x position of trees so
the trees will go backwards. Thus we see as the dinosaur moving forward.
When a tree reach the left most point assign its positon to be beyond the
right side of the oled.
3.1.2 DETECTING THE HAND MOVEMENT
Place MPU6050 at out hand using band or glove. When we tilt our hand the
gyroscope in mpu6050 senses it and provides the angle to Arduino. We have
to set a threshold for the angle otherwise small movement will be interrupted
as hand gesture. When hand gesture is detected increment the height of the
dinosaur. When the dinosaur reaches a limit it starts to descent.
3.1.3 WORKING OF THE GAME
When x position of any tree and dinosaur is equal we check if the dinosaur is
in jumping state. If the dinosaur is not in jumping state we exit the game and
display the score. Else we increment the score.
9
CHAPTER 4
IMPLEMENTATION
4.1 BLOCK DIAGROM
MPU6050 Oled Display
Arduino
Push Button Buzzer
Battery
10
4. 2 COMPONENTS
4.2.1 ARDUINO UNO
Arduino Uno R3
The Arduino Uno is an open-source microcontroller board based on the Microchip
ATmega328P microcontroller and developed by Arduino.cc. The board is
equipped with sets of digital and analog input/output (I/O) pins that may be
interfaced to various expansion boards (shields) and other circuits. The board has
14 digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is
programmable with the Arduino IDE (Integrated Development Environment), via a
type B USB cable. It can be powered by the USB cable or by an external 9-volt
battery, though it accepts voltages between 7 and 20 volts. It is similar to the
Arduino Nano and Leonardo.
11
4.2.2 OLED
Oled Display
The organic light-emitting diode (OLED) display that we used is the SSD1306
model: monocolor, 0.96-inch display with 128×64 pixels. The OLED display
doesn’t require backlight, which results in a very nice contrast in dark
environments. Additionally, its pixels consume energy only when they are on, so
the OLED display consumes less power when compared with other displays. The
model we’re using here has only four pins and communicates with the Arduino
using I2C communication protocol.
12
4.2.3 MPU6050
MPU6050
The MPU-6050 is the world’s first and only 6-axis motion tracking devices
designed for the low power, low cost, and high performance requirements of
smartphones, tablets and wearable sensors. MPU6050 consists of Digital Motion
Processor (DMP), which has property to solve complex calculations. MPU6050
consists of a 16-bit analog to digital converter hardware. Due to this feature, it
captures three-dimension motion at the same time. This module uses the I2C
module for interfacing with Arduino.
13
4.3 CIRCUIT DIAGROM
Circuit Diagram
14
4.4 SCHEMATIC DIAGROM
PCB Schematic
15
4.5 PCB LAYOUT
PCB layout
16
CHAPTER 5
SOFTWARE DESCRIPTION
During the project work, to obtain sufficient results the system needs some
software. Software description gives the details about the software’s that are used.
5.1 ARDUINO IDE
Arduino is an open-source hardware and software company, project, and user
community that designs and manufactures single-board microcontrollers and
microcontroller kits for building digital devices. Its hardware products are licensed
under a CC BY-SA license, while software is licensed under the GNU Lesser
General Public License (LGPL) or the GNU General Public License (GPL),
permitting the manufacture of Arduino boards and software distribution by anyone.
Arduino boards are available commercially from the official website or through
authorized distributors.
Arduino board designs use a variety of microprocessors and controllers. The
boards are equipped with sets of digital and analog input/output (I/O) pins that may
be interfaced to various expansion boards ('shields') or breadboards (for
prototyping) and other circuits. The boards feature serial communications
interfaces, including Universal Serial Bus (USB) on some models, which are also
used for loading programs.
ADVANTAGES
don’t need to external programmer (Burner)
programming ease
open source in software
IDE Software operate on any operating system
17
5.2 ALTIUM
Altium Designer is a PCB and electronic design automation software package for
printed circuit boards. Altium Designer is a powerful design package that helps
simplify the design and development of electronics and printed circuit boards.
Altium Designer’s suite encompasses four main functional areas, including
schematic capture, 3D PCB design, field-programmable gate array (FPGA)
development, and release/data management. It integrates with several component
distributors for access to the manufacturer’s data. It also has an interactive 3D
editing of the board and MCAD export to STEP. Its products are designed for use
in a Microsoft Windows environment and are used in industries such as
automotive, aerospace, defense, and telecommunications.
Advantages
• Easily accessible to any document in the project from the projects panel. All of
the project documents are displayed to reflect the design structure.
• Can easily move back and forth between the schematic and the PCB. For
example, tasks such as moving design changes from the schematic to the board, or
from the board back to the schematic, are quick and non-intrusive.
• Schematic can be added to a PCB component class easily and can be repositioned
and aligned, or flipped to the other side of the board.
• It allows flicking back and forth from a 2D view of the board to a highly realistic
3D view. Whenever a mistake is detected, we can immediately switch to the
schematic to edit and automatically update the PCB.
18
CHAPTER 6
RESULTS
PCB of our Project
Prototype of our Project
CHAPTER 7
19
FUTURE SCOPE
In Future, we will try to increase the speed of the dinosaur as the game
progresses.
Also we will try to add different obstacles like birds to make the game more
interesting
At present we can only make dinosaur jump using hand gesture. Future we
like implement various other controls in hand. For example increasing the
dinosaur speed with hand gesture.
20
CHAPTER 8
CONCLUSION
T- REX Game can be used for entertainment. Our Mini Project can be used as
reference for motion tracking. Motion tracking is important in modern day
transportation systems also in UAVs. Quadcopter use mpu6050 or similar modules
to level themselves, also to move around. Ability to control devices using hand
gestures is also applicable in many areas. It will help handicapped people to do
their daily jobs easily. We can also detect sudden changes in acceleration or angle
using mpu6050 and detect a potential accident.
21
REFERENCES
[1] MPU 6050 Tutorial | How to Program MPU 6050 With Arduino
(https://create.arduino.cc/projecthub/MissionCritical/mpu-6050-tutorial-how-to-
program-mpu-6050-with-arduino-aee39a )
[2] 0.96 inch OLED Getting Started Guide
(https://create.arduino.cc/projecthub/Arnov_Sharma_makes/0-96-inch-oled-
getting-started-guide-78163a)
[3] The T-Rex Game (Chrome Dino) in Arduino using OLED Display
(https://create.arduino.cc/projecthub/harshmittal2210/the-t-rex-game-chrome-dino-
in-arduino-using-oled-display-be5bc5)
[4] Image2cpp a simple tool to change images into byte arrays
(https://diyusthad.com/image2cpp)
22
APPENDIX A
CODE
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050.h>
MPU6050 mpu;
#define switchPin 9
#define buzzer 8
// Defines
// sudo chmod a+rw /dev/ttyUSB0
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C
#define DINO_WIDTH 25
#define DINO_HEIGHT 26
#define DINO_INIT_X 10 // Dino initial spawn location
#define DINO_INIT_Y 29 // Dino initial spawn location
#define BASE_LINE_X 0
#define BASE_LINE_Y 54
#define BASE_LINE_X1 127
#define BASE_LINE_Y1 54
23
#define TREE1_WIDTH 11
#define TREE1_HEIGHT 23
#define TREE2_WIDTH 22
#define TREE2_HEIGHT 23
#define TREE_Y 35
#define JUMP_PIXEL 22 // Number of pixel dino will jump
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
static const unsigned char PROGMEM dino1[]={
// 'dino', 25x26px
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x06, 0xff, 0x00, 0x00, 0x0e, 0xff, 0x00,
0x00, 0x0f, 0xff, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x0f, 0xc0, 0x00,
0x00, 0x0f, 0xfc, 0x00, 0x40, 0x0f, 0xc0, 0x00, 0x40, 0x1f, 0x80, 0x00, 0x40, 0x7f, 0x80, 0x00,
0x60, 0xff, 0xe0, 0x00, 0x71, 0xff, 0xa0, 0x00, 0x7f, 0xff, 0x80, 0x00, 0x7f, 0xff, 0x80, 0x00,
0x7f, 0xff, 0x80, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00,
0x03, 0xfc, 0x00, 0x00, 0x01, 0xdc, 0x00, 0x00, 0x01, 0x8c, 0x00, 0x00, 0x01, 0x8c, 0x00, 0x00,
0x01, 0x0c, 0x00, 0x00, 0x01, 0x8e, 0x00, 0x00
};
static const unsigned char PROGMEM tree1[]={
// 'tree1', 11x23px
0x1e, 0x00, 0x1f, 0x00, 0x1f, 0x40, 0x1f, 0xe0, 0x1f, 0xe0, 0xdf, 0xe0, 0xff, 0xe0, 0xff, 0xe0,
0xff, 0xe0, 0xff, 0xe0, 0xff, 0xe0, 0xff, 0xe0, 0xff, 0xc0, 0xff, 0x00, 0xff, 0x00, 0x7f, 0x00,
0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00
};
static const unsigned char PROGMEM tree2[]={
// 'tree2', 22x23px
0x1e, 0x01, 0xe0, 0x1f, 0x03, 0xe0, 0x1f, 0x4f, 0xe8, 0x1f, 0xff, 0xfc, 0x1f, 0xff, 0xfc, 0xdf,
24
0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff,
0xfc, 0xff, 0xef, 0xfc, 0xff, 0x83, 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x03, 0xf8, 0x7f, 0x03, 0xe0,
0x1f, 0x03, 0xe0, 0x1f, 0x03, 0xe0, 0x1f, 0x03, 0xe0, 0x1f, 0x03, 0xe0, 0x1f, 0x03, 0xe0, 0x1f,
0x03, 0xe0, 0x1f, 0x03, 0xe0
};
void setup() {
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
Serial.println("Initialize MPU6050");
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
mpu.calibrateGyro();
// Set threshold sensivty. Default 3.
mpu.setThreshold(3);
delay(3000);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
display.clearDisplay();
introMessage();
while(1){
25
int val = digitalRead(switchPin);
if(val == HIGH){
play();
void loop() {
void sound(){
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer);
void introMessage(){
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10,5);
display.println("Dino Game");
display.setTextSize(1);
display.setCursor(5,45);
display.println("Press Btn To Play ");
display.display();
// Move dino function
void moveDino(int16_t *y, int type=0){
display.drawBitmap(DINO_INIT_X, *y, dino1, DINO_WIDTH, DINO_HEIGHT, SSD1306_WHITE);
26
}
// Move tree funciton
void moveTree(int16_t *x, int type=0){
if(type==0){
display.drawBitmap(*x, TREE_Y, tree1, TREE1_WIDTH, TREE1_HEIGHT, SSD1306_WHITE);
else if(type==1){
display.drawBitmap(*x, TREE_Y, tree2, TREE2_WIDTH, TREE2_HEIGHT, SSD1306_WHITE);
// Game over display with score
void gameOver(int score=0){
sound();
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10,5);
display.println("Game Over");
display.setTextSize(1);
display.setCursor(10,30);
display.print("Score: ");
display.print(score);
display.setCursor(1,45);
display.println("Press Btn To Play");
display.display();
// Display score while running the game
27
void displayScore(int score){
display.setTextSize(1);
display.setCursor(64,10);
display.print("Score: ");
display.print(score);
void play(){
Vector normGyroPv = mpu.readNormalizeGyro();
Vector normGyro = mpu.readNormalizeGyro();
int16_t tree_x=127;
int16_t tree1_x=195;
int tree_type = random(0,2);
int tree_type1 = random(0,2);
int16_t dino_y = DINO_INIT_Y;
int jump=0;
int tree_present = 0;
int score=0;
for(;;){
display.clearDisplay();
if(normGyro.XAxis - normGyroPv.XAxis > 100){
Serial.println("Jump");
if(jump==0) jump=1;
Serial.println(normGyro.XAxis);
if(jump==1){
dino_y--;
28
if(dino_y== (DINO_INIT_Y-JUMP_PIXEL)){
jump=2;
// score++;
else if(jump==2){
dino_y++;
if(dino_y== DINO_INIT_Y){
jump=0;
if(tree_present){
score ++;
tree_present = 0;
if(tree_x<= (DINO_INIT_X+DINO_WIDTH) && tree_x>= (DINO_INIT_X+(DINO_WIDTH/2))){
// Serial.println("Might be Collision Happend");
if(dino_y>=(DINO_INIT_Y-3)){
// Collision Happened
Serial.println("Collision Happend");
break;
}else {
tree_present = 1;
if(tree1_x<= (DINO_INIT_X+DINO_WIDTH) && tree1_x>= (DINO_INIT_X+(DINO_WIDTH/2))){
// Serial.println("Might be Collision Happend");
if(dino_y>=(DINO_INIT_Y-3)){
// Collision Happened
Serial.println("Collision Happend");
29
break;
}else {
tree_present = 1;
displayScore(score);
moveTree(&tree_x,tree_type);
moveTree(&tree1_x,tree_type1);
moveDino(&dino_y);
display.drawLine(0, 54, 127, 54, SSD1306_WHITE);
tree_x --;
tree1_x --;
if(tree_x==0) {
tree_x = 127;
tree_type = 0;
if(tree1_x==0) {
tree1_x = tree_x + random(40, 70);
tree_type1 = 0;
if(tree1_x - tree_x > 55 ){
tree_type1 = 1;
display.display();
normGyroPv = mpu.readNormalizeGyro();
Serial.println("Game Over");
30
gameOver(score);
void renderScene(int16_t i=0){
display.drawBitmap(10, 29, dino1, 25, 26, SSD1306_WHITE);
display.drawBitmap(50, TREE_Y, tree1, 11, 23, SSD1306_WHITE);
display.drawBitmap(100, TREE_Y, tree2, 22, 23, SSD1306_WHITE);
display.drawLine(0, 54, 127, 54, SSD1306_WHITE);
display.drawPixel(i, 60, SSD1306_WHITE);
31