How to control speed of Stepper motor by potentiometer + arduino + A4988 Tutorial

Hello friends.

In this tutorial we will learn how to run and control speed of Stepper motor using Arduino, A4988 driver IC and Potentiometer.

You can watch the following video or you can continue to read this post for complete tutorial.



A4988 is a Microstepping driver IC to control bipolar stepper motors, A4988 Driver is so easy to use because it needs only two control pin from microcontoller to control steps and direction of stepper motor.  we can configure A4988 IC for full step, half step, quarter step, eight step & sixteen steps,



  1. ENABLE :- Enable pin is used to enable and disable stepper motors, like in some applications if you don’t need to engage motors while in rest position means you don’t need holding torque, so we just disable steppers during this rest position and enable them again when it required, in this why motors will not draw current in holding position and and heating of motor avoids. it is not always compulsory to used this pin. Enable pin is low motors are enable, Enable pin is high motors are disable.
  2. MS1, MS2, MS3 :- This pins are used to configure Microstepping study below table to get idea how to configure required micostepping.
    A4988 Microstepping table
    A4988 Microstepping table


  3. RESET :- Turn off all the FET outputs till when reset pin is high all steps are ignored.
  4. SLEEP :- When set low minimize the power consumption and and A4988 went in sleep mode.
  5. STEP :- Step pin connected with digital pin of microcontroller to run stepper motor as per the numbers of step signals from microcontroller, speed of stepper motor depends upon the the frequency of step signal more the delay in step signal lower the RPM & vice versa. step signal delay is universally prepositional to the speed of stepper motor.
  6. DIR :- Direction pin set high or low to run stepper motor in either direction.
  7. V MOT :-  Power supply for Motors (8-35V DC).
  8. GND :-  System ground.
  9. 1A,1B,2A,2B :- Connection pin for motor connection.
  10. VDD :- Logic power supply (3V – 5.5V).
  11. GND :-  System ground.


Basic wiring drawing to run Stepper motor

Following is the arduino code to run stepper motor one step in forward direction and one step in reverse direction.

Wiring drawing to control speed of Stepper motor with potentiometer

Following is the code to control speed of stepper motor by using 10k ohm potentiometer


Low cost PCB on PCBWay - only $5 for 10 PCBs and FREE first order for new members

PCB Assembly service starts from $88 with Free shipping all around world + Free stencil 

PCBWay 2nd PCB Design Contest




Hobbiest Electrical DIY project passionate

One thought on “How to control speed of Stepper motor by potentiometer + arduino + A4988 Tutorial”

  1. Hi Sandeep

    I don’t know if my earlier message is posted or not.
    I am using TB-6560 driver for my stepper and it is working fine with AccelStepper library.
    I need to control the stepper with a 5K potentiomer so I tried to use code similar to above but the stepper is not moving.

    Here is the portion of the code:

    const int dirPin = 18; // Pin for Direction
    const int stepPin = 19; // Pin for Step
    const int POTpin = A6; // Pin A6 of NANO to be used for 5k POT center pin

    byte homeButtonVal;
    const int FillSteps = 918; // Total steps required to load/fill 1 bottle
    int stepDelay; // Delay between steps to be obtained from POT

    void setup() {

    pinMode(stepPin, OUTPUT);
    pinMode(dirPin, OUTPUT);

    digitalWrite(dirPin, HIGH); // Set direction to Forward
    while (digitalRead(homeButton)) // While Limit Switch is not pressed
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image