Driving a stepper motor used to be complicated enough when we have to build a driver by ourselves. But since there are many kinds of driver modules out there, driving a stepper motor is not that hard anymore. In this video, we will learn how to use the A4988 stepper driver.
A4988 stepper motor driver specification :
- Max. Operating Voltage: 35V
- Min. Operating Voltage: 8V
- Max. Current Per Phase: 2A
- Microstep resolution: Full step, ½ step, ¼ step, 1/8 and 1/16 step
- Reverse voltage protection: No
- Dimensions: 15.5 × 20.5 mm (0.6″ × 0.8″)
- Short-to-ground and shorted-load protection
- Low RDS(ON) outputs
- Thermal shutdown circuitry
A4988 stepper motor driver pinout
A4988 stepper motor driver with Arduino Tutorial
In this tutorial, we will try to use this stepper motor with an Arduino. So let’s start with the wiring diagram.
You can use 47uF of a capacitor at Vmot and GND pins. In this tutorial I use the NEMA17 stepper motor.
Arduino Code
The first sketch we will try to use is a stepper spin clockwise and counterclockwise with a second delay between them.
// Define pin connections & motor's steps per revolution const int dirPin = 2; const int stepPin = 3; const int stepsPerRevolution = 500; int stepDelay=2000; void setup() { // Declare pins as Outputs pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { //clockwise digitalWrite(dirPin, HIGH); // Spin motor for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(stepDelay); digitalWrite(stepPin, LOW); delayMicroseconds(stepDelay); } delay(1000); // Wait a second //counterclockwise digitalWrite(dirPin, LOW); // Spin motor for(int x = 0; x < stepsPerRevolution; x++) { digitalWrite(stepPin, HIGH); delayMicroseconds(stepDelay); digitalWrite(stepPin, LOW); delayMicroseconds(stepDelay); } delay(1000); // Wait a second }
After that I add a trimmer to the circuit and will use the trimmer as speed adjuster. Here’s the wiring diagram.
// Define pin connections & motor's steps per revolution const int dirPin = 2; const int stepPin = 3; const int stepsPerRevolution = 500; int stepDelay = 700; void setup() { // Declare pins as Outputs pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); Serial.begin(9600); } void loop() { //clockwise digitalWrite(dirPin, HIGH); int pot = analogRead(A0); stepDelay=map(pot, 0, 1023, 10000, 0); Serial.println(stepDelay); // Spin motor digitalWrite(stepPin, HIGH); delayMicroseconds(stepDelay); digitalWrite(stepPin, LOW); delayMicroseconds(stepDelay); }