In: Electrical Engineering
Measuring muscle activity by detecting its electric potential, referred to as electromyography (EMG), has traditionally been used for medical research. However, with the advent of ever shrinking yet more powerful microcontrollers and integrated circuits, EMG circuits and sensors have found their way into all kinds of control systems.
This sensor will measure the filtered and rectified electrical activity of a muscle; outputting 0-Vs Volts depending the amount of activity in the selected muscle, where Vs signifies the voltage of the power source. It’s that easy: stick on a few electrodes, read the voltage out and flex some muscles!
(OR)
Measuring muscle activation via electric potential, referred to as electromyography (EMG) , has traditionally been used for medical research and diagnosis of neuromuscular disorders. However, with the advent of ever shrinking yet more powerful microcontrollers and integrated circuits, EMG circuits and sensors have found their way into prosthetics, robotics and other control systems. Yet, EMG systems remain expensive and mostly outside the grasp of modern hobbyist.
Electromyography (EMG) is a method to evaluate motor unit action potential activity in a muscle region. As action potentials (electrical signals) propagate through nerves to neuromuscular junctions, the change in electrical potentials (voltage) can be measured. EMG is performed in the clinical setting to diagnose functional abnormalities of muscle; in this procedure, a needle electrode is inserted directly into a muscle to monitor an area smaller than 1 square millimeter.
Surface EMG is a non-invasive method of measuring muscle activity. Rather than using needle electrodes, conductive gel electrodes are placed on the skin to measure overall activity of a large region of muscle fibers. The voltage measured represents the amount of force a muscle (or group of muscles) is exerting in real-time. Surface EMG is commonly used in biomedical engineering applications to connect human muscles to the outside world, e.g. interfacing a residual limb with a myoelectric prosthesis, controlling a limb within virtual reality, and providing biofeedback for muscular pain.
Parts needed
MyoWare
Arduino Uno
22-gauge wire (3-conductors)
A computer
EKG electrodes
What is MyoWare?
MyoWare is a small surface EMG sensor developed by Advancer Technologies as a Kickstarter project a few years ago. It automatically analyzes the incoming raw voltage signal and outputs a smooth positive waveform of integer values, as depicted by the graph below (more details are found in the MyoWare datasheet). The new version of MyoWare also outputs the raw voltage data for customized filtering and processing.
What is Arduino?
Arduino is an open-source project that has designed a family of simple computers that provide an interface between sensors and control of physical devices. Because the schematics to design the products are open-source, other companies may freely reproduce the models as well. These unofficial devices are often cheaper and generally reliable. The Arduino “Uno” is a good starter model with a fair amount of inputs and outputs.
Arduino devices are programmed using a simplified version of the C language. A user writes code on a computer and transfers this code to the Arduino by USB. Then, the Arduino can be powered by USB or a battery without the need for a computer.
Preparation
Browse through the MyoWare data sheet for helpful information about the sensor.
Find the three holes on the edge of the MyoWare that are labeled (+),(-), and SIG (signal). Solder a 22-gauge wire to each hole. Solder the other ends to header pins (pins can be found in an Arduino starter kit).
Connect the MyoWare’s (+) wire to the +5 output header on the Arduino and (–) to the Arduino GND (ground) header. Connect the signal wire to A0 on Arduino. Connect Arduino to the computer via USB cable.
Download and install Arduino editor. Alternatively, use the web-based Arduino Create developer environment.
Arduino Code
Arduino programs are called sketches and have .ino file extensions. Create a new sketch (File -> New) to generate the code below. The lines starting with // are comments for humans and ignored by the computer.
void setup() {
// put your setup code here, to run when Arduino is powered on:
}
void loop() {
// put your main code here, to run repeatedly:
}
void setup(){} is a function (a set of instructions) that is run when the Arduino is powered on. void loop(){} is a function that repeats continuously, approximately once every millisecond though the rate depends on the complexity of the code. Your program instructions will run in here.
“void” just means the function does not return any value when it is run. You can think of C functions like math functions, e.g. f(x) = 2x. If I perform f(3) in pre-calculus class, the “return value” is 6. Below is how the same mathematical function would look in Arduino code.
int f(int x){ // first int means the function returns an integer
return 2 * x; // end each statement with a semicolon
}
// run our function & assign result to the variable someMathProblem
int someMathProblem = f(3);
void printMathResult(){
println(someMathProblem); // prints out 6
}
printMathResult(); // this runs the function that prints 6.
// Notice we cannot assign the result to a variable,
// because the function returns void [nothing]
You do not need to add the f(x) and printMathResult() functions to your Arduino file; they are only included here as an explanation of functions.
3. Next, assign outbound pin #13 to a descriptive variable name. Define your voltageThreshold (MyoWare outputs data on a scale of 0–1023, so 400 is approximately 40% activity) These variables are defined outside of the setup and loop functions. In the setup() function, begin listening to the incoming data from MyoWare using Serial.begin(9600). 9600 represents the baud rate, or the number of 0’s and 1’s (bits) Arduino will transmit per second. We also setup pin #13 to be an output rather than input.
int onboardLED = 13; // Arduino onboard LED (pin 13) you can control
int voltageThreshold = 400; // any reading higher will trigger an action
void setup() {
// put your setup code here, to run when Arduino is powered on:
Serial.begin(9600);
pinMode(onboardLED, OUTPUT);
}
4. Add programming logic code to run repeatedly in loop():
void loop() {
// put your main code here, to run repeatedly:
int currentVoltage = analogRead(A0); // store the incoming voltage
Serial.print(currentVoltage); // prints voltage to monitor
if(currentVoltage > voltageThreshold){
// trigger actions
Serial.println("CONTRACTION!"); // prints string + new line
digitalWrite(onboardLED, HIGH); //this sends 5V, turning on LED
} else {
Serial.println(""); // adds a new line
digitalWrite(onboardLED, LOW);
// turn off the light if threshold is not met
}
}
If the currentVoltage coming from MyoWare is greater than the voltageThreshold we previously defined, then do all the statements within the first curly braces { }. If the currentVoltage is anything else (numbers less than the threshold or no value at all), then run the statements in the curly braces within else { }.
Build and send the code to Arduino, which must be connected by USB at this point. If building fails due to an error, take a look at the message and line number and make sure there are no spelling mistakes or missing parentheses or semicolons in the code. Also click Tools -> Board: -> and make sure Arduino Uno is selected.
Attach the MyoWare to a muscle via electrodes. You may need to trim the electrode adhesive borders so they fit properly. The sensor works well over many muscles including paraspinals. Try recording the flexor digitorum superficialis or biceps brachii first.
7. Open Tools -> Serial Monitor in the Arduino coding application to see voltage readings streaming in.
Example of Serial data from MyoWare. Values will range from 0 to 1023.