Introduction: Typing With EMG Using MyoWare

Authors:

L. Elizabeth Crawford & Dylan T. Vavra

Introduction:

In this tutorial, we are going to show you how to create a simple at-home electromyography (EMG) system - at the cost of about $100 - that will sense muscle activation from the surface of the skin and use it to send a keypress to a computer, bypassing the keyboard. We used a classic MaKey MaKey and a MyoWare sensor to accomplish this, along with a bit of coding. This project also requires some soldering. Useful tips for soldering technique and safety can be found here.

First, we will show you how to accomplish this using one MyoWare sensor. Then, we will show you how to add a second one to the system (for our purposes, we used two).

Our hope is that others will be able to mimic this DIY EMG technology, adapt it to their specific needs, and use it for any number of interesting applications. We used it in our Experimental Psychology lab at the University of Richmond to replicate research showing that people mimic others' facial expressions.

Step 1: Gather Your Materials.

Materials:

  • Computer
  • MaKey MaKey with accompanying USB cable (you should be able to do this with an Arduino Leonardo as well, but we haven't tried it)
  • USB Power isolator (unless running off of a battery-powered laptop), such as the Adafruit USB Isolator - 100mA Isolated Low/Full Speed USB (not pictured)
  • MyoWare sensor(s)
  • Electrodes (x3 per MyoWare sensor) - we used Covidien Kendall Disposable Surface EMG/ECG/EKG Electrodes 1" (24 mm)
  • Breakaway headers (we used L-shaped headers)
  • Wires with male connector on one end, female on the other
  • Solder
  • Electrical tape

Tools:

  • Soldering iron
  • Wire cutter
  • Wire splitter

Software:

  • Arduino IDE with MaKey MaKey addon

Step 2: Prepare the MyoWare Sensor.

1. Break off a set of three breakaway headers for soldering to the MyoWare.

2. With the MyoWare sensor positioned with the bicep face up, insert the shorter end of the three headers from below into the holes that have a "+" (plus sign", a "-" (negative sign), and "SIG" next to them. (See picture above.)

3. Solder the headers in place.

Step 3: Connect the MyoWare Sensor to the MaKey MaKey.

1. Pick three wires (ideally of different colors), male on one end, female on the other. The length of the wires you need depends on how far you want the MyoWare to be from the MaKey MaKey. To have the MyoWare on the face and the MaKey MaKey resting on a table, you'll need about 18 inches.

2. Decide which function the wire of each color will serve. One will be used for power (plugging into the + connector on the MyoWare sensor), one will be used for ground (plugging into the - connector on the MyoWare sensor), and the third will be used as the signal wire (plugging into the SIG connector on the MyoWare). In the pictures shown in this instructable, we're using green for power, brown for ground, and gray for signal.

Step 4: Upload Sketch to the MaKey MaKey.

1. Install Arduino IDE on your computer (Tutorial here).

2. Install the MaKey MaKey addon for Arduino (Tutorial here) by opening your Arduino preferences (File > Preferences), going to Additional Board Manager URLs text box, and pasting in:

https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json

3. In the Arduino IDE, click file, pull down to create a new sketch. Copy and paste this code into the text window:

/* thresholds for registering a key press*/
const int thresh1 = 1000;
/*assignment of inputs on MaKey MaKey*/
const int sensor1Pin = A3;
#include "Keyboard.h"
int LED (9);
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
/*The code below samples the MyoWare every 50 ms, sends its value to the serial port, and if the value is above threshold, sends a keypress. You can sample more frequently by reducing the delay. This will make the values harder to read in the serial window.*/
void loop()
{ int sensor1Val = analogRead(sensor1Pin);
Serial.println(sensor1Val);
if(sensor1Val >= thresh1)
{
Keyboard.begin();
// Sends keypress of letter "c"
Keyboard.write('c');
//wait 50 ms before sampling again
delay(50);
}
else
//wait 50 ms before sampling again
delay(50);
}

4. Connect the MaKey MaKey to your computer. Pull down the tools menu and make sure the selected board is Arduino Leonardo or MaKey MaKey. Pull down the tools menu to Port, and make sure the selected port has the name of your selected board. Upload your sketch to the board by clicking the right facing arrow at the top of the Arduino IDE.

Step 5: Connect All of Your Components Together.

1. Connect wires from the MyoWare sensor to the MaKey MaKey as follows:

  • The "+" on the MyoWare goes to the 5V slot on the MaKey MaKey.
  • The "-" on the MyoWare goes to the ground ("earth") on the MaKey MaKey.
  • The "SIG" on the MyoWare goes to the A3 slot on the MaKey MaKey.

2. Snap three electrodes to the MyoWare.

3. Plug in the MaKey MaKey. If using a computer connected to a power outlet, plug the MaKey MaKey into a USB power isolator and then plug that into the computer's USB port. (This is a safety precaution so that if something goes wrong with the power supply in your computer, the wearer is not directly connected to the electrical grid. It is unlikely that such a problem would occur, but we'd rather you be safe.) If using a laptop running off of a battery (i.e., NOT PLUGGED INTO THE WALL) you're safe without the isolator.

4. Check to see that everything is powered up. The MaKey MaKey red LED and the MyoWare green LED should both be lit.

5. Cleanse the skin where you want to attach the MyoWare with rubbing alcohol to remove dirt and oils.

6. Peel off the adhesive backing on the electrodes and attach the MyoWare to the skin. You want the two electrodes that are on the MyoWare to be on top of the muscle that you want to record from. The electrode attached to the wire serves as a comparison, and should be placed off of the muscle in an area that will not be active when the target muscle is contracted.

7. Check the adhesive on the electrodes to make sure you have a good seal to the skin. You may need to press the edges of the adhesive rings into the skin to get a good seal.

Step 6: Setting Thresholds in Arduino IDE

1. With everything connected and powered on, open the serial monitor in the Arduino IDE by clicking on the magnifying glass tool in the top right corner.

2. The serial monitor should now show the signal values from the MyoWare. As you flex and relax the muscle, you should see the values change accordingly. You should also see the red LED on the MyoWare light up when you contract the muscle hard enough.

3. While watching the serial monitor, contract the muscle with different intensities, being sure to relax in between contractions in order to get back to baseline. Determine a threshold value above which you want the contraction to produce a keypress. Higher values will require a stronger contraction to regist the keypress; lower values will make it more sensitive to small contractions but also more prone to false alarms.

4. In the Arduino sketch, change the threshold value (const int thresh1) from 1000 to your chosen threshold.

5. Close the serial monitor, re-upload the sketch, and start typing with EMG. You may find you need to readjust the threshold to get the sensitivity where you want it. You can also experiment with the delay so that it samples more or less frequently.

Step 7: Enjoy Using Your New Home-made EMG System!

You can place the electrodes in a multitude of places on the body (for instance, on the face, as our lab cyborg Kyle Lee depicts above).

Experiment with locations to put the electrodes and with the many possibilities of what you could use the keypresses to do.

Also, continue reading to learn how to add another MyoWare sensor to this system.

Step 8: Add a Second Sensor to Your EMG System.

1. Repeat Step 2 for a second MyoWare sensor.

2. To attach multiple sensors to one MaKey MaKey, you'll need a way to get power to each one. We did a bit of wire stripping, soldering, and taping to create a Y-shaped connector (see picture above), splitting the single output from the MaKey MaKey's power supply in to two wires that connect to the "+" power input on each of two MyoWares.

3. Connect the "SIG" slots on the MyoWare sensors to different A-slots on the right side of the MaKey MaKey (the code we provide below assumes you're using A3 and A4).

4. Upload the sketch for two sensors:

/* this sketch reads two MyoWare sensors signals and sends a keypress 'b' when one goes above threshold and 'c' when the other goes above threshold.*/
/* set thresholds*/
const int thresh1 = 1000;
const int thresh2 = 1000;
/*assignment of inputs on MaKey MaKey*/
const int sensor1Pin = A3;
const int sensor2Pin= A4;
#include "Keyboard.h"
int LED (9);
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop()
{ int sensor1Val = analogRead(sensor1Pin);
int sensor2Val = analogRead(sensor2Pin);
Serial.print(sensor1Val);
Serial.print(",");
Serial.println(sensor2Val);
if(sensor1Val >= thresh1)
{
Keyboard.begin();
// Send keypress c
Keyboard.write('c');
delay(50);
}
if(sensor2Val >= thresh2)
{
Keyboard.begin();
// Send keypress b
Keyboard.write('b');
delay(50);
}
else
//wait 50 ms before sampling again
delay(50);
}

5. Now both muscle readings should be visible in the serial monitor. Set each threshold separately in the Arduino sketch, just as in Step 6, and then reload the sketch.

Now your EMG system will have two separate inputs!

If you get to feeling a little wild, you could follow similar procedures to add more MyoWare sensors to the system. If you get to feeling REALLY wild, you could even add another MaKey MaKey to the system. We encourage you to experiment with this design.