Summary of Allegro A4988 and Arduino (3)
This tutorial details building an Arduino-based controller to adjust the speed and direction of a NEMA17 stepper motor using an A4988 driver. The system utilizes an LCD Keypad shield for user interaction, allowing speed adjustments from 0 to 70 RPM via UP/DOWN buttons and direction changes via LEFT/RIGHT buttons. Continuous rotation is achieved by sending step commands at a constant frequency determined by Timer1 interrupts to ensure accurate timing.
Parts used in the Stepper Motor Controller:
- Arduino Uno
- LCD Keypad shield
- Pololu A4988 driver
- NEMA17 stepper motor
- Breadboard
In the last part of my tutorial about the A4988 driver, I’m going to explain how to build a controller to adjust speed and rotation direction of a stepper motor.
Schematics
I used the same setup introduced in a previous post:
- an Arduino Uno;
- a LCD Keypad shield;
- a Pololu A4988 driver mounted on a breadboard;
- a NEMA17 stepper motor.
GUI
Using the controller, you can adjust the speed (from 0 to 70 RPM, revolutions per minute) and the rotation direction.
On the LCD are displayed the actual speed, direction and a progress bar:
The 5 available buttons are used to control the motor:
- UP and DOWN adjust the speed;
- LEFT and RIGHT adjust the direction;
- SELECT activates the emergency stop (speed = 0).
Continuous rotation
To achieve a continuous rotation, your sketch must send the step commands to the Pololu driver at constant frequency.
Let’s see an example: for a speed of 60RPM and for a motor with 200 steps / revolution, Arduino must send to the driver (60*200)/60 = 200 commands / sec or a command every 5ms.
To ensure an accurate timing, I’m going to use the interrupts generated by the Timer1 as explained in this article.
From the Playground you can download a convenient library to configure that Timer:
For more detail: Allegro A4988 and Arduino (3)
- What components are required for this project?
An Arduino Uno, LCD Keypad shield, Pololu A4988 driver on a breadboard, and a NEMA17 stepper motor. - How can you adjust the motor speed?
The UP and DOWN buttons on the LCD Keypad shield adjust the speed between 0 and 70 RPM. - How do you change the rotation direction?
The LEFT and RIGHT buttons on the interface are used to adjust the rotation direction. - Does the SELECT button activate an emergency stop?
Yes, pressing SELECT activates the emergency stop which sets the speed to 0. - What calculation determines the command frequency for 60 RPM?
For 60 RPM with 200 steps per revolution, the Arduino must send 200 commands per second or one every 5ms. - How does the sketch ensure accurate timing for continuous rotation?
It uses interrupts generated by Timer1 to send step commands at a constant frequency.

