How to Control Servo Motor using EMG Muscle Sensor | Arduino

In this video we will see how to control the servo motor with an EMG muscle sensor. In this project, we will use Advancer Technologies EMG Muscle Sensor v3. The Muscle Sensor measures the electrical activity of a muscle and produces an analog output signal that can easily be read by a microcontroller. In the coming days we will use this muscle sensor to control a robot hand. Required Hardware Arduino Board -- EMG Muscle Sensor Kit -- Servo Motor -- 9V Battery (2Pcs) -- 9V Battery Connector (3Pcs) -- Breadboard -- Jumper Wires -- Caution: This sensors needs a positive and negative reference voltage. Two power supplies are required. The sensor has a maximum operating voltage of ±18 V; however, I recommend using no higher than ±9 V to minimize the risk of electric shock.

Source Code:
#include <Servo.h>

//Threshold for servo motor control with muscle sensor. 
//You can set a threshold according to the maximum and minimum values of the muscle sensor.
#define THRESHOLD 250

//Pin number where the sensor is connected. (Analog 0)
#define EMG_PIN 0

//Pin number where the servo motor is connected. (Digital PWM 3)
#define SERVO_PIN 3

//Define Servo motor
Servo SERVO_1;

/*-------------------------------- void setup ------------------------------------------------*/

void setup(){
  //BAUDRATE set to 115200, remember it to set monitor serial properly. 
  //Used this Baud Rate and "NL&CR" option to visualize the values correctly.
  //Set servo motor to digital pin 3

/*--------------------------------  void loop  ------------------------------------------------*/

void loop(){

  //The "Value" variable reads the value from the analog pin to which the sensor is connected.
  int value = analogRead(EMG_PIN);

  //If the sensor value is GREATER than the THRESHOLD, the servo motor will turn to 170 degrees.
  if(value > THRESHOLD){

  //If the sensor is LESS than the THRESHOLD, the servo motor will turn to 10 degrees.

  //You can use serial monitor to set THRESHOLD properly, comparing the values shown when you open and close your hand.