Experiment: Controlling a Robotic Gripper

What will you learn?

In the following experiment you will learn to control a gripper hand with the EMG signal of your muscles. This Gripper will open and close depending on the strength of the signal you make when contracting the muscles of your hand; you can perform this experiment to impress your friends, for a school science fair, or just to dive into the study of Neuroprosthetics!

Where can I get a Gripper? You can get this this kind of robotic structure at any store that sells electronic kits and robotic parts. You can even make one with plastic at home. There’s a lot of information on the Internet with texts and videos that describe the steps and materials needed to build one. Here are some sites that show you how to create one:   Thingiverse   Instructables

Background  Gripper

Designed and written by José Enrique López Pérez, student of Electronic Engineering in Oaxaca, Mexico.


To make robots people often use servomotors. They are popularly called “servos” and are useful for their small size, low power consumption, and high accuracy. They can be found in the steering control of a toy car or at the helm of a ship or aircraft, for example… A servo motor is made up of small DC motor, a gear transmission which reduces speed and increases strength, and a small circuit control that makes it possible to move the motor accurately.

What is the difference between a stepper motor and a servo motor?

Inside a stepper motor there are coils and it’s necessary to apply a series of pulses to them for the motor to rotate a certain number of steps; This is why it has so many wires coming out of it (usually 5 to 6 wires). However, inside the servo motor there is one DC motor and a circuit control which enables precise positioning of this motor using only three wires, one for control and the other two for power and ground.

Some significant differences between a servomotor and a stepper motor are: speed, strength, and accuracy; the servomotor can move with a velocity greater than a stepper motor, and with more strength and accuracy. A stepper motor is normally not used in high speed applications because at these speeds it loses strength. However, at low speeds the Stepper motor is more accurate and stronger than the servo, that’s why it’s widely used in industrial robot arms.

Servomotor Functionality:

The PWM (Pulse Width Modulation) is the most commonly used system for servo control. This system generates a square wave which changes the amount of time the pulse is high, keeping the same period; a high level duration of the signal indicates the position where we want to put the motor shaft. An integrated potentiometer in the control circuitry monitors the current angle of the servo: if the axis is at a right angle, then the motor is off. The circuit checks that if the angle is not correct, the servo will correct the direction until the angle is right. Normally, the axis of the servo is able to reach around 180 degrees, but in some servos it reaches 210 degrees (you can even find motors of 360°, these servos are ideal for installations where you need a wide angle rotation), but this range varies by application and manufacturer. The pulse duration indicates the rotation angle of the motor.

Minimum Position


Medium Position


Maximum position


It’s important to emphasize that, to make a servo remain in the same position, it is necessary to continuously send a pulse of constant width. This way, if there’s a force that tries to change this position, the motor will try to resist. If the servo motor stops sending pulses, or the interval between pulses is greater than the maximum allowed, then the servomotor lose strength and stops trying to maintain its position, and any external force will be able to move it.

Servo control. A servomotor traditionally has three wires: power, ground, and signal. The power cable is usually red, and in this configuration is connected to 5V. The ground wire is usually black or brown and must be connected to….ground. The signal cable is usually white, yellow, or orange and needs to be connected to the PWM (Pulse Width Modulation) signal. For generating a PWM waveform a microcontroller is often used, because it has specific hardware to perform this task and facilitates the process of generating the signal. It can do this with just a few lines of code.

In this experiment you will use only use power, ground, and digital out pin 2 of the SpikerShield to generate a PWM wave. Power will come from a USB battery (if you use the Arudino’s own power supply to power the motor, amplification of your muscle activity becomes unstable due to the voltage draws of the servo), and ground will be shared between the USB battery and the Arduino circuit.


