Introduction: Control a Computer With Your Mind!

Controlling your computer with your mind definitely seems like something still out of a sci-fi movie, but mind control is actually a relatively easy and cheap thing to accomplish. Using a cheap EEG toy, let's use the power of our mind to send commands to our computer. There’s a lot to do, so let’s start tinkering

Step 1: Watch the Video

This Instructable is based on a video series I did a while back. So for those of you that are video learners, please check it out and support my channel! For those of you that like the written step by step instructions, on to step two!

Step 2: Gathering the Parts

Here's the parts you need and the approximate prices at the time of writing this post.

  1. Star Wars Force Trainer (or other EEG headset) = $40
  2. Arduino Uno = $7
  3. Hard drive jumper = scavenged for free (or 0.35 if you can't scavenge)

Total is approximately $50

Step 3: Disassemble the Force Trainer

In order to use the brain waves that the Star Wars Force Trainer receives, we need to take it apart and connect to it. All we will need is the headset. The ball tube will not be used for this project. One of the best things about this project is that it still functions as a toy even after you’ve hacked it. So you don’t have to worry about not being able to play with it again once you’ve taken it apart.

  1. On the headset, remove the batteries and the screws that hold the top plate on.
  2. Locate the Neurosky EEG board, as pointed out on the left.
  3. Solder a wire to the T-Pin on the EEG board.
  4. Solder a second wire to the Ground terminal on the battery case.
  5. Drill or carve a small hole in the plastic casing that the wires can run through.
  6. Put a small dab of hot glue on the wires after running them through the hole to hold them in place.

Now you’re headset should be ready for outputting data! Replace the batteries and ensure everything is still working, and then screw the top casing back on. The next part is connecting an Arduino to the headset to collect the data!

Step 4: Connecting the Arduino

The next step is to get the EEG data from the headset onto our computers. In order to do this, we need something that will convert it from raw data coming from wires to readable data coming through USB. We’ll be using an Arduino for this. And here’s the steps we’ll need to take to connect it all.

  1. If you like, you can fasten the Arduino to the top of the headset using tape or zip ties.
  2. Connect the T pin wire from the headset to the RX pin on the Arduino.
  3. Connect the Ground wire from the headset to a Ground pin on the Arduino.
  4. Using a USB cable, connect the Arduino to your computer.
  5. Download and install the Arduino software version 1.0.5.
  6. The software doesn’t work with any newer versions.
  7. Before starting up the software, download and install the Arduino Brain library. You want to place it in your Arduino Libraries folder.
  8. Startup the software and load up the test program by going to File > Examples > Brain > BrainSerialTest
  9. Upload it to the Arduino (you may have to temporarily remove the RX wire in order to do this)
  10. Open up the serial console, put the headset on your head, turn it on, and see what results you get!
  11. The first number is the signal strength, the second is the attention value, and the third is the mediation value.

***PLEASE NOTE*** If you continuously get a 200,0,0 as your status, this may be due to a grounding issue with the headset. If you are using a laptop, unplug it and let it run off of battery while your headset is plugged in to see if it fixes the issue.

Step 5: Resetting the Arduino

Unfortunately, in its purchased state, the Arduino Uno R2 and R3 cannot emulate a keyboard and send keyboard commands to a computer. The Arduino Leonardo can do this, but it would be ideal if we did not have to purchase another Arduino just to simulate keystrokes. Luckily, this tutorial by Kevin DeMarco shows us a workaround that allows an Arduino Uno R3 and R2 to emulate a keyboard by resetting the Atmega chip.

If you are using Windows or Mac, you can follow the similar steps listed here.

Here are the steps for linux:

  1. Place the hard drive jumper on the reset and ground Arduino pins as shown in the image to the left.
  2. Power on the Arduino by plugging it into your computers USB port.
  3. Once you see the Arduino receive power, wait a few seconds and then remove the jumper from the pins. This should place the Arduino in reset mode, and we can now upload our own firmware.

Step 6: Uploading New Firmware

As mentioned in the previous step, with the Arduino in reset mode, we can upload our own firmware to the Atmega chip. Why would we want to do this? Because it will allow us to have the Arduino act as an HID keyboard. So here’s the steps to get started:

  1. Open up a linux terminal
  2. Update apt-get
    1. sudo apt-get update
  3. Install the DFU (Device Firmware Updater) Program
    1. sudo apt-get install dfu-programmer
  4. Download and unzip the custom firmware we will need for this project. This zip file contains two hex files: Arduino-keyboard-0.3.hex and Arduino-usbserial-uno.hex
    1. wget http://www.tinkernut.com/demos/arduino_hid/arduino_hid.zip
    2. unzip arduino_hid.zip
  5. Use the DFU programmer to erase the chip, upload a new firmware, and reset the chip. For this example, we will just upload an Atmega16u2 version of the USB firmware.
    1. sudo dfu-programmer atmega16u2 erase
    2. sudo dfu-programmer atmega16u2 flash --debug 1 Arduino-usbserial-uno.hex
    3. sudo dfu-programmer atmega16u2 reset

With the new firmware uploaded, you now have to power-cycle the Arduino. You can do this by simply unplugging it and plugging it back in.

Step 7: Emulating a Keyboard

We now know how to flash the firmware, so now we need to make it act like a keyboard. So the first thing we need to do is write a simple program for the Arduino that sends keystrokes to the serial console. How we send a keystroke? By using this list of HID keyboard codes to find the character you want to send. Below is the sample code provided by Kevin DeMarco:

/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */

void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}

