You may have seen people using an Arduino to automate playing the Chrome Dino Game in their browser, I thought we could take it a bit further and see if we could get one Arduino to play the Chrome Dino Game on another Arduino.

I’ve previously set up an Arduino to run a simple version of the game, which produces a continuous stream of randomly spaced cactuses at an increasing speed, and closer together. The game is really easy to get running and only requires an Arduino Uno and an LCD keypad shield. A single button on the keypad shield is then used to make the dinosaur jump over each cactus until the player messes up and hits one. The score is kept based on how long you’re able to avoid running into a cactus.

Once I had the game running on one Arduino, I set up a second one, which uses an LDR to sense each cactus and then moves a servo to press the button on the other Arduino to make the dinosaur jump over each cactus.

Here’s a video of the build and the one Arduino playing the Chrome Dino Game on the other:

We’ll first have a look at running the dino game on an Arduino and then set up a second to play the game on the first. The code would be the same to set the second Arduino up to play on your computer’s browser as well, you’d just need to stick the LDR to the display.

What You Need For This Project

For The Dino Game

For The Dino Game Player

How To Load The Chrome Dino Game

Let me start out by saying – I didn’t code the dino game. It’s a version I found on Hackster.io which was the least complicated layout and ran the smoothest. One downside is that it’s written in AVR C code, so it looks a little different to the generic Arduino language but you should still be able to figure a lot of it out, I’ve also expanded on the description of the game and explained how you can change a few things around in another post – How to Play the Chrome Dino Game onto an Arduino.

Here’s a general overview of the game:

  • You push a button on the keypad shield to make the dinosaur jump over each cactus.
  • The game speed up the longer you play it.
  • Cactuses are initially separated by a minimum of 5 spaces and this goes down to 4 as the game progresses.
  • The current score is displayed throughout the game and is joined by the high score at the end of the game.
  • Cheating by holding down the button or continuously pressing the button is prevented.

I have made a couple of changes to the original version of the code for the timing, cactus spacing and the text layouts to better accommodate the sensor.

Here is the code:

Download The Code – DinoGame

The game is quite easy to play on the LCD keypad shield, although the buttons are not the best for quick presses, and the LCD is quite slow, so it starts suffering from ghosting and brightness issues once the cactuses start moving quickly.

Playing The Chrome Dino Game On An Arduino

Setting Up An Arduino To Play The Chrome Dino Game

Now that we’ve got the game running on our first Arduino, let’s try and get the second one playing the Chrome Dino Game on the first.

The components and wiring are quite simple, they involve basic starter circuits for the LDR, LED and servo. I initially included the LED to light up when each cactus was detected but the light started interfering with the LDR, so I turned it off. You can leave this LED out if you want to or cover it up slightly with tape so that it doesn’t interfere with the surrounding components.

Schematic - Arduino Chrome Dino Game Player

I connected the components together using a few strips of ribbon cable and some header pins to make it easier to plug into the Arduino and the servo.

Soldering Components

Ribbon Cable Connector

You’ll need to glue the servo onto a box or stand just above the left button on the keypad shield so that the servo arm pushes the button down when it rotates. You’ll then need to glue the LDR onto the edge of the LCD screen as close to the screen as possible. It needs to be positioned over the 7th character from the left of the display in the second row.

Arduino Playing The Chrome Dino Game On Another Arduino - Side

Make sure that the LED is covered, turned off or pointed away from the display so that the light from the LED doesn’t interfere with the LDR sensing the cactuses. The first few runs I had were interrupted by the LED causing false cactus readings by the LDR, so it turned it off.

Servo Pressing Jump Button

Now let’s have a look at the player code.

Download The Code – DinoGamePlayer

We start by including the servo library to control the servo.

We then create a servo object called player to control the servo and then create two variables, one to store the value read from the LDR and a second to store the light level set point when a cactus passes in front of the LDR.

In the setup function we set the servo pin number and set the servo position slightly above the jump button. You’ll also need the Serial monitor for calibration, this is detailed further on.

In the loop function, we read in the LDR sensor level, then compare it to the cactus set point. If the measured level is greater than the cactus set point, indicating a cactus is passing the sensor, then we move the servo downwards to push the button, wait 300 milliseconds for the servo to move and for the game to register the input and then move the servo back up for the next push. The second delay is to avoid repeated servo movements, this could be reduced to 50ms.

I’ve also included a serial monitor printout of the sensor value which is used initially to set the cactus value set point. You’ll need to run the game and display the sensor values and then see what value is measured when a cactus runs past the sensor and update this value in the code accordingly. This step is detailed in the video at the beginning of the project.

One Arduino Playing The Chrome Dino Game On Another

Upload the code and calibrate the sensor and you’re ready to try it out. Startup the player Arduino first and then start the game on the other. Press the reset button on the LCD shield to start a new game.

Arduino Playing The Chrome Dino Game On Another Arduino

It initially looks like the sensor is making the dinosaur jump a little too early, but it doesn’t hit the cactuses and you need to it respond quickly later on in the game. It starts to look better as the game progresses.

LDR Detecting Cactuses

You may need to make a few adjustments to the servo travel limits and to the cactus detection set points in your code to get it to work correctly.

Arduino Playing The Chrome Dino Game On Another Arduino - Side

Also, position the LDR as close to the LCD as possible. These LDRs are really sensitive, I noticed a significant fluctuation in the measured values with me moving around the room or at different times of the day, so It would be a good addition to add a pot to adjust the set point at any time. This way you could get it to work in any light conditions and use it on the Arduino game or your computer without having to change the code.

Let me know in the comments if you’ve tried playing the Chrome Dino Game on an Arduino or tried getting an Arduino to play the Chrome Dino Game.

Share This Guide

An Arduino Playing The Chrome Dino Game On Another Arduino Social

Leave a Reply

Your email address will not be published.