Arduino Camera Slider using NEMA Stepper Motors – Part 1

//Arduino Camera Slider using NEMA Stepper Motors – Part 1

Control 2 Stepper Motors simultaneously using an Arduino and the Easy Driver board


In this tutorial we will see how to control 2 stepper motor simultaneously using the Arduino Serial Monitor.

To help us achieve this we will be using the AccelStepper library developed by ‘Mike McCauley‘ which enable us to control up to 10 steppers at the same time if we want.

In this Part 1 we will look at the code that will control the stepper motor and how to use the Serial Monitor to send values to the Arduino to move the steppers.

In the next parts we will modify the code to calculate the speed and acceleration of the steppers automatically and add more modules (LCD, Buttons, etc…) to make our Camera Slider more portable.


Here are the connection needed for this tutorial:

To power the Stepper Motors connected to the Easy Driver boards we are using a 12V 1A power supply.

The GND and 5V (out) of the Power Supply are connected to the breadboard power rails.
GND and 5V (in) of the Easy Driver boards are connected to the breadboard power rails.

Each pair of winding of the Stepper motors are connected to the A-B pins of the Easy Drivers.

The GND of the UNO is connected to the breadboard GND power rail.

Each Easy Driver GND is connected to the breadboard GND power rail.

Pin 2 and 3 of the UNO are connected to the STEP and DIR pins of one Easy Driver.

Pin 5 and 6 of the UNO are connected to the STEP and DIR pins of the other Easy Driver.


As you see the code needed is quite short, since all we are doing is sending the ‘Move To’ values from the Serial Monitor and using those to make the stepper move.

When we first power up the Arduino, the Stepper motors have a position value of ‘zero’.  So if we enter a minus number the stepper will move counter clockwise and a positive number will move clockwise.  To return to the starting point we just have to enter a value of zero.

Since we are controlling 2 stepper motors, we have to separate the values using a comma in the Serial Monitor: X,Z.

In the following tutorials, we will add more functions.

As always, Don’t forget to watch our Tutorial video for more information.

/* Arduino Multiple Stepper Control Using The Serial Monitor
Created by Yvan /

This code is in the public domain...

You can: copy it, use it, modify it, share it or just plain ignore it!


#include "AccelStepper.h" 
// Library created by Mike McCauley at

// AccelStepper Setup
AccelStepper stepperX(1, 2, 3);   // 1 = Easy Driver interface
                                  // UNO Pin 2 connected to STEP pin of Easy Driver
                                  // UNO Pin 3 connected to DIR pin of Easy Driver
AccelStepper stepperZ(1, 5, 6);   // 1 = Easy Driver interface
                                  // UNO Pin 5 connected to STEP pin of Easy Driver
                                  // UNO Pin 6 connected to DIR pin of Easy Driver

// Stepper Travel Variables
long TravelX;  // Used to store the X value entered in the Serial Monitor
long TravelZ;  // Used to store the Z value entered in the Serial Monitor

int move_finished=1;  // Used to check if move is completed

void setup() {
  Serial.begin(9600);  // Start the Serial monitor with speed of 9600 Bauds
// Print out Instructions on the Serial Monitor at Start
  Serial.println("Enter Travel distance seperated by a comma: X,Z ");
  Serial.print("Enter Move Values Now: ");

//  Set Max Speed and Acceleration of each Steppers
  stepperX.setMaxSpeed(500.0);      // Set Max Speed of X axis
  stepperX.setAcceleration(500.0);  // Acceleration of X axis

  stepperZ.setMaxSpeed(250.0);      // Set Max Speed of Y axis slower for rotation
  stepperZ.setAcceleration(250.0);  // Acceleration of Y axis


void loop() {

while (Serial.available()>0)  { // Check if values are available in the Serial Buffer

  move_finished=0;  // Set variable for checking move of the Steppers
  TravelX= Serial.parseInt();  // Put First numeric value from buffer in TravelX variable
  Serial.print(" X Travel , ");
  TravelZ= Serial.parseInt();  // Put Second numeric value from buffer in TravelZ variable
  Serial.println(" Y Travel ");
  stepperX.moveTo(TravelX);  // Set new move position for X Stepper
  stepperZ.moveTo(TravelZ);  // Set new move position for Z Stepper
  delay(1000);  // Wait 1 seconds before moving the Steppers
  Serial.print("Moving Steppers into position...");

// Check if the Steppers have reached desired position
  if ((stepperX.distanceToGo() != 0) || (stepperZ.distanceToGo() !=0)) {;  // Move Stepper X into position;  // Move Stepper Z into position

// If move is completed display message on Serial Monitor
  if ((move_finished == 0) && (stepperX.distanceToGo() == 0) && (stepperZ.distanceToGo() == 0)) {
    Serial.println("Enter Next Move Values (0,0 for reset): ");  // Get ready for new Serial monitor values
    move_finished=1;  // Reset move variable

Copy the above Sketch code in your Arduino IDE software to program your Arduino.

Used Libraries:

Download The AccelStepper Library

created by ‘Mike McCauley’ :

Once downloaded, just extract the content of the zip files inside your “arduino/libraries” folder, and make sure to restart the Arduino IDE (Close and Reopen) software so it detect this newly installed library.

By | 2018-02-23T16:58:31-05:00 October 30th, 2016|Tutorials|


  1. Ben May 4, 2019 at 10:59 am - Reply

    Looking forward to part 2.
    Is there a date when I can await it ?

  2. Matthew February 13, 2019 at 4:33 pm - Reply

    thanks for your help
    can you help with a prodject

  3. Matthew February 12, 2019 at 10:59 pm - Reply

    thanks for the the tutorial
    it was helpfull learning more
    could you help with a circuit that i’am trying to make

  4. anti January 31, 2019 at 7:13 am - Reply

    Hi, thanks for the tutorial.
    Are you still planning making part 2?
    It would be very usefull for my project, thanks.

  5. Chia Keat January 12, 2019 at 8:23 am - Reply

    Hi, I’m using TB6600 driver to drive the steppers motor.
    Can u advise where should the ENA+ port connected to and does it need to be defined in the Arduino code.

    Thanks for your help.

  6. Rishi Singh October 27, 2018 at 3:25 am - Reply

    What if I want to add a third stepper? The circuit, the code, pls help.

Leave A Comment