Arduino A4988 Stepper Motor Driver: Basic Setup and Control
Arduino A4988 Stepper Motor Driver: Basic Setup and Control
This guide covers the fundamentals of using the A4988 Stepper Motor Driver Module with Arduino, including IC operation, wiring, current limiting adjustment, and writing control code.
Understanding the A4988 IC
The A4988 is a DMOS Microstepping Driver with Translator manufactured by Allegro MicroSystem. Key features include:
- Compatible with both 3.3V and 5V logic signals
- Built-in protection circuits: Thermal Shutdown, Short-to-Ground, and Short-Load protection
- Supports 5 step modes: Full Step, Half Step, 1/4, 1/8, and 1/16
- Maximum motor drive current: 2A
- Maximum voltage: 35V (module limited by capacitors)
Since the IC comes in a tiny 5×5 mm QFN 28 Contact package, practical use requires the A4988 Stepper Motor Driver Module, which provides proper circuit layout and accessible pin headers.
Power Supply Connections for A4988
The A4988 module requires two separate power supplies:
Supply 1 - Logic Power (Low Voltage)
- Connect to VDD and GND (bottom-right corner of module)
- Uses 3-5V to power the internal IC circuitry
- Can be connected directly from Arduino’s 5V and GND pins
Supply 2 - Motor Power (High Voltage)
- Connect to VMOT and GND (top-right corner of module)
- Use voltage matching your motor specification (e.g., 12V for 12V motors)
- Important The power supply must provide sufficient current; 12V 5A or higher is recommended
Caution Although the IC specification lists 37V, the capacitors on the module are rated for only 35V. Exceeding this voltage will damage the module.
Main Control Pins of A4988
STEP and DIR
These two pins are essential and must never be left floating.
- STEP - Receives pulse signals from Arduino. Each HIGH pulse moves the motor one step according to the configured Step Mode. Faster pulses mean faster motor rotation.
- DIR - Controls rotation direction. HIGH = clockwise, LOW = counter-clockwise
ENABLE, RESET, SLEEP
All three pins are Active LOW, meaning they activate when receiving a LOW signal.
- ENABLE - Enables/disables the A4988 IC. LOW enables motor drive output.
- RESET - Resets the IC operation. When LOW, all operations pause until HIGH is applied.
- SLEEP - Enters low-power Sleep mode when not driving the motor.
Pro tip Connect SLEEP to RESET to keep RESET HIGH at all times, ensuring continuous operation.
Motor Output Pins
The output has 2 pairs for connecting to the two windings of a stepper motor:
- 1A, 1B - Controls winding 1
- 2A, 2B - Controls winding 2
Current Limiting Adjustment
Critical Always adjust the current limit to match your motor before operation, or the motor may be damaged.
Adjustment Procedure
-
Check motor Rated Current - Refer to the motor datasheet. NEMA17 motors vary: some are 1A, others 1.2A or 1.5A.
-
Calculate Vref - Using the formula:
Current Limit = Vref × 2.5
For example: 1.2A desired → Vref = 1.2 / 2.5 = 0.48V
-
Set Full Step Mode - Connect M1, M2, M3 to GND.
-
Measure and adjust Vref - Touch multimeter probes to the trimmer potentiometer and GND. Slowly rotate until the reading matches the calculated value.
Alternative method Measure current by inserting an ammeter between the module and motor, then adjust until reaching the rated current.
[image: Photo showing potentiometer location on A4988 module with arrow pointing to Vref measurement point]
Wiring: Arduino + A4988 + Stepper Motor
Parts List
- Arduino UNO R3
- A4988 Stepper Motor Driver Module + Heatsink
- NEMA17 Stepper Motor (12V, e.g., 17HS3401)
- Power Adapter 12V 5A
- Breadboard MB-102 830 Point
- Jumper wires (M-M, M-F)
Wiring Table
| Arduino | → | A4988 |
|---|---|---|
| 5V | → | VDD |
| GND | → | GND |
| Pin 2 | → | DIR |
| Pin 3 | → | STEP |
| A4988 | → | Motor |
|---|---|---|
| B1 | → | B+ (Red wire) |
| A1 | → | A- (Green wire) |
| A2 | → | B- (Blue wire) |
| B2 | → | A+ (Black wire) |
| Adapter 12V | → | A4988 |
|---|---|---|
| Positive | → | VMOT |
| Negative | → | GND |
Jumper SLEEP → RESET
[image: Complete circuit diagram showing Arduino UNO connected to A4988 on breadboard with 12V power supply and stepper motor]
Don’t forget Always attach the heatsink to the A4988 IC. High-current operation generates significant heat, and overheating can trigger protection circuits or damage the IC.
Arduino Code for A4988 Control
Method 1 - Manual Control Without Library
// Define control pins
const int dirPin = 2; // DIR pin
const int stepPin = 3; // STEP pin
void setup() {
// Set both pins as OUTPUT
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
}
void loop() {
// Rotate clockwise 200 steps (1 revolution in Full Step)
digitalWrite(dirPin, HIGH);
for (int x = 0; x < 200; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000); // Adjust speed here
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Pause 1 second
// Rotate counter-clockwise 200 steps
digitalWrite(dirPin, LOW);
for (int x = 0; x < 200; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Pause 1 second
}
Method 2 - Using AccelStepper Library
#include <AccelStepper.h>
// Define pins (DIR, STEP)
AccelStepper stepper(1, 3, 2);
void setup() {
// Configure speed and acceleration
stepper.setMaxSpeed(1000); // Max speed (steps/second)
stepper.setAcceleration(500); // Acceleration (steps/second²)
// Set starting position
stepper.setCurrentPosition(0);
}
void loop() {
// Move to position 800
stepper.moveTo(800);
// Run motor to target position
while (stepper.distanceToGo() != 0) {
stepper.run();
}
delay(1000);
// Return to position 0
stepper.moveTo(0);
while (stepper.distanceToGo() != 0) {
stepper.run();
}
delay(1000);
}
Note To use AccelStepper library, install it via Arduino IDE: Sketch → Include Library → Manage Libraries, then search for “AccelStepper”
Reference Video
Summary
Using A4988 with Arduino is straightforward. Key precautions:
- Adjust current limit for your motor - Calculate Vref = Current / 2.5
- Jumper SLEEP to RESET - For continuous operation
- Install the heatsink - Prevent overheating
- Use adequate power supply - 12V 5A or higher recommended
Once wired and code uploaded, the motor will rotate clockwise one revolution, pause 1 second, then rotate counter-clockwise one revolution, repeating continuously.
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย