I Played the Chrome Dino Game With My Brain

Surya Sure
Visionary Hub
Published in
5 min readDec 22, 2021

I’m sure everyone reading this article has played the Google Dino Game before. The one where the dino jumps over the cacti when your internet doesn’t work. I would be proud to say my high score in that game is 3000, but I bet someone reading this has 7000 or something. But the real question is what is your high score when playing the game with your brain? Because I was able to score a whopping 210 (which is very impressive) when playing this game by blinking instead of pressing space.

A GIF of the dino game

Getting data from my brain

To play the game with my brain, I actually need my live brain data and use the signals that are produced when blinking to jump.

To record my data, I used a brain-computer interface (BCI). A BCI is a device that tracks your brain activity and sends it to the computer, allowing performing a task that you programmed it to do.

There are many types of data you can record with a BCI, but I used electroencephalogram (EEG) signals. These are the signals produced by the electricity generated by action potentials, which are sent through your nervous system when your brain wants to perform a function.

I used the OpenBCI Ganglion Board to record my EEG data, along with the EEG Headband Kit.

Ganglion Board

The Ganglion Board has 4 channels, meaning I can place 4 electrodes around my head and connect them to the board with wires. The data is live-streamed, which I can see through the OpenBCI GUI. For this task, I only needed to use 2 channels because blinking is a simple task and only requires you to record the frontal lobe of the brain, which is behind your forehead. The frontal lobe is responsible for executive functions, which include simple movements such as blinking.

Me wearing the headband kit

Programming the output

Obviously, getting the data isn’t enough. I have to actually translate the blinking signals into an output, which in this case, is the space bar, by programming.

To do this, I used the coding language Python. Python is used for a wide variety of tasks, but I worked with a specific library called BrainFlow, which takes the data from my board in the form of an array and filters it. Once it’s filtered, I use another library called pydirectinput, which allows me to input a button from my keyboard, without me actually pressing it. So basically I say, “If there is a spike in the signals, then press space”, through the code.

My full code is in my GitHub, but I’ll break down my code into chunks and explain what each section does.

Importing Packages

In the first part of the code, I’m importing the libraries that I’ll need to use later on. NumPy and pandas are needed to work with arrays, which is the format that the EEG data is in when working with Python. The BrainFlow, BoardShim, and DataFilter libraries contain the functions that let you stream data from your board and filter it to remove noise.

Assigning Values

Here, I’m assigning values to certain variables. Each board has different setup variables and I copied down the variables for the Ganglion board from the BrainFlow documentation. The other values such as time_thres, max_val, vals_mean, and num_samples are for later in the code to deal with the maximum and average values of the data relative to the sampling rate, or how many times it records the data. The last part is telling the board to connect to the computer through Bluetooth.

Preparation

This part of the code is preparing the board to collect the data. It starts the stream of the data and gives the computer 5 seconds to process the data.

Calibration

In this part, the computer is learning what happens to the data when I blink, so that it can detect it. The while loop is essentially saying that vals_mean is the average of all of the samples of data and max_val is the maximum value in the data. This helps set up the blink threshold, which is the difference between the maximum value and the average value. The blink threshold allows the computer to detect a blink when the values in the data go higher than the blink threshold.

Performance

Finally, here, the second “if” statement is telling the computer to update the time as the data is received. The final “if” statement is telling the computer to press space if the difference between the current value and the average value goes above the blink threshold. At the end, we stop the data stream and disconnect the board from the computer.

If I run this program, my blinks will register as the space bar to my computer, so I can play the dino game.

Demo

Here is a video of me playing the game by blinking. You’ll probably notice that not all of my blinks register as jumps because there is occasional noise, which overshadows the blink signals. But most of the time, it did work.

And…THAT'S IT! This was a very confusing and time-consuming project for me because I am completely new to coding and have never worked with BCI’s before. But now, I can work on more complicated projects since I know the basics, so expect more from me soon!

If you liked this article and want to follow my research, feel free to connect with me on LinkedIn and follow me on Medium!

--

--