void loop()
{
delay(5000);

buf[0] = 0;
buf[2] = 0x15; // letter R
Serial.write(buf, 8);
releaseKey();
}

void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}

Check this code for errors and then upload it to the Arduino. Now all that’s left to do is follow the same steps as in steps 2 and 3 to upload the Arduino Keyboard firmware. Briefly, here are the

  1. Unplug the Arduino from the computer
  2. Place the hard drive jumper on the Ground and Reset pins.
  3. Plug the Arduino back into the computer so that it powers on
  4. Remove the hard drive jumper
  5. In your computer terminal, execute these commands to upload the Arduino Keyboard firmware
    1. sudo dfu-programmer atmega16u2 erase
      sudo dfu-programmer atmega16u2 flash --debug 1 Arduino-keyboard-0.3.hex
      sudo dfu-programmer atmega16u2 reset
  6. Power cycle the Arduino by unplugging it and plugging it back in.

With your Arduino reconnected, open up a text editor, and you should see the letter “R” being typed (or whichever letter you chose). You’ve successfully emulated a keyboard with your Arduino!

Step 8: Connecting It to the EEG

The last step is to connect our EEG headset to the Arduino and edit the Arduino code so that it sends a keyboard command everytime our Brain data reaches a specific value. We can do this by opening up our Arduino code from the Homemade Mind Control TV Remote tutorial and removing all the code references to the IR LED and commands and then replacing them with our new keyboard commands. The final code should look something similar to this:

#include <Brain.h>
Brain brain(Serial);
long interval = 500; 
long previousMillis = 0; 
int medValue;
uint8_t buf[8] = { 0 };
void setup() {
 Serial.begin(9600);
 randomSeed(analogRead(0));
 delay(200);
}
void loop() {
 if (brain.update()) {
 Serial.println(brain.readCSV());
 medValue = brain.readMeditation();
 }
 if(brain.readSignalQuality() == 0) {
 if (medValue < 50) {
 buf[0] = 0;
 buf[2] = 0x17; // letter T
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x0C; // letter I
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x11; // letter N
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x0E; // letter K
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x08; // letter E
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x15; // letter R
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x11; // letter N
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x18; // letter U
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x17; // letter T
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 
 buf[0] = 0;
 buf[2] = 0x28; // enter
 Serial.write(buf, 8);
 delay(40);
 releaseKey();
 }
 } 
 
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}

Before we can upload it to the Arduino, however, we need to convert the Arduino back into USB mode, so repeat Steps 2 and 3 for that.

And finally, once you have it uploaded to your Arduino, you will need to repeat step 4 to convert your Arduino back into keyboard mode.

If everything is successful, once you have your headset on and plugged into your computer, once your meditation value drops below 50, you should see your keyboard commands executed on the screen!

Coded Creations

Second Prize in the
Coded Creations