Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » How to Control Stepper Motor with A4988 Driver & Arduino
Arduino Projects

How to Control Stepper Motor with A4988 Driver & Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:January 24, 202514 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
A4988 Stepper Motor Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview: Control Stepper Motor with A4988 Driver & Arduino

In this tutorial we will Control the NEMA17 Stepper Motor with A4988 Driver Module & Arduino. The A4988 is a micro-stepping driver for controlling bipolar stepper motors which have a built-in translator for easy operation. Thus, we can control the stepper motor with just 2 pins from our controller. The DIR pin will control the rotation direction and the STEP pin will control the steps.

In the previous tutorial we learned Controlling the Stepper Motor with Potentiometer and also with Joystick. The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5 volts and doesn’t require any driver. But the NEMA17 Stepper Motor is requires 8V-35V Power as the torque is too high. Therefore we need Stepper Driver Module like A4988 or DRV8825.


Bill of Materials

The following are the components required for learning this tutorial. All the components can be easily purchased from Amazon. The component purchase link is given as well.

S.N.Components NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2A4988 Stepper Motor Driver1Amazon | AliExpress
3. NEMA17 Stepper Motor1Amazon | AliExpress
4Electrolytic Capacitor 100uF2Amazon | AliExpress
512V DC Adapter1Amazon | AliExpress
65V DC Adapter1Amazon | AliExpress
7Connecting Jumper Wires20Amazon | AliExpress
8Breadboard1Amazon | AliExpress




A4988 Stepper Motor Driver Module

A4988 Stepper Driver Module

The A4988 is a complete Microstepping Motor Driver with a built-in translator for easy operation. The breakout board from Allegro features adjustable current limiting, over-current and over-temperature protection and five different microstep resolutions. It operates from 8 V to 35 V and can deliver up to approximately 1 A per phase without a heat sink or forced airflow. It is rated for 2 A per coil with sufficient additional cooling.

Features

  1. Max. Operating Voltage: 35V
  2. Min. Operating Voltage: 8V
  3. Max. Current Per Phase: 2A
  4. Microstep resolution: Full step, ½ step, ¼ step, 1/8 and 1/16 step
  5. Reverse voltage protection: No
  6. Dimensions: 15.5 × 20.5 mm (0.6″ × 0.8″)
  7. Short-to-ground and shorted-load protection
  8. Low RDS(ON) outputs
  9. Thermal shutdown circuitry

A4988 Motor Driver Pinout

The A4988 driver has total of 16 pins which are as follows:

A4988 Pins

1. Power Supply Pins: The pin include VDD & VMOT & Pair of GND pins. VDD is employed for driving the interior logic circuitry which may be 3V to 5V whereas VMOT supplies power for the motor which may be 8V to 35 V.

2. Microstep Selection Pins: The A4988 driver has three-step resolution selector inputs, i.e., MS1, MS2 & MS3. By setting appropriate logic levels to those pins we will set the motors to at least one of the five-step resolutions.

3. Control Input Pins: STEP & DIR are the 2 control input pins. STEP input controls the micro-steps of the motor whereas DIR input controls the spinning direction of the motor.

4. Power States Control Pin: The A4988 has three different inputs for controlling its power states, i.e EN, RST, and SLP. The EN pin is active low input, when pulled LOW the A4988 driver is enabled. SLP Pin is active low input. Pulling this pin LOW puts the driver in sleep mode, minimizing the facility consumption. The RST is a lively low input which when pulled LOW, all STEP inputs are ignored. It also resets the driver by setting the internal translator to a motor initial stage.

5. Output Pins: There are 4 output pins as 2B, 2A, 1B, 1A. We can connect any bipolar stepper motor having voltages between 8V to 35 V to those pins.



Heat Sink Requirement

It is safe to use the A4988 Driver without a heat sink if the current rating is up to 1A. For achieving more than 1A per coil, a heat sink or other cooling method is required.

A4988 Heat Sink

Because of the excessive power dissipation of the A4988 driver, there is a rise of temperature that can go beyond the capacity of IC, probably damaging it.

Setting Up Current Limit

Before we connect the motor we should adjust the current limiting of the driver so that the current is within the limit of the motor. We can do that by adjusting the reference voltage using the potentiometer on the board and considering this equation below.

1
Current Limit = VRef x 2.5

For example, if the Stepper Motor is rated for 350mA, we need to adjust the reference voltage to 0.14V. Take a small screwdriver and adjust the current limit with a potentiometer until you reach the rated current.

A4988 Current Limit Setting


NEMA17 Stepper Motor

NEMA 17 is a hybrid stepping motor with a 1.8° step angle (200 steps/revolution). Each phase draws 1.2 A at 4 V, allowing for a holding torque of 3.2 kg-cm. NEMA 17 Stepper motor is generally used in Printers, CNC machines and Laser Cutters. Check out Stepper Motor Calculator to calculate various stepper motor parameters.

