USB Biofeedback Game Controller

111,361

300

54

About: The bionics wizards at Advancer Technologies are changing the world by helping homegrown inventors flex their creative muscles. From robots to video games to prosthetics, their muscle sensor, MyoWare™,...

Intro: USB Biofeedback Game Controller

Building upon our last tutorial, which taught you how to build a muscle sensor, we've decided to give you a project that really showcases the power of our muscle (EMG) sensors. Advancer Technologies’ “USB Biofeedback Game Controller” harnesses the power of electromyography to allow players to directly control video games with their muscles. At the core of this plug-in-play controller is the powerful yet low-cost Arduino UNO microcontroller, a favorite among hobbyist and students, acting as a HID keyboard interface. Integrated with the Arduino UNO are four of our Muscle (EMG) Sensors, allowing four muscles to act independently or in combination with each other to control over four buttons. In our setup, we elected to use a six button setup with the left forearm controlling the B button (RUN/ATTACK), the right forearm controlling the A button (JUMP), the left bicep controlling the LEFT button, the right bicep controlling the RIGHT button, and combinations for UP and DOWN.

This tutorial will teach you to build a USB Biofeedback Game Controller. Use it to play any computer game (that uses keyboard inputs) using your muscles as the controller.




Check out our previous Instructable to learn how to build your own Muscle Sensor

or

Drop by our webstore to purchase muscle sensors, kits, cables and electrodes
Muscle Sensor Kit (now also on SparkFun)
Muscle Sensor Electrodes

Note: This sensor is not intended for use in the diagnosis of disease or other conditions, or in the cure, mitigation treatment, or prevention of disease, in a man or other animals.

About Advancer Technologies
Advancer Technologies is a company devoted to developing innovative game-changing biomedical and biomechanical technologies and applied sciences. Additionally, Advancer Technologies promotes all forms of interest and learning into biomedical technologies. To help cultivate and educate future great minds and concepts in the field, they frequently post informative instructions on some of their technologies. For more information, please visit www.AdvancerTechnologies.com .

Step 1: Materials

Basics
1 x Arduino Uno R2 (needs the atmega8u2 USB chip which is only available on newer Arduino MCUs)
1 x Arduino Project Enclosure
1 x USB cable for your Arduino
4 x Advancer Technologies Muscle Sensor 
1 x +/-5V Power Supply
1 x 12V Power Supply (Wall wart) 
1 x Muscle Sensor Electrodes

