T-Rex GO! Arduino OLED Survival Game
by 1077320 in Circuits > Arduino
216 Views, 2 Favorites, 0 Comments
T-Rex GO! Arduino OLED Survival Game
Have you ever played the Chrome dinosaur game when there is no internet? I wanted to create my own physical version of that game using an Arduino Uno. Instead of only having a simple computer game, I wanted to build something interactive where the player can physically control the character using real buttons, sensors, and electronic components.
**BEFORE WE DIVEIN, THIS PROJECT WAS INSPIRED BY HTML WORKSHOP- PLEASE CHECK THEM OUT!! CLICK ME
For this project, I created T-Rex GO!, an Arduino-based survival game where the player controls a dinosaur on an OLED display. The main objective of the game is to survive as long as possible by avoiding different obstacles, increasing the score, and managing the player's health. The player can jump over obstacles, duck under flying obstacles, and collect energy to activate a special shield ability.
One of the main features I added was an ultrasonic sensor shield system. Instead of using another button, I wanted to make the game more interactive, so the player can activate the shield by moving their hand close to the sensor. The ultrasonic sensor measures the distance of the hand and sends that information to the Arduino, which decides when to activate the shield.
This project combines electronics, programming, and game design by connecting different hardware components together and controlling them through Arduino code. The Arduino Uno acts as the brain of the system by reading inputs from buttons, sensors, and the potentiometer while controlling outputs like the OLED display, RGB LED, and buzzer.
The OLED display is used to create the game visuals, including the dinosaur, obstacles, score, health, and different game screens. The RGB LED provides visual feedback by changing colors depending on the game state, such as showing when the player is damaged, when the shield is ready, or when the shield is active. The buzzer adds sound effects to make actions like jumping, starting the game, and activating the shield feel more realistic.
The purpose of this project was to learn how different electronic components can work together with programming to create a complete interactive device. Throughout the building process, I improved the original idea by adding features like a health system, increasing difficulty, sound effects, RGB feedback, and the shield ability to make the game more challenging and enjoyable.
Downloads
Supplies
To build the T-Rex GO! Arduino game, I used different electronic components to create the controls, display system, sound effects, and interactive features. Each component has a specific purpose in making the game work.
Arduino Uno (1)
The Arduino Uno is the main controller of the project. It works as the brain of the system by reading inputs from buttons and sensors, processing the game logic, and controlling outputs such as the OLED display, RGB LED, and buzzer.
Breadboard (1)
A breadboard was used to connect all the electronic components together without needing to solder. It allows the circuit to be changed easily during testing and development.
Jumper Wires
Jumper wires were used to connect the Arduino pins to the different components on the breadboard. Different wire colors were used to keep the wiring organized and easier to troubleshoot.
OLED Display SSD1306 128x64 (1)
The OLED display is used to show the game graphics. It displays the dinosaur, obstacles, score, health bar, shield energy, pause screen, and game over screen. The display communicates with the Arduino using I2C communication.
RGB LED (1)
The RGB LED shows:
- Green → Normal gameplay
- Red → Damage or game over
- Cyan → Shield active
- Purple → Shield ready
Push Buttons (2)
Two push buttons are used as player controls.
- Jump button → Makes the dinosaur jump over obstacles
- Duck button → Makes the dinosaur avoid flying obstacles
Slide Switch (1)
The slide switch is used as a start/pause control. It allows the player to start the game and pause the system during gameplay.
Ultrasonic Distance Sensor HC-SR04 (1)
The ultrasonic sensor is used for the shield activation system. It measures distance by sending sound waves and calculating how long it takes for them to return.
The sensor allows the player to activate the shield by moving their hand close to it.
NPN Transistor (1)
The NPN transistor is used as an electronic switch to control power to the ultrasonic sensor. The Arduino sends a small signal to the transistor, which allows a larger current to flow to the sensor.
This prevents the Arduino pin from supplying too much current directly and helps protect the board.
Buzzer (1)
The buzzer creates sound effects throughout the game, including:
- Game start sounds
- Jump sounds
- Shield activation sound
- Collision effects
Potentiometer (1)
The potentiometer is used as a speed control input. The Arduino reads the analog value from the potentiometer and adjusts the game speed depending on the position of the knob.
Resistors (220Ω–330Ω)
Resistors are used to protect components, especially the RGB LED, by limiting the amount of current flowing through them.
USB Cable
The USB cable is used to connect the Arduino Uno to the computer. It provides power and allows the Arduino code to be uploaded using Arduino IDE.
Computer with Arduino IDE
Arduino IDE was used to write, upload, and test the program. The code controls all the game features and allows the hardware components to work together.
Power Rails & Center Console Assembly
Before plugging in any logic components, we need to set up the infrastructure of our console. This step builds the virtual power lines and slots the main visual display cleanly right in the middle, giving our project that classic handheld Game Boy style layout.
Part A: Establish the Power Infrastructure
- Grab your Solderless Breadboard and orient it horizontally.
- Run a solid red jumper wire from the 5V pin on the Arduino to the top Red (+) Rail of your breadboard.
- Run a solid black or blue jumper wire from the GND pin on the Arduino to the top Blue (-) Rail of your breadboard.
- Optional Tech Tip: Use two small jumper wires to connect the top Red/Blue rails to the bottom Red/Blue rails. This gives you a live power line on both the top and bottom of your board!
Part B: Mount the Center OLED Display
- Press your 0.96-inch OLED Screen firmly into the absolute horizontal center rows of the breadboard.
- Connect the GND pin on the OLED directly to your Blue (-) Ground Rail.
- Connect the VCC pin on the OLED directly to your Red (+) Power Rail.
- Connect the SDA (Serial Data) pin on the OLED to Arduino Analog Pin A4.
- Connect the SCL (Serial Clock) pin on the OLED to Arduino Analog Pin A5.
"Extra Tip!"- I2C (Inter-Integrated Circuit) is a smart communication protocol. Instead of using 8 or 9 separate messy wires to send individual pixel data to the screen, I2C compresses everything down into just two lines: SDA (the data road) and SCL (the clock ticker that keeps the data in sync).
Wiring the Console Input Controls
Now that our screen has power and a data link, we need to wire up the physical inputs so the player can actually interact with the game engine.
Part A: The Action Buttons (Jump & Duck)
- Place one Pushbutton Switch directly to the Left side of your center OLED screen. This is your Jump Button.
- Connect one leg of this button to Arduino Digital Pin 5. Connect the diagonally opposite leg directly to your Blue (-) Ground Rail.
- Place your second Pushbutton Switch directly to the Right side of your center OLED screen. This is your Duck Button.
- Connect one leg of this button to Arduino Digital Pin 6. Connect the diagonally opposite leg directly to your Blue (-) Ground Rail.
Part B: System Adjustments (Pause Switch & Speed Dial)
- Mount your SPDT Slide Switch below the buttons. Connect its center pin to Arduino Digital Pin 2. Connect either the left or right outer pin to the Blue (-) Ground Rail.
- Mount your 10kΩ Potentiometer nearby. Connect its leftmost outer leg to the Blue (-) Ground Rail, its rightmost outer leg to the Red (+) Power Rail, and its center pin (the wiper) straight to Arduino Analog Pin A0.
HELPFUL INFO- Why don't our buttons need external resistors connected to power? Because our Arduino code uses INPUT_PULLUP. This instructs the Arduino's internal microchip to activate a hidden built-in resistor that holds the pin safely at (HIGH). When you press the button, it bridges the gap directly to the ground rail, dropping the voltage to (LOW). The code spots this sudden drop and instantly triggers a jump or duck!
Game Feedback Systems (Audio & Visuals)
Part A: Wiring the Common Anode RGB LED
- Place your RGB LED into the breadboard. Locate its longest pin—this is the Common Anode pin.
- Run a jumper wire from that longest pin directly into your Red (+) 5V Rail.
- Connect a 220 ohms or 330 ohms resistor to each of the remaining three shorter color legs to protect the internal LED diodes from burning out.
- Route the opposite end of the resistors to the Arduino pins exactly like this:
- Red Leg Resistor to Arduino Digital Pin 9
- Green Leg Resistor to Digital Pin 10
- Blue Leg Resistor to Arduino Digital Pin 13
🔊 Part B: Wiring the Audio Piezo Buzzer
- Press the Piezo Buzzer into the breadboard.
- Connect its positive leg (usually marked with a small + sign or having a longer wire) to Arduino Digital Pin 7.
- Connect its remaining negative leg directly to your Blue (-) Ground Rail.
Building the Transistor Power Gate & Shield Sensor
Instead of letting your Ultrasonic Sensor run constantly and waste power during a pause or game-over state, we are building a custom Low-Side Transistor Switch. This cuts the sensor's ground line completely at the command of the Arduino code.
Part A: Setting Up the NPN Transistor
- Take your NPN Transistor (2N3904 or PN2222) and push it into three separate rows on your breadboard. Orient it so the flat side is facing you.
- Looking at the flat side, the pins from left to right are Emitter (1), Base (2), and Collector (3).
- Connect a 1k ohms to 10k ohms resistor directly to the center Base pin. Connect the other side of this resistor to Arduino Digital Pin 12.
- Run a jumper wire from the leftmost pin, the Emitter, directly into your main Blue (-) Ground Rail.
Part B: Connecting the Ultrasonic Sensor (HC-SR04)
- Place your Ultrasonic Sensor at the top edge of your console layout, facing outward toward the player.
- Wire the sensor's VCC pin directly to your Red (+) 5V Rail.
- Wire the sensor's Trig (Trigger) pin to Arduino Digital Pin 3.
- Wire the sensor's Echo pin to Arduino Digital Pin 4.
- The Power Gate Connection: Take the sensor's GND pin and connect it directly to the rightmost pin of your transistor—the Collector.
💡 How it Works: When the game starts, the Arduino sends a signal out of Pin 12 into the Base of the transistor. This saturates the semiconductor material, completing the circuit from the Collector to the Emitter. This safely bridges the Ultrasonic Sensor's ground pin right back to your main system ground rail, powering it on instantly!
Uploading the Core Game Engine
With the entire physical hardware layout constructed, connect your Arduino Uno to your computer using your USB cable and fire up the Arduino IDE.
📚 Install the Libraries First
Go to Tools---Manage Libraries, search for, and install:
IF UNABLE TO LOCATE INSTALL THEM BY CLICK ON 1 / 2 OPITION ABOVE
💻 The Complete Production Code
Create a new sketch, delete any default placeholder functions, and paste this optimized code block completely into your IDE:
Lets Check! -Power Test & First Boot Checklist
Before playing your game, run this basic diagnostics sequence to verify your electrical links and code compilation are completely solid:
- Check for Short Circuits: Look closely at your power rails. Ensure no bare wire links are shorting 5V straight into a Ground column.
- Hit the Power: Plug your USB link cable into the console. The OLED should light up displaying "T-REX GO!" with an animated dinosaur bouncing across the display, while your RGB shifts gracefully through a smooth rainbow cycle.
- Flipping the Switch: Flip the slide switch to start. The console will play an upscale startup tone, the LED will shift to Solid Green, and the obstacles will start scrolling down the runway.
- Testing Inputs: Press the Left button to jump and the Right button to slide down. Turn the potentiometer dial; moving the knob should noticeably accelerate or slow down the speed of the game scrolling frame!
- The Shield Wave: Clear three obstacles to full-charge the energy bar. When the LED shifts to a blinking Purple, quickly wave your hand over the top of the ultrasonic sensor (under 10cm). If a circular barrier box snaps onto your dinosaur and flashes Cyan, your hardware gate setup is working perfectly!
Thanks For Visiting! Have FUN with THE CIRCUIT!!
CHECK OUT THESE 2 VIDEOS BELOW DEMONSTRATING THE T-REX GO CIRCUIT!!!!!!