Skip to content

About

EMG with Arduino

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

EMG with Arduino 🦾

EMG (Electromyography) is a test that analyzes the electrical impulses generated by the contraction of muscle fibers.

This allows us to control any object with the simple movement of a hand. The potential is limitless: it can be applied to hardware (like a servo motor, an RC car, or a robotic arm) or even software (such as controlling a character in a video game).

In this project, we will see how to move a servo motor every time we open and close our hand.


📺 YouTube Tutorial

To see the project in action and follow the steps visually, check out the full video tutorial on my channel: EMG with Arduino


🛠️ What You Need

To replicate this project you will need:

  • Arduino (e.g., Uno, Nano, etc.)
  • EMG Sensor Kit (in this guide, the Fyearfly kit was used)
  • Cable with its electrodes
  • Servo motor
  • 2x 9V Batteries
  • 3x Battery connectors
  • Jumper Wires
  • Breadboard

🔌 Wiring & Connections

The connections must be made according to the following schematic:

EMG Sensor Connections

  • +Vs: Connected to the + of the batteries.
  • -Vs: Connected to the - of the batteries.
  • GND (first): Connected to the GND of the batteries.
  • SIG: Connected to the A0 analog pin on Arduino.
  • GND (second): Connected to the GND of Arduino.

Servo Motor Connections

  • Orange Wire (Signal): Connected to digital pin 9.
  • Red Wire (Power): Connected to +5V on Arduino.
  • Brown Wire (Ground): Connected to GND on Arduino.

⚡ Electrode Placement

In this case, we are going to apply the electrodes to the arm, specifically on a muscle called the flexor carpi radialis. To get a proper reading of the electrical impulses, follow this color-coding scheme:

  • 🔴 Red: Must be applied to the end of the muscle.
  • 🟢 Green: Must be applied to the beginning of the muscle.
  • 🟡 Yellow: Must be applied to a bony part of the arm (this acts as a reference/ground to isolate noise).

💻 How the Code Works

The raw signal coming from an EMG sensor tends to be very noisy and "spiky". If we used this data directly to move the servo, we would get a jerky movement.

To solve this problem, the code implements a Moving Average algorithm:

  1. Sampling: Arduino continuously collects a defined number of readings (DIM) into an array.
  2. Smoothing: It calculates the average of these values, returning a smooth and linear curve visible on the Arduino IDE's Serial Plotter.
  3. Actuation: If the calculated average exceeds the contraction threshold (SOGLIA), the servo moves to 170°. Otherwise, it stays at rest at 10°.

⚙️ Sensor Calibration

Every person and every electrode placement generates signals of different intensities. For the project to work properly, it is crucial to calibrate two constants at the beginning of the code:

// Adjusts the smoothness of the movement
#define DIM 50

// Adjusts the sensitivity to muscle contraction
#define SOGLIA 100
  • DIM (Array Size): Indicates how many samples to use to calculate the average.

    • The larger it is: the movement is more linear but slightly delayed.

    • The smaller it is: the response is reactive, but the movement could be jerky.

  • SOGLIA (Contraction Trigger): It is the value beyond which Arduino considers the muscle "contracted".

    • If the servo moves by itself at rest, increase the threshold.

    • If you have to strain too much to move the servo, decrease the threshold.

About

EMG with Arduino

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages