Controlling Robots with Muscle Signals
You may have controlled a Hummingbird robot with a sensor, but have you ever controlled a robot by detecting the electrical signal from your own muscles? When we saw this video by Tim Hurt from the Lawrence Hall of Science, we knew we had to try it for ourselves. Many thanks to Tim for this inspired idea!
When you contract a muscle, it produces an electrical signal. You can use electrodes to measure this signal; this is called electromyography, or EMG. If you measure the muscle signal with the Hummingbird, you can use it as a sensor. This tutorial will show you how to measure the electrical signal, plot the value to the screen, and use it to control a robot.
This tutorial requires some extra equipment. First, you need a Muscle SpikerShield from Backyard Brains. You probably also want to buy some extra electrodes, because the shield only comes with enough disposable electrodes for two attempts. This experiment from Backyard Brains also has a lot of useful information about the MuscleSpikerShield.
The Muscle SpikerShield is a shield for an Arduino. It can be used with the Hummingbird Duo, but not with the original Hummingbird.
The Muscle SpikerShield is designed to use analog pin A0 on the Arduino Uno. Unfortunately, this pin is already being used by the Hummingbird for something else (LED port 4). To fix this problem, bend the A0 pin on the shield so that it points out from the board. Then use a small piece of wire to connect pin A0 to pin A1. Now you will be able to read the muscle signal through pin A1, which is sensor port 1 on the Hummingbird.
Next, attach the Muscle SpikerShield to the bottom side of the Hummingbird. The shield pins do not go all the way into the ports on the Arduino. You can also attach the electrode cable to the shield.
The other end of the electrode cable has three alligator clips. These will be attached to disposable electrodes that you place on your arm. These electrodes have adhesive that will let you stick them to your skin, but they are disposable, so you can only use them once.
The electrical signals produced by muscles are very small and easily obscured by electrical noise. To maximize the amount of muscle signal and minimize the amount of noise, you need to be very careful about how you place the electrodes. The skin should be clean and free of both hair and lotions.
Two electrodes should be placed on the muscle you want to record. For this example, they were placed on the biceps. The two electrodes should be side by side and along the length of the muscle. For example, the biceps runs from the shoulder to the elbow, so the two electrodes are side by side along a line connecting the shoulder and the elbow. Also, make sure you place the electrodes over the main part of the muscle. You may want to consult an anatomy website or textbook.
The third electrode should be placed over a bony part of the body, like the side of the wrist. The two red alligator clips should be connected to the electrodes on the muscle, and the black alligator clip should be connected to the electrode over bone.
Basically, the Muscle SpikerShield measures the voltage between each red electrode and the black electrode (ground). It then subtracts these voltages to find the change in voltage across the muscle. When you see a spike in the voltage difference, that is the electrical signal produced by your muscle as it contracts. For more information, please see Surface Electromyography: Detection and Recording, particularly the excellent diagram on page 4.
In Scratch, you can use the HB voltage block to read the voltage your muscle is producing.
Start by graphing this data to get an idea of what the signal looks like. The script below will plot approximately 15 s of muscle data on the Scratch stage. If you like, you can modify this program so that when the graph reaches the right side of the screen, it begins again from the left side. That way, the program will continually graph your muscle signal. In this script, we have scaled the muscle voltage by multiplying it by 100; you may need to adjust the scaling factor in your script.
As you look at your graph, you will see that it looks very noisy. You can eliminate some of this noise by taking an average of 10 muscle voltage measurements. To do this, declare variables named sum and mean. Then you can use the code below to find the mean in the repeat until loop. Be sure to change your program so that you graph mean instead of the HB voltage block.
Now your graph should look something like this one. When you are sitting still, you will see small spikes. These are noise. When you contract your muscle, you should see larger spikes. To get a good contraction, it can be helpful to clench your fist or push against something. If you can’t see any muscle spikes, you may need to try new positions for the electrodes (this will require new electrodes).
Once you have a reliable muscle signal, you can use it to control a robot. In this example, we used a model of the elbow. This model shows the bones of the arm. It includes two motors with pulleys attached. The right motor represents the biceps muscle, while the left motor represents the triceps muscles. When the program detects a spike in the voltage of the biceps muscle, it sets the motors to flex (bend) the arm. The ‘e’ key was used to extend (straighten) the arm, since we could only measure one muscle signal. Sample code is given in MuscleExample.sb2. The if statement below was used to flex the elbow. The and statement was used to keep the arm from flexing and extending at the same time.
In this example, we chose to use motors, but you can also use the muscle signal to control lights, sound, or servos!