A4988 Stepper Motor Driver – How to use

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

MS1MS2MS3Microstep Resolution
LowLowLowFull Step
HighLowLowHalf Step
LowHighLowQuarter Step
HighHighLowEighth Step
HighHighHighSixteenth 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.

A4988 with Arduino UNO
A4988 with NodeMCU

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.

Manage libraries in Arduino IDE
A4988 Arduino Library

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:

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.

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.

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.

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

Stepper Motor Clock Example – Microstepping at Full Steps

Stepper Motor Clock Example – Microstepping at Sixteenth Steps

Moving a specific number of steps in multiple directions

Components used in this example

*As an Amazon & Ebay Associate I earn from qualifying purchases.

ComponentLink
Arduino UNOhttps://amzn.to/3uYVAMC
https://ebay.us/veZdKX
NodeMCUhttps://ebay.us/q33b4R
A4988 Stepper Motor Controllerhttps://ebay.us/D0Adpn
NEMA 14 – 14HS10-0404S Stepper Motorhttps://ebay.us/BnkeMz
Breadboard (Elenco 9440)https://amzn.to/3x23dnq
https://ebay.us/FcwSdb

Leave a Reply

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