Experiment: Controlling a Stepper Motor with Your Muscles
Backyard Brains Logo

Neuroscience for Everyone!

+1 (855) GET-SPIKES (855-438-7745)

items ()

Experiment: Controlling a Stepper Motor with Your Muscles

What biology beyond flagella has never achieved: Rotary Motion with Axles. Here you will learn to make an interface with a Stepper Motor and enjoy making precise circular movements.

Time 3 horas
Difficulty Intermedio

What will you learn?

In this experiment, we will drive a stepper motor using EMG signals from the EMG SpikerShield. With this stepper motor, you can design your own inventions that make things move.


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

Where can we find a stepper motor? Instead of buying one, you can also get a stepper motor by opening up an old printer. These motors are generally used in devices controlled by digital systems, like robotics, automation, and, of course, our favorite, 3D printers!

What are advantages of Stepper motors?() The axis of a stepper motor rotates at regular intervals instead of doing it continuously like DC (direct current) motors. A Stepper Motor is programmed by a micro controller and can be used for precise positioning within a wide range of applications. Precise positioning of a DC motor is not possible by simple methods.

How does a stepper motor work? The stepper motor is known for its ability to convert a train of input pulses (typically square wave pulses) applied to its coils, into a precisely defined increment of movement in the shaft's position. Each pulse moves the shaft through a fixed angle. This is called a step, hence the name stepper motor. The result of this movement is fixed and repeatable, allowing accurate and reliable positioning.

Why are there so many cables in a Stepper Motor? Unipolar Stepper motors can have 5, 6 or 8 terminals that connect to magnetic coils that allow precise positioning, in addition to other cables such as power and ground.

Circuit of Stepper Motor

How is a Stepper Motor different from a DC Motor?

A DC (direct current) motor moves continuously, without steps. It´s used when its important to continually regulate the velocity of a motor. These are the common motors you find in radiocontrol cars and other toys.

A DC motor has two terminals, (+) and (-). Electric current is generated through this terminals making the motor spin in a determinate direction.

How is a Stepper Motor different from a Servo Motor?

A Stepper Motor consists of electromagnetic coils that can move a axle in "steps." The more coils, the smaller the "steps" and the finer control. A servo motor consists of a DC motor than is controlled by circuitry and a geared transmission (transmission gears not shown below.) The chips are monitoring the position of the axis and maintaining its position via feedback control.

Important.In this experiment we will use only digital out pins 2 through 5 for the Motor, VCC, and GND.


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



  1. First, Connect pin 9 (GND) and pin 10 (VCC) to the breadboard. Then, join the following pins as shown in the image below: 1-2, 3-4, 5-6, 7-8, 11-12, 13-14, 15-16, and 17-18.
  2. Now we will connect the stepper motor to the integrated circuit (controller) just like the next image shows. Note that this stepper has two cables for +5 V (for the two coils). Most stepper motors just integrate this into one cable.
  3. We now connect the Integrated Circuit (Controller) to the SpikerShield and also the GND pin on the SpikerShield to the breadboard.

    Note:It's important to feed the Stepper Motor with its own voltage (5V, though we use 6V here and it's fine), without using the voltage of the Arduino; the microcontroller is not capable of providing enough current for the motor to work.

  4. To finish up we load the program to the Arduino; now we can finally test it!
  5. Circuit diagram

    Code description:This code will convert the EMG signal that comes from your muscle to a number of pulses that will be sent to the motor. For each pulse input the motor will spin a determined angle; if there is more muscle activity, the Arduino will send more pulses to the motor. This means the more you flex, the more the motor will turn! Below you can see the code, but if you want to download it, just click here or see the download links above.

    The Code

    #include  //Library for converting a stepper motor.
    #define PASOS 48  //Number of steps that the motor has.
    Stepper motor(PASOS, 2, 3, 4, 5);  // Specifies the number of steps and the pins.
    #define MAX 20    // Maximum range as possible. You can change this number!
    #define PASOSMAX 10 // The motor will go max through 19 steps. (You can also modify this).
    int lecturas[10];  
    int lecturaFinal;
    byte multiplicador = 1;
    byte pasosAvanza = 0;
    int  cuentaPasos = 0;
    void setup(){
      motor.setSpeed(200);  // We specify RPM (velocity of the motor)
    }//Fin de void setup.
    void loop(){
      for(int i = 0; i < 10; i++){    //It takes 10 readings in ~ 0,02 seconds
        readings[i] = analogRead(A0) * multiplicador;
      for(int i = 0; i < 10; i++){   //10 readings average.
        lecturaFinal += lecturas[i];
      lecturaFinal /= 10;
      lecturaFinal = constrain(lecturaFinal, 0, MAX); //Restricts "lecturaFinal" into a defined range(0->MAX).
      pasosAvanza = map(lecturaFinal, 0, MAX, 0, PASOSMAX); //It converts the value of "lectura final" to the number of steps the motor will go through. 
          if(pasosAvanza == 0) //If there is no reading, there is no motor movement
                for(cuentaPasos = 0 ; cuentaPasos <= pasosAvanza ; cuentaPasos++)  
          motor.step(1);  // Advance a Step
    }//End of void loop.

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

    Science Fair Project Ideas

    • Try to design some reaction time experiments that could be done with your own body and with the motor. How does the time differ with other kinds of reaction time tests? Does it depend on the sensory stimulus you're reacting to?
    • Hook up people of differing levels of athleticism-does this affect the strength or speed of th emotor? How about how long they can move the motor for?
    • What are some other devices you could connect this to? What might be the limit to what or how many you could connect to?