NEMA17 Stepper Motor

This motor has six wires, connected to two split windings. Black, Yellow, Green wires are part of the first winding while Red, White, and Blue is part of the second winding.


Interfacing NEMA17 Stepper Motor with Arduino using A4988 Driver

Now lets connect the A4988 Stepper Motor driver to Arduino and control NEMA17 Stepper Motor. I used D2 & D3 pins to control the motor direction and step. The schematic for the connection is given below.

A4988 Arduino Nema17 Stepper Motor

The VMOT pin is powered by 12V Power Supply and VDD is powered using a 5V Supply. Remember to put a large 100µF decoupling electrolytic capacitor across motor power supply pins, close to the board.



Basic Stepper Motor Control Code

Now that you have wired up the driver and set the current limit, it is time to connect the Arduino to the computer and upload some code. This sketch controls motor in a single direction.

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
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
 
void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}
void loop()
{
  // Set motor direction clockwise
  digitalWrite(dirPin, HIGH);
 
  // Spin motor slowly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }
  delay(1000); // Wait a second
  
  // Set motor direction counterclockwise
  digitalWrite(dirPin, LOW);
 
  // Spin motor quickly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // Wait a second
}


Controlling Stepper Motor Spinning Direction

Using this code, the stepper motor direction can be controlled. You can rotate the motor in either clockwise direction or in anticlockwise direction. This sketch controls both the speed, the number of revolutions, and the spinning direction of the stepper motor.

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
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
 
void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}
void loop()
{
  // Set motor direction clockwise
  digitalWrite(dirPin, HIGH);
 
  // Spin motor slowly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }
  delay(1000); // Wait a second
  
  // Set motor direction counterclockwise
  digitalWrite(dirPin, LOW);
 
  // Spin motor quickly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // Wait a second
}




Controlling Stepper Motor with AccelStepper Library

Stepper Motor can be controlled using the Arduino AccelStepper library. It provides an object-oriented interface for 2, 3, or 4 pin stepper motors and motor drivers.

AccelStepper significantly improves on the standard Arduino Stepper library in several ways like it supports acceleration and deceleration. It also supports multiple simultaneous steppers, with independent concurrent stepping on each stepper. Even very slow speeds are also supported

The following code shows all the above-mentioned features.

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
45
46
47
48
49
50
51
52
53
#include <AccelStepper.h>
 
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
 
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
 
void setup() {
  // Set the maximum speed in steps per second:
  stepper.setMaxSpeed(1000);
}
 
void loop()
{
  // Set the current position to 0:
  stepper.setCurrentPosition(0);
 
  // Run the motor forward at 200 steps/second until the motor reaches 400 steps (2 revolutions):
  while(stepper.currentPosition() != 400)
  {
    stepper.setSpeed(200);
    stepper.runSpeed();
  }
 
  delay(1000);
 
  // Reset the position to 0:
  stepper.setCurrentPosition(0);
 
  // Run the motor backwards at 600 steps/second until the motor reaches -200 steps (1 revolution):
  while(stepper.currentPosition() != -200)
  {
    stepper.setSpeed(-600);
    stepper.runSpeed();
  }
 
  delay(1000);
 
  // Reset the position to 0:
  stepper.setCurrentPosition(0);
 
  // Run the motor forward at 400 steps/second until the motor reaches 600 steps (3 revolutions):
  while(stepper.currentPosition() != 600)
  {
    stepper.setSpeed(400);
    stepper.runSpeed();
  }
 
  delay(3000);
}


Stepper Motor Acceleration & deceleration Code

The following sketch will add acceleration and deceleration to the movements of the stepper motor. The motor will run back and forth with a speed of 200 steps per second and an acceleration of 30 steps per second.

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
#include <AccelStepper.h>
 
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
 
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
 
void setup()
{
  // Set the maximum speed and acceleration:
  stepper.setMaxSpeed(200);
  stepper.setAcceleration(30);
}
 
void loop() {
  // Set the target position:
  stepper.moveTo(600);
  // Run to target position with set speed and acceleration/deceleration:
  stepper.runToPosition();
 
  delay(1000);
 
  // Move back to zero:
  stepper.moveTo(0);
  stepper.runToPosition();
 
  delay(1000);
}


Control NEMA17 Stepper Motor with A4988 & Potentiometer

The stepper motor can be controlled using Potentiometer as well. I used a 10K Potentiometer and connected it to the A0, analog pin of the Arduino Nano board. The voltage fed to the Analog pin of Arduino can be used as a reference voltage to control the speed of the Stepper Motor. The connection diagram is given below.

Stepper Motor A4988 Potentiometer Arduino

Copy the code from below and upload it to the Arduino Nano Board.



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
/ Defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
int customDelay,customDelayMapped; // Defines variables
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
  
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}


Video Tutorial & Guide

