Introduction: Play Tug of War Game With Your Mind Using EEG

About: Making neuroscience affordable and accessible to all with our DIY Neuroscience Kits

Imagine controlling the game on your laptop with just the power of your brain!

In this project, we will play a fun and interactive game driven by EEG signals. But before moving forward let's get familiar with BCI and EEG.

What is electroencephalography (EEG)?

Electroencephalography (EEG) is a method to record an electrogram of the spontaneous electrical activity of the brain. It is typically non-invasive, with the EEG electrodes placed along the scalp (commonly called "scalp EEG") using the International 10–20 system.

What is Brain Computer Interface (BCI)?

A brain computer interface (BCI), sometimes called a brain machine interface (BMI), is a direct communication link between the brain's electrical activity and an external device, most commonly a computer or robotic limb.

How this game works?

When you focus, the ball in the middle of the game moves to the opponent's side, mimicking their concentration level. The more you concentrate, the closer you are to victory.

The key idea is to measure the players' level of concentration by analyzing alpha (8-13 Hz) and beta (13-30 Hz) brainwaves. We specifically chose alpha waves as it indicated calm and relaxed state while beta wave was chosen as it is associated with active thinking and concentration.

As the players focus harder, their beta-to-alpha wave ratio increases, generating a stronger force on the ball. This force pushes the ball toward the opponent’s side of the screen. The game ends when the ball crosses one player’s line, declaring the other player as winner.

Note: This project is made by Dev Saran Sujan and Payal Lakra

Supplies

HARDWARE:

1 x Arduino UNO R4 Minima with type C cable

2 x BioAmp EXG Pill

2 x BioAmp Cables

4 x Male to Male jumper cables

6 x Male-to-female jumper cables

1x Breadboard

6 x Gel electrodes

1x Nuprep skin preparation gel

2 x Alcohol swabs

1 x Laptop


SOFTWARE:

Arduino IDE

Visual Studio Code

Python

Step 1: Assembling BioAmp EXG Pill

If in case you received unassembled BioAmp EXG Pill from a marketplace/distributor, then you may have to assemble it for this project by soldering the header pins and JST PH 2.0 connector as shown in the diagram.

Step 2: Connecting BioAmp EXG Pills to Breadboard

Use 4 male-to-female jumper cables to connect the BioAmp EXG Pills to the breadboard. Connect as mentioned below:

  1. Black cable to GND
  2. Yellow cable to OUT
  3. Red one to VCC.

Repeat the same for the 2nd BioAmp EXG Pill. Refer to the diagram for the complete setup.

Note: We are using a breadboard for demonstration purposes only, but since the breadboard can interfere with the signal quality, you can use a perf board to make the connections.

Step 3: Conneting BioAmp Cables

Connect BioAmp Cables to BioAmp EXG Pill as shown.

Step 4: Skin Preparation

Apply Nuprep Skin Preparation Gel on the skin surface where electrodes would be placed to remove dead skin cells and clean the dirt from skin surface. After rubbing the skin surface thoroughly, clean it with a wet wipe or an alcohol swab.

About Nuprep Gel:

Nuprep skin preparation gel is a mildly abrasive, highly conductive gel that should be applied before placing the electrodes on the skin to improve measurements. When applied gently, it strips away the top layer of skin and moistens the underlying skin layer which reduces the skin impedance with minimal skin irritation and discomfort.

Step 5: Electrode Placements

Let's understand the electrode placements before moving forward in this project. For recording EEG from prefrontal cortex part of brain, you have to place the electrodes on your forehead, specifically on Fp1 (refer International 10-20 system for recording EEG)

What is International 10-20 system for recording EEG?

It is an internationally recognized method to describe and apply the location of electrodes in the context of an EEG exam or voluntary lab research. This method was developed to maintain standardized testing methods ensuring that a subject's study outcomes (clinical or research) could be compiled, reproduced, and effectively analyzed and compared using the scientific method.

Measuring EEG using Gel electrodes:

  1. Connect the BioAmp Cable to gel electrodes,
  2. Peel the plastic backing from the electrodes.
  3. Place the IN+ cable of BioAmp EXG Pill connected to A0 of Arduino Uno R4 on the Fp1 position of Player A
  4. Place IN- and REF on the bony part behind the earlobe of Player A
  5. Place the IN+ cable of BioAmp EXG Pill connected to A1 of Arduino Uno R4 on the Fp1 position of Player B
  6. Place IN- and REF on the bony part behind the earlobe of Player B

Step 6: Connecting Development Board

Connect both the BioAmp EXG Pills to Arduino Uno using the jumper cables as directed below:

  1. VCC to 5V
  2. GND to GND
  3. OUT to A0

Now connect Arduino Uno to the laptop using USB Type C cable.

Note: BE VERY CAREFUL and follow the above diagram while making the connections between your BioAmp EXG Pill & Arduino Uno/Maker Uno, especially the GND and VCC else it may damage the sensor.

Step 7: Download Prerequisites

Download the following softwares:

  1. Python v3.11.X: https://www.python.org/downloads/
  2. Arduino IDE: https://www.arduino.cc/en/software

After you have downloaded the above mentioned softwares, go ahead and download the following GitHub repositories:

Download the zip file of the GitHub Repository mentioned below:

  1. Chords Arduino Firmware: https://github.com/upsidedownlabs/Chords-Arduino-Firmware
  2. Chords Python: https://github.com/upsidedownlabs/Chords-Python/

Step 8: Uploading Arduino Firmware

Extract the Chords Arduino Firmware you downloaded from GitHub repository and open the folder.

You will see a lot of folders which corresponds to various development boards on which Chords Python is compatible.

Now open the folder as per the development board you are using. We are using Arduino Uno R4, so let's open Uno R4 and open the ino file in Arduino IDE.

Upload the ino file. When you see "Done Uploading" in the left corner, this means the code is successfully uploaded on your development board.

Step 9: Running Chords Python

Extract the Chords Python you downloaded from GitHub repository and open the folder.

Open the Command Prompt (For windows laptop: Right-click inside the folder, then select "Open in Terminal")

To create the virtual environment:

PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main> python -m venv venv


To activate the virtual environment:

PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main>.\venv\Scripts\activate


You should now see (venv) at the start of your command prompt:

(venv) PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main>


Install the required modules to run the Python script:

(venv) PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main> pip install -r chords_requirements.txt


Install game specific modules:

(venv) PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main> pip install -r app_requirements.txt


Run the python script:

(venv) PS C:\Users\Dikshant Dahiya\Downloads\Chords-Python-main\Chords-Python-main> python app.py


Now a web interface will open,

  1. Click on Start LSL button to start the LSL stream of the EEG data.
  2. Click on Game Button (EEG Tug of War) to start playing the game

Step 10: Playing the Game

After pressing the game button, a pop up will appear in which you will see a ball placed at the center and Player A in the left and Player B at the right corner of the laptop screen.

Your aim will be to push the ball toward your opponent's side by concentrating on the ball. The player with more focus applies more force to the ball, moving it toward the opposite player. When the ball touches the opponent's edge, you win the game.

Controls and Gameplay:

  1. Start/Restart: Clicking on start, begins the game. Once the game starts, the button changes to Restart and when you click on it, the game restarts.
  2. Pause: Freezes the ball movement to it's current position.
  3. Resume: Continue the game from the pause position.
  4. Exit: Exits the game