Whenever your nervous system needs to make a movement, it sends tiny electrical signals through neurons to control your muscles. The technique of electromyography (EMG) allows us to amplify and measure these electrical signals. In addition to being a useful clinical tool for diagnosing different neurological disorders, EMG recordings have been used more recently to control prosthetic devices.
In the hopes of becoming more familiar with EMG amplification and recording techniques, I thought it'd be fun to build an EMG amplifier that I could then use as a control signal for a different device. Rather than controlling a prosthetic arm, I decided to incorporate my interests in music and used the EMG signals to control a MIDI device. MIDI stands for Musical Instrument Digital Interface, and is the standard protocol for sending and receiving musical signals electronically.
This Instructable includes breadboarding a circuit, soldering a few wires, programming an Arduino, and interfacing with a MIDI device. If you don't have some of this necessary background, I recommend checking out some of classes / Instructables below:
Safety Note: This project does involve connecting oneself to an electrical circuit. Take all necessary safety precautions. This paper from Delsys has a section on electrical safety as well as a useful description of EMG techniques in general. We'll be powering our circuit off of two 9V batteries; at no point should your circuit (especially when you're connected to it as well) be connected to AC power from the wall.
Step 1: Project Overview and Parts List
Our project is composed of three main components:
The 1.) EMG amplifier, 2.) the Arduino, and 3.) the MIDI device.
- We'll build the EMG amplifier on a breadboard. I plan on writing a more in-depth Instructable focused solely on the EMG amplifier soon.
- We'll power the Arduino from the same 9V batteries that power the EMG amp. Most of the work with the Arduino will be on the software side.
- I used an iPhone running Garageband as my MIDI device. The Arduino will send standard MIDI signals over a standard MIDI cable, so any MIDI device should work in place of the iPhone.
- (2x) LT1167 (instrumentation amplifier)
- (2x) LT1112 (or any dual op-amp chip)
- (1x) LM386N (audio amplifier)
- (5x) Surface EMG electrodes (two per muscle and one for a reference) (Amazon)
- Arduino Uno (Amazon)
- iPhone (or any MIDI device)
- MIDI to iPhone adapter cable (if using an iPhone) (Amazon)
- Various resistors, capacitors, and jumper wires
- Breadboard (Amazon)
- (2x) 9V battery
- Soldering iron (Amazon)
- Wire strippers
- Heat shrink tubing
- Electrical tape
Step 2: Assemble the EMG Amplifier
We'll build an EMG amplifier capable of amplifying two EMG channels. We'll use one LT1167 instrumentation amp per channel. The LT1167 datasheet helpfully contains a schematic for a "Nerve Impulse Amplifier," which we will follow in this step.
Assemble the circuit
On the breadboard, assemble two copies of the nerve impulse amplifier shown above. The pictures of my assembled circuit should help guide you towards the end goal. I added passive 1st order low-pass filters to the output of each my amplifiers to help reduce noise. If you'd like to add them to your circuit, I used a 1 kΩ resistor with a 0.047 μF capacitor for a cutoff frequency of approximately 2,000 Hz.
We'll be powering the circuit off of two 9V batteries. The LT1167 needs a +V and -V (because the EMG source signal has both positive and negative values), so we'll connect the minus pin on the +V battery to the plus pin on the -V battery. The minus pin on the -V battery becomes the -V value. When using two 9V batteries, you'll end up with +V and -V being equal to +9 and -9 volts respectively.
The next step covers the electrode placement in more detail. The reference electrode plugs into pin 1 of one of the instrumentation amps, and the muscle electrode pairs plug into pins 2 and 3 on the instrumentation amps. The +/- orientation of the electrodes does not matter.
Note:If your circuit isn't working, you probably did something wrong! A good technique for finding a mistake in a circuit is to draw out the schematic for the circuit you've actually assembled on your breadboard and compare it to the original schematic. In that process you may find an error (as I did many a time).
Step 3: Prepare the Electrodes
As I mentioned above, we'll need a total of five electrodes for this project. EMG recordings are conducted with a differential amplifier, meaning we are amplifying the difference between two points of reference on the muscle. This means we'll need two electrodes per muscle. Additionally, we need a single reference for the muscle activity to be measured with respect to. Here is a link to some surface EMG electrodes sold on Amazon. The exact type of electrode isn't too important for our purposes.
Like I've shown in the picture above, place two electrodes on the inside edge of each forearm, parallel to the length of the muscle and separated by about 2 cm. Place the reference electrode on the bony part of one of your elbows, away from the electrodes on the muscles.
Twisted wire pairs
You'll also want to twist the wires on your electrode pairs as shown above. In addition to cleaning up the mess around your circuit, twisted wire pairs help reduce electrical noise picked up by the electrodes. By alternating the position of the wires back and forth, any external electromagnetic interference (e.g. 60 Hz from mains) will affect the wires an equal amount. The differential amplifier will then remove this common noise signal.
Step 4: Audio Amplifier (optional)
If you're interested in listening to the raw EMG signal (without any MIDI) you can add an audio amplifier to your EMG circuit. Use an LM386N audio amplifier chip and the necessary resistors and capacitors to assemble the circuit shown above. The video above demonstrates what a raw (well, there are some filters in the circuit, but it's mostly raw) EMG signal sounds like.
While this step is not necessary for triggering the MIDI signals, I do suggest you attempt it. Listening to the EMG signal can be a very helpful technique for troubleshooting and debugging your system. For example, if there is a strong 60 Hz interference from mains power, you'll be able to hear it much easier than you'd be able to detect it when sampling the signal with your Arduino.
The audio in my video is clipping a bit, but it's a pretty decent example of what a clean EMG signal should sound like.
Step 5: Prepare the MIDI Components
In order to send MIDI signal from the Arduino to the MIDI device, we need to solder up one of the female MIDI jacks. You should check out my first Instructable for a more thorough tutorial on setting up MIDI on Arduino.
Here are the steps:
- Solder a 220 Ω resistor to pin 4 of the MIDI connector.
- Solder a 10 cm wire from the resistor to the Tx connector on the Arduino.
- Solder a 10 cm long wire to pin 2 and connect it to ground on the Arduino.
- Solder a 10 cm long wire to pin 5 and connect it to 5V on the Arduino.
Once you've assembled the EMG amplifier and prepared the MIDI to iPhone cable, use two jumper wires to send the outputs of the instrumentation amplifiers to pins A4 and A5 on the Arduino.
Step 6: Write the Arduino Code
The basic pipeline for the Arduino code is as follows:
- Measure the baseline noise level for both EMG channels
- Loop continuously, measuring the voltage of each EMG channel
- If the EMG channel controlling the note intensity crosses the threshold, trigger a MIDI note on
- Use the signal from the other EMG channel to modulate the pitch of the note
I encourage you to try writing your own Arduino code to process the EMG signals. I know for sure there is a better control scheme out there than what I cobbled together! If you do want to start with my code, feel free to download it here. You can check out my GitHub repository to see the various iterations of my code while I was working on the project.
Step 7: Put It All Together!
If all has gone according to plan, you should be able to control your MIDI device using the signal from your own muscles. Pretty exciting! Once you have the project working you can play around with different control schemes and explore different MIDI sounds.
Let me know if you try to make one of your own EMG-controlled MIDI devices! I'd love to hear how it goes and would be happy to help with any questions that come up along the way. Good luck!