Learn how to use the A4988 Stepper Motor Driver with an Arduino UNO or a NodeMCU. In this post I will cover the basics for the A4988 Stepper Motor Driver, what each of its pins does, what is micro-stepping and how to define the micro-stepping mode, wiring to the Arduino UNO, wiring to a NodeMCU (ESP8266), as well as examples to tie it all together!
What is the A4988 Stepper Motor Driver?
The A4988 Stepper Motor Driver is used to control bipolar stepper motors, including microstepping (I’ll go over that later). So basically, think of the A4988 as a motor driver. We will use it to send commands from an Arduino or NodeMCU to control how the stepper motor moves. Now, to be clear, this diver is meant to be used to drive stepper motors only.

What is a Stepper Motor?
A stepper motor is a type of DC motor that divides it’s motion into individual steps of equal angular rotation. It’s common for a stepper motor to have 200 steps per rotation, so if such motor takes 200 steps, it would have done one full rotation. If it takes 100 steps, it does half a rotation. 50 steps? one quarter of a rotation (or 90 degrees), and so on. This is great because we can easily tell the motor to go to a specific angular rotation position and hold this position without having to use any sensors. Given the ability of stepper motors to accurately move to specific positions, they are used for applications such as 3D Printers, CNC machines, robotics, and others.

Now, I mentioned that stepper motors have a pre-defined number of steps per revolution (i.e. 200 steps per revolution). So for a 200 step-per-revolution motor, it can go to 200 pre-defined positions, but what happens if we want to move with more steps per revolution? In that case we can use microstepping, just note that microstepping doesn’t normally increase accuracy, it mainly the smoothness of the motion by having an more steps as it rotates, which can help reduce noise, vibration, and makes the overall motion more gentle.
What is stepper motor microstepping?
Microstepping allows driving a stepper motor with increments smaller than the pre-defined steps for the motor. Normally, without microstepping the motor will move a full steps. Microstepping allows energizing the motor in a way that the motor no longer is required to move only at the pre-defined steps with no stops in between.
Microstepping setting with the A4988 Stepper Motor Driver
The A4988 stepper motor driver allows for a range of microstepping setting ranging from full steps (no microstepping) all the way to sixteenth steps (increasing the total number of steps per revolution by a factor of 16X). In between those extremes we have half steps, quarter steps, and eighth steps. So net, the A4988 offers 5 different settings for microstepping.
A4988 Pinout & Settings/Controls
A4988 Pins
ENABLE – Pin to enable the A4988 driver. It is enabled by default. To disable, a logic 1 (High) needs to be connected.
MS1, MS2, MS3 – Microstepping selection pins. Different combination of inputs define the specific setting (see further below for details).
RESET – When activated, it ignores all inputs sent to the “STEP” pin until deactivated. RESET is activated when is pulled down. This pin is floating, so one way to keep it high is by keeping it connected to the SLEEP pin.
SLEEP – Can be used to minimize power consumption when the motor is not in use.
STEP – This is where you tell the A4899 to move the stepper motor by one step (defined by the microstepping setting). One signal on HIGH equals one step. Speed is defined by how fast / how frequently we switch the HIGH/LOW signal.
DIR – This is where you define the direction of rotation (clockwise or counter-clockwise).
VMOT – This is were you connect the voltage supply for the motor being driven. The A4988 allows an input from 8V – 35V, but the actual needed will be based on the voltage you choose to use. The motor I use in this example is a 12V motor, so I will connect 12V.
1A, 1B, 2A, 2B – These are the output pins that get connected to the bipolar stepper motor being controlled. One loop of the stepper motor goes through 1A and 1B, and the other through 2A and 2B. Make sure to look at your motor’s datasheet to confirm which sets of cables are on the same loop. See diagrams further below for connection details.
VDD – This pin is used to power the internal circuit of the A4988. Acceptable voltages can range from 3 – 5.5V.
GND – GND pins must be connected to a common ground.
A4988 Current Limit Control
The A4988 comes with a potentiometer (labeled on the image above as “Current Limit Control”) that can be use to prevent the current flowing through the stepper motor from exceeding the motor’s rated current. Make sure to checks the amps/phase of the motor you are trying to use. This specifies the current that each winding (or phase) can support without damaging the motor. A simple process to adjust the potentiometer is the following:
Adjusting the A4988 potentiometer to limit the motor current
- Confirm the rated current for your motor (mine is 0.4Amps).
- Divide this number by 2.5ohms.
- The truth is that the actual number to divide by can vary, but 2.5 is a good number.
- The actual number will depend on the value of an internal resistance within the module (varies by manufacturer and based on tolerance of the actual resistor used).
- The resulting number (in my case 0.4A / 2.5Ω = 0.16V) is the reference voltage (VREF).
- Set the microstepping mode to “Full Step”.
- Hold the motor steady by not sending stepping signals and having the A4988 enabled.
- Measure the reference voltage between the potentiometer screw and ground (see image).
- Adjust the potentiometer until the measured reference voltage equals the calculated value of VREF.
- Note that this setting is dependent on the VDD voltage. So if you change it, you need to recalibrate.