A4988 Tutorial | Control NEMA17 Stepper Motor with A4988 Stepper Motor Driver Module & Arduino
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleHow to use FreeRTOS for STM32F103C8 in Arduino IDE
Next Article Interfacing LoRa SX1278 with STM32 – Sender & Receiver

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 14 Comments

14 Comments

  1. Markus Optfakeng on January 3, 2021 3:26 AM

    Why not using the Arduino 5V output to power the A4988 driver, instead of using another external 5V power source? Thank you!

    Reply
  2. Dimitri Maniatopoulos on January 19, 2021 2:04 AM

    Arduino can provide only about 20ma per output in, and thiw is not enough to move the more than 50 times higher current for the motor. That is the reason of using the ‘driver circuit’. Small current from Arduino becomes ‘big’ current for the motor.

    Reply
    • Andratos on July 7, 2021 10:13 PM

      Hello, I was wondering if it would be possible to power both the arduino and stepper motor (via the A4988) with a single power supply, instead of 2 (one 5V and one 12V…). I am planning to use this for a project which requires a tiny space and it would be preferable for me to be able to only have 1 wire going in to power the circuit rather than 2. Thank you!

      Reply
      • Dimitri Maniatopoulos on July 9, 2021 3:01 AM

        Yes. You could. BUT :5v is very low and you will need more current. If you can use a 12v power suply and add a 5v regulator (7805 ?) for the arduino part, it could help you overcomming this. A small heatsink on regulator will do as arduino itself will need a few ma.

  3. Whyvon on January 30, 2021 11:37 AM

    Can you clarify what capacitor should be used for the 5v power supply? Bill of Materials implies 100 uF, schematic says 10 uF, video says 47 uF or more. Also, can I use a ceramic capacitor? My (limited) understanding is that for this application, ceramic is fine, and anywhere from 10 to 100 uF will probably be fine… but I’d like to have confirmation and also know what is ‘ideal’.

    Reply
    • Mr. Alam on January 30, 2021 11:38 AM

      You can use any capacitor from 10uF to 100uF

      Reply
  4. manti on May 8, 2021 8:18 PM

    So every NEMa17 I come across has a operational voltage of around 3V. still the only thing I can find is people driving it with 12V and a A4988.

    wont that damage the motor?

    Reply
  5. Dimitri Maniatopoulos on May 9, 2021 10:46 AM

    What will damage the motor is current (Amperes). And what is keeping current in balance is A4988. So 3v is just the lowest possible voltage to achieve the current needed to move motor. A4988 works like a current limiter so we always drive motor with the correct current even when voltage is more than 3v. More voltage helps in using thinner wires in circuit and so keep it cooler.

    Reply
  6. Andratos on July 7, 2021 10:14 PM

    Hello, I was wondering if it would be possible to power both the arduino and stepper motor (via the A4988) with a single power supply, instead of 2 (one 5V and one 12V…). I am planning to use this for a project which requires a tiny space and it would be preferable for me to be able to only have 1 wire going in to power the circuit rather than 2. Thank you!

    Reply
  7. Travis Johnson on May 26, 2022 12:13 AM

    I’ll start off with, I am a beginner, so please forgive me if I am incorrect, but it appears that the trace routing from the 5V and 12V plugs are routed incorrectly. The A4988 VMOT is connected to the 5V and the VDD is connected to the 12V.

    Reply
  8. Mike Bruski on July 6, 2022 6:16 PM

    The Arduino Nano will accept 12v on the Vin pin and produce 5v on the 5v pin via the onboard regulator. The 5v regulator is capable of about 800mA. It can power up to 3 A4988 drivers, a bluetooth driver (HC-05) and one or two low power I2C devices as well as the MCU. On the Nano board, this 5v output is isolated from the 5v on the USB by means of a diode. I haven’t played with a Nano 33 yet so I’m not sure if this information applies to these newer Arduino devices which are otherwise not 5v logic tolerant. I believe the schematics for these board are available on the Arduino web page as they are open source.

    Reply
  9. Nick Simmons on November 2, 2022 12:01 PM

    I’m sorry to be ignorant on this but how do i set the ‘reference voltage’ on the driver? What do i connect to what? I can check the voltage of a battery but that generally has volage within.

    Reply
  10. shahd on July 12, 2025 8:43 PM

    what the reason of losing steps

    Reply
  11. JOE on July 13, 2025 10:54 AM

    ESTA MAL EL DIAGRAMA NO SE POR QUE PUBLICAR ERRORES QUE PUEDEN QUEMAR LOS COMPONENTE PESIMO EL SITIO NI SIQUIERA CORRIGEN EL DIAGRAMA ,NUNCA MAS CON UDS.ESTUDIEN Y DESPUES ENSEÑEN

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • DIY Turbidity Meter using Turbidity Sensor & Arduino
    DIY Turbidity Meter using Turbidity Sensor & Arduino
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module with Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.