Take our (.ino) Gripper Sketch and load it on your Arduino.


  1. We will connect the three cables to the servo, as follows:- Red cable of the gripper to the +5 wire of a modified USB battery.
    – Brown cable of the Gripper to the ground of the USB battery and Arduino.
    – Orange cable of the Gripper to the digital out 2 (pin location 3) on the Arduino.To do this, we have to build a custom USB cable. Read these brief pdf instructions for how to build it, it’s not too hard.
  2. Plug the USB end of the USB cable into a USB battery, and the three pin header end into the servo motor cable. The side of the three header cable with an orange wire plugs into the side of the servo motor cable with the orange cable.Hand_Battery_Shield
  3. Plug the orange jumper wire into digital out 2 (pin three) on the Arduino, and the black jumper wire into ground (second to last pin) on the Arduino.
  4. Lastly we load the code of the Arduino.
  5. Now flex your arm! You should see the robotic gripper move as well. You can push button 2 (closest to the red LEDs) to change between high and low threshold mode, and you can also change the gain (orange knob on the shield) to find a “sweet spot of control”

    Code description: This code makes the Arduino, with help of the SpikerShield, capture EMG signals produced by contracting muscles of the forearm and converts them to PMW pulses to give movement to the servo motor. These pulses change according to the movement of the muscles: the more strength you use to close your hand, the more the Gripper closes. Using the library included in this program you can control servo motors easily without much code.

    Below you can see the code, but if you want to download it, just click here or in the links above.

    The Code

    /* Arduino Code for an EMG SpikerShield to control a TENS device, LED lights, and a gripper */
    #include   //Includes the Gripper Servo Library
    Servo ServoGripper; //Declares the Name of the Servo to be ServoGripper -- this is all if you want to control a gripper hand as well
    #define NUM_LED 6  //sets the maximum numbers of LEDs
    #define MAX_Low 100   //for people with low EMG activity
    #define MAX_High 254//for people with high EMG activity
    #define Threshold 3 // this sets the light to activate TENS
    #define threshold_degrees 10 //Number of steps the Servo will have
    int reading[10];
    int finalReading;
    int StimPin = 3; // TENS Digital 3
    int SwitchPin = 4;   // pushbutton connected to digital pin 4 -  this will momentarily turn on TENS
    int SwitchThreshold = 7; //pushbutton connected to digital pin 7 - this will switch thresholds
    int GripPin = 2; //Digital Out that controls Servo Motor Gripper Hand
    int SwitchState = 0;
    int SwitchThresholdState = 0;
    int MAX = 0;
    byte litLeds = 0;
    byte multiplier = 1;
    byte leds[] = {8, 9, 10, 11, 12, 13};
    int aQ1 = 11;
    int aQ2 = 13;
    int aQ3 = 8;
    const int UpdateTime = 200; // (number of milliseconds between updating servo position -- if too low you will burn motor out)
    unsigned long OldTime = 0;
    int old_degrees = 0;
    int new_degrees = 0;
    void setup(){
      Serial.begin(9600); //begin serial communications
      ServoGripper.attach(GripPin); //Declare the Servo to be Connected to GripPin
      pinMode(StimPin, OUTPUT); // Set TENS output to StimPin
      pinMode(SwitchPin, INPUT);      // sets the digital pin 4 as the switch input
      pinMode(SwitchThreshold, INPUT);      // sets the digital pin 7 as the threshold changer
      for(int i = 0; i = Threshold){
          digitalWrite(StimPin, HIGH); // This turns on the TENS as a function of which LED is lit
      new_degrees = map(finalReading, 0 ,MAX, 165, 0); //Translate the analog reading to degrees for the servo (from 165° to 0°).
    if (millis() - OldTime > UpdateTime){
      if(abs(new_degrees-old_degrees) > threshold_degrees){
        ServoGripper.write(new_degrees); //Move the servo according to the degrees calculated
      OldTime = millis();
      old_degrees = new_degrees;
      //for serial debugging, uncomment the next two lines.

    With this new experience, now you can make your own inventions. Tell us what you are making and maybe we can start a friendship!


Experiment: Controlling a Robotic Gripper.

Source: Experiment: Controlling a Robotic Gripper

Leave a Reply