A4988 Microstepping Settings
MS1 | MS2 | MS3 | Microstep Resolution |
Low | Low | Low | Full Step |
High | Low | Low | Half Step |
Low | High | Low | Quarter Step |
High | High | Low | Eighth Step |
High | High | High | Sixteenth Step |

Connecting the A4988 to an Arduino or NodeMCU (ESP8266)
Now that we have enough background on what the A4988 can do and its pins, let’s see how we can get them connected to an Arduino UNO or a NodeMCU. In this post I’ll be showing how to do both with Arduino codes examples for both) and will be using a 12V NEMA 14 stepper motor.
Downloading the required Arduino Libraries for A4988
To control the A4988 Stepper Motor Driver with code from Arduino IDE, you will need to install the “Stepper” library. To do so, please go to the Arduino IDE top menu, click on “Sketch”, then go to “Include Library”, the click on “Manage Libraries…”. A pop-up window will show up. On the search bar, type “StepperDriver” by Laurentie Badea (see screenshot below to ensure you pick the correct one). Select and then install.
A4988 Examples with Arduino UNO and NodeMCU
I will now proceed to show some examples on how to use the A4988 with example codes specific to both Arduino UNO and NodeMCU (ESP8266). The code will be consistent with the wiring diagrams showed on the images previously shown above.
A4988 Examples – NodeMCU (ESP8266)
Continuous rotation at constant speed
This example will allow the motor to rotate in one direction at a specified constant rate (which I will set a 100 revolutions per minute). Microstepping setting will be set to full steps. Steps per revolution will be defined as 200 since that is the case for my NEMA 14 motor. Below is the Arduino code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 14; //GPIO14---D5 of Nodemcu--Step of stepper motor driver int Dire = 2; //GPIO2---D4 of Nodemcu--Direction of stepper motor driver int Sleep = 12; //GPIO12---D6 of Nodemcu-Control Sleep Mode on A4988 int MS1 = 13; //GPIO13---D7 of Nodemcu--MS1 for A4988 int MS2 = 16; //GPIO16---D0 of Nodemcu--MS2 for A4988 int MS3 = 15; //GPIO15---D8 of Nodemcu--MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 100; //Motor Speed in revolutions per minute int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Stepper Motor Clock Example – Microstepping at Full Steps
In this example the stepper motor will move to match the seconds hands of a clock (meaning one full rotation per second, equivalent to rotating at a rate of 1 revolution per minute). The microstepping setting will be set to full steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 14; //GPIO14---D5 of Nodemcu--Step of stepper motor driver int Dire = 2; //GPIO2---D4 of Nodemcu--Direction of stepper motor driver int Sleep = 12; //GPIO12---D6 of Nodemcu-Control Sleep Mode on A4988 int MS1 = 13; //GPIO13---D7 of Nodemcu--MS1 for A4988 int MS2 = 16; //GPIO16---D0 of Nodemcu--MS2 for A4988 int MS3 = 15; //GPIO15---D8 of Nodemcu--MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 1; //Motor Speed in revolutions per minute - Here we set the RPM to 1 rpm to match the speed of second hand from a clock int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Stepper Motor Clock Example – Microstepping at Sixteenth Steps
In this example the stepper motor will move to match the seconds hands of a clock (meaning one full rotation per second, equivalent to rotating at a rate of 1 revolution per minute). The microstepping setting will be set to sixteenth steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 14; //GPIO14---D5 of Nodemcu--Step of stepper motor driver int Dire = 2; //GPIO2---D4 of Nodemcu--Direction of stepper motor driver int Sleep = 12; //GPIO12---D6 of Nodemcu-Control Sleep Mode on A4988 int MS1 = 13; //GPIO13---D7 of Nodemcu--MS1 for A4988 int MS2 = 16; //GPIO16---D0 of Nodemcu--MS2 for A4988 int MS3 = 15; //GPIO15---D8 of Nodemcu--MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 1; //Motor Speed in revolutions per minute - Here we set the RPM to 1 rpm to match the speed of second hand from a clock int Microsteps = 16; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Moving a specific number of steps in multiple directions
In this example the stepper motor will move 400 steps clockwise, then 400 steps counter-clockwise, then 50 steps clockwise, then 100 steps counter-clockwise, and finally 50 steps clockwise. In my motor with 200 steps per revolution, this will be 2 turns in the clockwise direction, 2 turns counter-clockwise, then a quarter turn clock-wise, then turning back to the starting position and turning another 90 degrees in a single sweep, and finally returning to the starting point. See YouTube video for full details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <Arduino.h> #include "A4988.h" int Step = 14; //GPIO14---D5 of Nodemcu--Step of stepper motor driver int Dire = 2; //GPIO2---D4 of Nodemcu--Direction of stepper motor driver int Sleep = 12; //GPIO12---D6 of Nodemcu-Control Sleep Mode on A4988 int MS1 = 13; //GPIO13---D7 of Nodemcu--MS1 for A4988 int MS2 = 16; //GPIO16---D0 of Nodemcu--MS2 for A4988 int MS3 = 15; //GPIO15---D8 of Nodemcu--MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 100; //Motor Speed in revolutions per minute int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep delay(1000);//Wait 1000 milliseconds (1 second) proceeding // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.move(400);//Move 400 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(-400);//Move 400 steps counter-clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(50);//Move 50 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(-100);//Move 100 steps counter-clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(50);//Move 50 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again } |
Examples – Arduino UNO
The following examples are the same as the ones shown above for the NodeMCU (ESP8266), but with minor changes to allow using with the Arduino UNO following the same connection defined in the diagram shown previously.
Continuous rotation at constant speed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 3; //GPIO3 in Arduino UNO --- Step of stepper motor driver int Dire = 2; //GPIO2 in Arduino UNO --- Direction of stepper motor driver int Sleep = 4; //GPIO4 in Arduino UNO --- Control Sleep Mode on A4988 int MS1 = 7; //GPIO7 in Arduino UNO --- MS1 for A4988 int MS2 = 6; //GPIO6 in Arduino UNO --- MS2 for A4988 int MS3 = 5; //GPIO5 in Arduino UNO --- MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 100; //Motor Speed in revolutions per minute int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Stepper Motor Clock Example – Microstepping at Full Steps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 3; //GPIO3 in Arduino UNO --- Step of stepper motor driver int Dire = 2; //GPIO2 in Arduino UNO --- Direction of stepper motor driver int Sleep = 4; //GPIO4 in Arduino UNO --- Control Sleep Mode on A4988 int MS1 = 7; //GPIO7 in Arduino UNO --- MS1 for A4988 int MS2 = 6; //GPIO6 in Arduino UNO --- MS2 for A4988 int MS3 = 5; //GPIO5 in Arduino UNO --- MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 1; //Motor Speed in revolutions per minute - Here we set the RPM to 1 rpm to match the speed of second hand from a clock int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Stepper Motor Clock Example – Microstepping at Sixteenth Steps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <Arduino.h> #include "A4988.h" int Step = 3; //GPIO3 in Arduino UNO --- Step of stepper motor driver int Dire = 2; //GPIO2 in Arduino UNO --- Direction of stepper motor driver int Sleep = 4; //GPIO4 in Arduino UNO --- Control Sleep Mode on A4988 int MS1 = 7; //GPIO7 in Arduino UNO --- MS1 for A4988 int MS2 = 6; //GPIO6 in Arduino UNO --- MS2 for A4988 int MS3 = 5; //GPIO5 in Arduino UNO --- MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 1; //Motor Speed in revolutions per minute - Here we set the RPM to 1 rpm to match the speed of second hand from a clock int Microsteps = 16; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.rotate(360); } |
Moving a specific number of steps in multiple directions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <Arduino.h> #include "A4988.h" int Step = 3; //GPIO3 in Arduino UNO --- Step of stepper motor driver int Dire = 2; //GPIO2 in Arduino UNO --- Direction of stepper motor driver int Sleep = 4; //GPIO4 in Arduino UNO --- Control Sleep Mode on A4988 int MS1 = 7; //GPIO7 in Arduino UNO --- MS1 for A4988 int MS2 = 6; //GPIO6 in Arduino UNO --- MS2 for A4988 int MS3 = 5; //GPIO5 in Arduino UNO --- MS3 for A4988 //Motor Specs const int spr = 200; //Steps per revolution int RPM = 100; //Motor Speed in revolutions per minute int Microsteps = 1; //Stepsize (1 for full steps, 2 for half steps, 4 for quarter steps, etc) //Providing parameters for motor control A4988 stepper(spr, Dire, Step, MS1, MS2, MS3); void setup() { Serial.begin(9600); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dire, OUTPUT); //Direcction pin as output pinMode(Sleep, OUTPUT); //Set Sleep OUTPUT Control button as output digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dire, LOW); digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep delay(1000);//Wait 1000 milliseconds (1 second) proceeding // Set target motor RPM to and microstepping setting stepper.begin(RPM, Microsteps); } void loop() { digitalWrite(Sleep, HIGH); //A logic high allows normal operation of the A4988 by removing from sleep stepper.move(400);//Move 400 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(-400);//Move 400 steps counter-clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(50);//Move 50 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(-100);//Move 100 steps counter-clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again stepper.move(50);//Move 50 steps clockwise delay(1000);//Wait 1000 milliseconds (1 second) before moving again } |
Components used in this example
*As an Amazon & Ebay Associate I earn from qualifying purchases.
Component | Link |
Arduino UNO | https://amzn.to/3uYVAMC https://ebay.us/veZdKX |
NodeMCU | https://ebay.us/q33b4R |
A4988 Stepper Motor Controller | https://ebay.us/D0Adpn |
NEMA 14 – 14HS10-0404S Stepper Motor | https://ebay.us/BnkeMz |
Breadboard (Elenco 9440) | https://amzn.to/3x23dnq https://ebay.us/FcwSdb |