Misc.
Jumper cables or solid core wire
3 x 1" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 2" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 3" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 4" length pieces of 24-30 AWG wire (1/8" stripped off each end)
3 x 3 position Female Receptacle 
1 x 3 position Female Housing
3 x Crimps for Female Housing
Plastic board (ABS)
1 pack x 3/8" 4-40 Screws (91772A108)
2 packs x 4-40 Nuts

Tools
Soldering Iron
Scissors or Tin Snips
Crimping tool
Screw driver
Drill with 1/8" bit
Sandpaper
Dremel tool or other cutting tool

Software
Arduino
Processing

Step 2: Constructing the Plastic Insert

First we will need to create a insert to attach the Power Supply board and three of the Muscle Sensors. This insert will fit inside the project enclosure and rest on top of the Arduino UNO and the last muscle sensor.

If you're using relatively thin plastic board material, you can probably use a set of heavy duty scissors or tin snips to cut out the insert.

The dimensions (in inches) are shown in the drawing above and are approximate. You might need to do some sanding for a better fit.

After you construct the insert, try sliding it into the bottom of the enclosure and putting the top on. If it doesn't fit properly, get the sand paper out and sand down the parts that are interfering. 

Step 3: Preparing the Bottom of the Project Enclosure

Next we'll prepare the Arduino project enclosure. 

First, trim down the two middle supports on the bottom of the enclosure. Leave enough height so that they will still go through your Arduino mounting holes but not go past the Arduino headers. (Pic 1)

Next, place one of the muscle sensors in the bottom left of the enclosure by sliding the bottom left support through the muscle sensor's mounting hole (the one near the female headers). Straighten the sensor by rotating it around the support such that its sides are parallel with the enclosures. Gently and such that you don't jostle the sensor board, slide your plastic insert onto the enclosure and hold it above the sensor. Now, look down the rectangular cutout on your insert and verify the three male headers of your sensor are directly below. If not, remove the insert, adjust the sensor position and repeat until it is in position. Once it is in position, mark the location of the muscle sensor's second mounting pin, remove the sensor, and drill the hole. 

Note: If you don't get the hole in exactly the right position, it's OK you can just widen the cutout more to compensate.

Step 4: Preparing the Top of the Project Enclosure

Next, you'll need to modify the top portion of the enclosure as well. Using a Dremel tool or some other cutting tool, completely cut off the reinforcement wall near the front of the enclosure (see picture). Additionally, completely cut off the two middle supports that complement the supports you cut on the bottom portion of the enclosure. These both need to be removed to give us some more head room for the muscle sensors and plastic insert.

Step 5: Soldering the Power Supply Connectors

We now need to create a way to connect the Power Supply board to each of the sensors. Grab your power supply board, the four sets of wire lengths, and the female housing and receptacles.

On the Power Supply board, there is a grid of through holes in a 3 col x 4 row pattern. Solder the three 3" wires to the holes in row 1, solder the three 2" wires to the holes in row 2, solder the three 1" wires to row 3, and solder the 4" wires to the holes in row 4.

Next, grab your 3 female receptacles and bend all the solder tabs so that they're at a 90 degree angle. For the 1"-3" wire sets, solder the female receptacles (with the ports facing downward) such that the wire soldered to the +5V column is soldered to the right solder tab, the GND wire is soldered to the middle solder tab, and the -5V wire is soldered to the left solder tab. For reinforcement, dab a glob of hot glue on the joints.

Using a crimping tool (you can also choose to solder instead of crimping), crimp the crimp tips to each of the 4" wires with the tabs pointing upward. Now insert each of the wires' crimp tips into the female housing, again following the +5V right, GND middle, -5V left order.

Your power supply board should be ready to go. double check each solder and crimp to make sure they'll good and solid.

Step 6: Mounting the Muscle Sensors and Power Supply Board

Now it is time to mount your sensors using the 4-40 screws and nuts.

Grab three of your sensors and the power supply board and put a screw into each mounting hole. Thread a nut on each screw but leave it slightly loose. These nuts will be used as standoffs. 

Next, place each sensor's mounting screw into each corresponding mounting hole. Remember to keep the muscle sensors' female headers on the same side as the shelf's offset. Thread another nut onto each screw until they are nice and tight. Tighten more with a screw driver and a wrench, holding the second nut secure.

Next, follow this same process for the power supply board. Make sure the power jack is facing the front side of the shelf.

For the last muscle sensor, insert a screw up through the bottom of the enclosure and secure with a nut. Then slide the muscle sensor down the support column and insert the screw into the sensor's mounting hole and secure with a nut.

Check to make sure you can fit the female housing through the gap between the sensors and down into the rectangular cutout and onto the male headers of the sensor below. If the gap is too tight, remove one of the top sensors and sand one of its mounting holes on the shelf until the gap is wide enough.


For the remainder of these instructions we're going to refer to the sensors as follows:
Sensor 1 = Closest to Power Supply
Sensor 2 = Middle
Sensor 3 = End
Sensor 4 = Bottom

Step 7: Connecting the Power Supply to the Muscle Sensors

By this time, your muscle sensors and power supply should be mounted and your Arduino should be in the project enclosure. Now you should be ready to start connecting everything together and setup your electrodes. 

First you'll want to give all your sensors power. Insert the plastic insert into the project enclosure and then connect each female receptacle and housing to the corresponding sensors. (Hint... the 1" wire goes to the sensor closest to the power supply, the 2" wire goes to the middle sensor on the insert, the 3" wire to the last sensor on the insert, and the 4" wire goes through the rectangular cutout to the sensor on bottom).

MAKE SURE THE CORRECT VOLTAGES ARE CONNECTED TO THE CORRESPONDING SENSOR PINS (+Vs = +5V, GND = GND, -Vs = -5V). IF NOT, YOU CAN POTENTIALLY BURN OUT YOUR SENSOR BOARD.

DOUBLE CHECK.... BETTER SAFE THAN SORRY!

Step 8: Decide Which Muscles Are Going to Control Which Button(s)

Now, you're going to have to decide which muscles/muscle combos you want to use for your button(s) layout. We've opted to go with the following layout. If you want to go with a different layout, you'll have to make some modifications to the Arduino code we'll get to later on.

Function buttons:
Button A --> Right forearm muscle
Button B --> Left forearm muscle
Start Button --> Not muscle controlled
Select Button --> Not muscle controlled

Directonal pad:
Right  --> Right bicep muscle
Left --> Left bicep muscle
Up --> All four muscles (combo)
Down --> Left and right bicep muscles (combo)

Step 9: Attaching the Electrodes to Your Muscles

Next, you'll need to attach the electrodes to your muscles. The image above illustrates where to place the electrodes for our button layout. You can use any muscle you want (bigger muscles have stronger signals and surface muscles are easier to detect) but for our example we've gone with the ones shown.

Check out this video for a quick overview of how to connect the electrodes to your bicep...

Step 10: Connecting the Electrodes to the Muscle Sensor(s)

Now, we'll attach the electrodes to each muscle sensor using the EMG cables.

Sensor 1
Dark green- M.Mid Pin
Light green - M.End Pin

Sensor 2
Dark pink- M.Mid Pin
Light pink - M.End Pin

Sensor 3
Dark red - M.Mid Pin
Light red - M.End Pin

Sensor 4
Dark blue- M.Mid Pin
Light blue - M.End Pin

Each muscle sensor needs a reference electrode to be connected to the Ref pin. For our example, we are going to place them on the back of the forearm near the elbow. The reference electrodes should be placed on electrically neutral areas of the body such as the bony area by the elbow.

Step 11: Connecting the Muscle Sensor(s) to the Arduino

Now we're getting close. By this step, your muscle electrodes and power supply should be hooked up to your muscle sensors. We just have to connect the sensors to the Arduino.

Using the solid core wire/jumper wire, connect the Vout pin of each muscle sensor to the analog pins on your Arduino.

Sensor 1 Vout --> Analog pin 0
Sensor 2 Vout --> Analog pin 1
Sensor 3 Vout --> Analog pin 2
Sensor 4 Vout --> Analog pin 3

Then connect the GND pin of muscle sensor 1 to the GND pin on your Arduino and the GND pin of muscle sensor 2 to the Analog pin 3 of your Arduino. That last part will keep the remaining two analog pins from floating along with your sensor 4's output.

Step 12: Upload Visualization Sketch to Your Arduino

By this point, your USB Biofeedback Game Controller should be completely assembled and hooked up. Before we go any further, we'll need to test out your muscle sensors to make sure everything is setup properly.

To test your setup, we're going to use the same visualization software as we used in our muscle sensor demo video. If you haven't already, download and install both the Arduino and Processing software.

Next, download the BarGraph example code on our GitHub repository. Open the Arduino sketch and upload it to your UNO. If you're new to Arduino, check out the information on Arduino's website to help you on this step. Once uploaded, plug in the wall adapter to the barrel jack to power up your muscle sensors.

Next, open the Processing sketch and hit the Run button in the top left. Another window will pop up with 6 colored bars on it. Flex your right forearm, left forearm, right bicep, and left bicep and watch the bars move accordingly. If while at rest, your sensors value is below or above 150 then adjust the gain of your sensor using a screwdriver and turning the poteniometer on the corresponding sensor so that they are around 150 at rest.

As you flex each muscle, the bars should move past the 300 mark. This is important since the software to follow uses the 300 mark to trigger a "button press". You can adjust the gain of your sensor and this threshold level in the code to fine tune your desired button press sensitivity.

Once everything appears to be in working order, close out Processing and you're ready to hack your Arduino into a keyboard.

Step 13: Upload Keyboard Sketch to Your Arduino

Now, we'll work on turning your Arduino UNO into a HID keyboard.

First, Download the Arduino sketech from our GitHub repository, then compile and upload the sketch to your Arduino.

This is the code that, if desired, you would modify the threshold value in to adjust the "button" sensitivity.

Step 14: Hack Your Ardunio to Load New Atmega8u2 Firmware

To play video games on your computer with the Arduino, we're going to turn your Arduino into a HID USB keyboard to interface with your computer; to do this you'll need to upload new firmware.

For Mac:
Follow the instructions on this very well put together blog...
Arduino Keyboard HID Part 1
Arduino Keyboard HID Part 2
Latest Hex Files for Uno and Mega 2560

For Windows:
Download the latest hex files
Then follow the instructions on how to upload the hex files to your board using free software called Flip
Upgrading the Arduino Uno 8U2 using Flip

For Linux:
Download the latest hex files
Then follow the instructions on how to upload the hex files to your board
Building Arduino Atmega8u2 firmware on Linux

Note: You'll need to reflash your Arduino with the original firmware to upload new sketches again

Once your Arduino can be connected to your computer and recognized as a HID device, it should be ready to go. Disconnect it and slide it down into your project enclosure.

Step 15: Playing Super Mario Bros 3

The Mad Science Fair

Runner Up in the
The Mad Science Fair

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest
    • Audio Contest 2018

      Audio Contest 2018

    54 Discussions

    0
    None
    19asanchez

    1 year ago

    The "Download the latest hex files" link you've provided leads to a page not found. Is it essential to the project?

    2 replies

    To the instructions as written, yes. But these instructions are pretty old and I don't maintain them. There's probably a better way to program an Arduino to act as a USB HID than what is described here.

    0
    None
    19asanchez

    1 year ago

    What is the vout pin on the muscle sensors?

    0
    None
    19asanchez

    1 year ago

    The link that you provided for the library is invalid, where can we find a valid library for the muscle sensor code?

    4 replies

    Which link? https://github.com/AdvancerTechnologies/USBBiofeedbackGameController still works fine for me.

    The link works but there is no zip file for the muscle sensor library. Without the library arduino cant configure the code.

    0
    None
    19dmontano

    1 year ago

    How do we update the arduino so that it works? i keep getting "exit status 1

    'MuscleSensor0' does not name a type"

    1 reply
    0
    None
    19dmontano19dmontano

    Reply 1 year ago

    i fixed this error but am now getting "compilation terminated.

    exit status 1

    Error compiling for board Arduino/Genuino Uno."

    0
    None
    19dmontano

    1 year ago

    Would we connect the muscle sensors to the power supply board the same way as the instructions say or no, and is there anyway you can send me a link for the power supply board because the hyperlink you have is down.

    4 replies

    No, the power requirements for the MyoWare are much simpler. I would suggest reading through it's user's manual. There are examples of how to power the sensor via an arduino in it.

    We don't make nor sell the power supply board anymore.

    I've read about some ways that people have done this but they don't pair it with a cable shield and they use where we soldered the cable shield in as their way to connect the board to a power source. If you could look at this and tell me if this is how we should connect it ,because we did not get a users manual with our parts.

    Our sensors don't ship with a physical user's manual; they can be found on our distributor's websites (like you linked) and on our GitHub repository (https://github.com/AdvancerTechnologies/MyoWare_MuscleSensor) along with example code

    0
    None
    19dmontano19dmontano

    Reply 1 year ago

    https://cdn.sparkfun.com/datasheets/Sensors/Biometric/MyowareUserManualAT-04-001.pdf

    0
    None
    19dmontano

    1 year ago

    How do we connect the muscle senors to the cable shield? How will the plastic insert vary with the new muscle senors?

    1 reply

    Use header pins to connect the cable shield to the sensor board. The pins on the shield line up with the pins on the sensor board.

    As for how the plastic insert will vary, this is something you're going to need to work out on your own. Please come back and share your work when done though. I'm sure others will appreciate it!

    0
    None
    syafiq9404

    2 years ago

    can i use arduino UNO R3 ? .. is it use the same steps above ? thank you

    1 reply

    I think the R3 has a different chip for its USB interface. I would recommend looking into that. If the chips are the same, then you can use the same steps.