Imagine controlling a racing game without touching a keyboard or controller—using nothing but your muscle movements.
In this project, you'll build a 2-channel Electromyography (EMG) game controller that translates forearm muscle activity into keyboard inputs. Using the DIY Neuroscience Kit Pro, the system detects muscle contractions from both forearms and maps them to different keyboard keys, allowing you to steer and drive a racing game naturally.
The controller recognizes four different actions:
- Right forearm flex → Turn right (
D) - Left forearm flex → Turn left (
A) - First simultaneous flex of both forearms → Activate Forward Mode (
W) - Next simultaneous flex → Toggle Reverse Mode (
S)
Instead of pressing keys manually, your muscles become the controller, demonstrating how biosignals can be used to create intuitive Human-Computer Interaction (HCI) projects.
NOTE: This project is made by Ankit Dhillon.
What is Electromyography (EMG)?
Electromyography (EMG) is a technique used to measure the electrical activity generated by skeletal muscles during contraction.
Whenever your brain sends a signal to move a muscle, tiny electrical impulses travel through the motor neurons. EMG sensors capture these signals, allowing computers and embedded systems to detect muscle activity.
EMG technology is widely used in:
- Prosthetic limb control
- Human-Computer Interaction (HCI)
- Gesture recognition
- Robotics
- Rehabilitation research
- Biomedical engineering education
In this project, we use EMG signals to replace conventional keyboard controls with muscle gestures.
This project creates a 2-channel EMG acquisition system.
- Channel 1 records muscle activity from the right forearm.
- Channel 2 records muscle activity from the left forearm.
The Arduino continuously processes both EMG channels and converts muscle contractions into keyboard events that control the racing game.
Hardware AssemblyStep 1 – Install the Muscle BioAmp ShieldStack the Muscle BioAmp Shield securely onto the Arduino UNO R4.
Connect the BioAmp EXG Pill to the A2 port on the Muscle BioAmp Shield using the supplied STEMMA cable.
Attach one BioAmp cable to the BioAmp EXG Pill and another to the Muscle BioAmp Shield through their JST connectors.
Good electrode contact is essential for clean EMG signals.
Apply NuPrep Skin Preparation Gel to each electrode location to remove dead skin cells and reduce skin impedance. Afterwards, clean the area using an alcohol wipe or wet wipe before attaching the electrodes.
For Channel 1 (Right Forearm)
- Positive (+) electrode: Right forearm
- Negative (−) electrode: Right forearm
- Reference electrode: Back of the right palm
For Channel 2 (Left Forearm)
- Positive (+) electrode: Left forearm
- Negative (−) electrode: Left forearm
- Reference electrode: Back of the left palm
- This configuration enables independent acquisition of EMG signals from each forearm, allowing separate detection of left and right muscle contractions.
1. Copy the code from the GitHub repository.
2. Open the Arduino IDE
3. Install the Arduino UNO R4 board package:
- Tools → Board → Boards Manager → Search "Arduino UNO R4 Boards" → Install the latest version.
Note: If any installation or permission pop-up appears during the process, click OK, Install, or Allow to continue the installation.
4. Create a new sketch:
- Go to File → New Sketch.
5. Remove the default code:
- Press Ctrl + A to select all the existing code and press Ctrl + V to paste the copied code.
6. Connect the Arduino board to your laptop using a USB cable.
7.Select the board:
- Go to Tools → Board.
- Choose Arduino UNO R4 Minima.
8.Select the correct port:
- Go to Tools → Port.
- Select the port corresponding to your Arduino board.
(if you can't find your port disconnect the Arduino and reconnect again)
9.Upload the code:
- Click the Upload button (→) in the Arduino IDE.
- Wait for the upload process to complete successfully.
Once the upload is complete, the Arduino is ready to run the program.
IMPORTANT: For the best signal acquisition, make sure your laptop is not connected to a charger and sit at least 5m away from any AC appliances.
Now test the code:
1. Open any text editor like Notepad.
2. Flex your right forearm ->The key 'd' should be typed once.
3. Flex your left forearm -> The key 'a' should be typed once.
4. Flex both arms together(first time) -> The key 'w' should be typed continuously.
5. Flex both arms together(second time) -> The key 's' should be typed continuously.
If the detection is not accurate, you may need to calibrate the threshold values according to your muscle strength.
Follow these steps for calibration:
- Open the Arduino code and locate the following line:
- Uncomment the line so that it becomes:
#define calibrate- Upload the modified code to the Arduino.
- Open the Serial Monitor from the Arduino IDE.
- Flex your left forearm muscle several times while observing the values displayed in the Serial Monitor. Record the maximum peak value reached during a strong muscle contraction.
- Next, flex your right forearm muscle several times and record the maximum peak value for that channel.
- Calculate the threshold values by taking approximately 60–70% of the peak value measured for each channel.
- Update the threshold values in the code with the newly calculated values.
int envelop1threshold = 40;
int envelop1threshold = 40;- Comment out the calibration line again:
//#define calibrate- Upload the updated code to the Arduino.
- Test the controls in the game. If necessary, repeat the calibration process and
- fine-tune the threshold values until reliable muscle detection is achieved.
Testing the Controller:
Before launching the racing game, verify that the controller is generating the correct keyboard inputs.
- Open a text editor such as Notepad.
- Perform the following muscle gestures and observe the output:
- Flex your right forearm → Presses the D key once.
- Flex your left forearm → Presses the A key once.
- Flex both forearms simultaneously (first time) → Continuously presses the W key (Forward Mode).
- Flex both forearms simultaneously (second time) → Continuously presses the S key (Reverse Mode).
If the output matches the expected keyboard inputs, the controller is ready to play the game.
const char MODE_1_KEY = 'w'; // Forward
const char MODE_2_KEY = 's'; // Reverse
const char LEFT_ARM_KEY = 'a'; // Turn Left
const char RIGHT_ARM_KEY = 'd'; // Turn RightConclusion:This was just a demonstration to show you how both the sensors (BioAmp EXG Pill & Muscle BioAmp Shield) can be used together to create a 2-channel EXG acquisition system and play games. In this project, we used BioAmp EXG Pill to record EMG signals, but it can also be used to record other biopotential signals as well like ECG, EOG, o


Comments