Introduction: EMG Basketball With an Arduino Uno

Nowadays, widely available wearable sensors make it possible for everyone to create new things that we can control without using a mouse and keyboard or a controller, and have a lot of fun doing so. In this project, we wanted to make a game that used your muscle movements to control the action, and make it easy to use. So, we designed our game with a few things in mind:

  • We want the game to be customized to the person, since everyone has slightly different EMG patterns
  • We wanted the sensor to be lightweight and wearable
  • We wanted the game to be able to run, even if you couldn’t quite get the sensor to work all the way.

Our final product was an EMG basketball game that used the EMG signal to throw the ball, and set the hoop based on the signal strength. You can see the end product of the sensor setup in the image above! The rest of the guide will walk you through the steps to build the sensor, and set up the game. We hope you enjoy it!

Supplies

Tools Needed:

  • Wire Strippers
  • Soldering Iron
  • Electrical Solder
  • Electrical Tape
  • A computer that can run MATLAB

Materials:

  • 1x Arduino Uno with USB to USB-A connector- This is the brains of your sensor, and sends the raw signal data it receives to the computer
  • 1x MyoWare Muscle Sensor - used to get your EMG data
  • 1x Set of button EMG sensor electrodes - You'll need three to set up the sensor, and you will want extras in case more than one person uses the sensor.
  • 3x 4-foot lengths of Silicone Stranded Core Wire(Recommended) or 4 feet of Doorbell Wire(three stranded)- You can get the Doorbell wire from your local hardware store, but the core wire will be much more flexible. This connects from the sensor to the Arduino itself.

Software:

  • A valid MATLAB license- You'll need this to run our code, and to have all of the support packages that you need.
  • The free Arduino Support Package for MATLAB- This is how we connect to the Arduino in the code

Step 1: Assembling the Sensor: Preparing the Wires

We based our procedure and some of the materials we used off of this guide, which does an excellent job of explaining what to do to build the sensor. We simplified the procedure a little, though, as we found that if you use a solid and sturdy wire, like the doorbell wire we used, you won't need to have an additional connection to a jumper cable to connect the wires to the Arduino in the last step. If you're using a braided or flimsy wire, through, you will want to include jumper cables, and attach them to one end of your leads.

If you have continuous wires, you’ll want to measure out 3-4 foot lengths of wire and cut them, so that you have one wire for positive, negative, and signal wires leading from the EMG sensor to the Arduino. After this, you’ll want to strip a small portion of the wire using a set of wire strippers. We were able to do this using the 22 size on the wire strippers. On the side that you’ll be soldering to the sensor, be sure to leave a little bit of extra space, as the soldering iron will burn the plastic used very quickly.

Step 2: Soldering the Wires to the Sensor

Following the guide from Adafruit, soldering the wires to the EMG sensor is a straightforward task. First, you need to indicate which wire is your positive, negative, and signal lead, using tape, or differing wire colors. Next, gather the solder, the soldering iron, and the EMG sensor, and start heating the iron. Once the iron is hot, solder the wires on one by one to the sensor.

If you haven’t soldered before, you can do this in two or three steps. First, put the sensor in a location where you can securely feed the wire through, so that it won’t move when you press against it. If you're soldering wire to wire, you'll want to wrap the ends you are connecting to each other instead. The first image shows this part. Next, take the now-hot iron and the solder, and press the solder and the iron against the wire. The second image shows this. The solder and the iron should both touch the wire. The process will likely take a minute, but the solder will relatively quickly melt off the end of its coil and into the hole where the wire is. Once this happens, pull away the iron and solder coil, and wait a few seconds for the solder to harder. You can blow on it to speed up the process, but it will be done relatively quickly.

When you repeat this process for the other two leads, make sure that you keep the orientation the same, that way it will be easier to manage. The second and third images show wires soldered to the EMG sensor, and where the contacts are on the sensor. After all three leads are soldered to the EMG Sensor, braid the three leads together so that they are one completed bundle, and use rubber bands or zip ties to secure them together. This will make it easier to manage the wires, and keep everything together when you move.

Step 3: Finishing Assembling Your Circuit

The circuit to use the EMG sensor is simple to set up! All of the connections that you need are marked on your Arduino, and should all be on the same side.

First, put the signal lead into the digital 1 channel on the Arduino. This will let the signal be read by the Arduino and transferred to the computer. Next, hook up the positive lead to the 5V channel marked on the Arduino, and the negative lead to the ground channel on the Arduino. Once this is done, you should see a green light indicating power to the sensor. If you touch all three electrodes at the same time, you should also see an orange light indicating it is receiving a signal. If you don’t get either of these, you may need to re-solder the connections in order to make the sensor function properly. When you're all finished, you should be able to see something similar to the last image!

Step 4: Installing the Prerequisite MATLAB Package

The first thing that you need to do is install the Arduino Support Package for MATLAB. This allows you to interface with your Arduino Uno and get signals from it. To do this, you can go into your MATLAB, then navigate to the Add-ons Manager in the home tab. Once inside, search for the support package and hit install. Follow the instructions for the installer, and then your package will be ready to use! All you need to do to integrate the Arduino Uno is plug it into your computer using the cable. Once you have the sensor set up, you’ll be ready to run the code!

Step 5: Setting Up the Completed Device

You're just about ready to go! The only thing left to do is making sure everything is connected to the computer, and then positioning the sensor on your arm. Like in Step Three of the hardware section, setting up the completed device involves hooking it up properly to the Arduino. Attach the positive lead to the 5V output, the negative lead to ground, and the signal lead to the digital 1 input channel on the Arduino. It should look like this when it’s set up to go, and you should see a green and orange light on the sensor. Next, you’ll need to attach the sensor to your bicep in order to get a full signal. To do this, take the adhesive pads and put them onto the three contacts that the sensor has. Next, put the main body of the sensor in the middle of your bicep, making sure the two contacts are securely on your arm. The third contact needs to connect to an area on a different muscle, off to the side. We put the main sensor on the bicep toward the bottom of the upper arm, and placed the third electrode just behind the elbow, so that it was on a different muscle than the rest of the sensor. This allowed us to get a good signal. An example of this can be seen in the first image. Once you have this, you’re all set to use the device!

Step 6: Running the Game!

To run the code, run the rundata.m file in your MATLAB folder from Step 2. It will take you through two phases: Calibration and the game itself. The code will take you through the calibration phases, starting with a fully relaxed arm, moving to half flexion, then full flexion, requiring you to press enter to proceed to each phase. Once you’re done with this, it calculates the range of EMG voltages that you made, and makes a custom scale, so that each person who starts up the game plays based on their own body's signals. The game calculates the height of the hoop based on this calibration phase, too. When you play the game, you flex your arm to throw the ball at the hoop, and the height of your throw depends on the strength of your arm's flexion. The first image shows a basic image of how this works.

Now you're all set to play the game! The last image shows a screenshot of what the game looks like.