Making a stepper motor move is easy with an A4988 driver. They’re super straightforward and very versatile, making them very popular for 3D printers and other DIY CNC machines.
What’s a stepper motor
Stepper motors are great, affordable way to move something a precise distance. Stepper motors have pairs of wires that power sets of magnetic coils inside the motor. By changing the electric charge on the coils the output shaft of the motor can be made to move tiny increments in either direction. They are designed to move a certain number of steps per turn, often described as degrees-per-step. A 200 step-per-turn would be (360/200=) 1.9 degrees per step. There are several popular sizes for stepper motors, notably the NEMA sizes 17 and 23 used in 3D printers.
Stepper motors can come in different power ratings, steps-per-turn, and number of wires, so check your requirements carefully.
Marginally Clever carries NEMA-17 stepper motors that run with 4 wires at 12 volts and 0.3 amp peak. Perfect for robots like the Makelangelo. Once you’ve mastered these low power parts you’ll be ready to move up to bigger and more dangerous projects.
What’s the A4988?
The A4988 is a dual H bridge with added safety features. An H Bridge is a circuit that can send power to a motor forward, backward, or not at all, based on your commands. The A4988 is dual because it has two H bridges, one for each pair of wires attached to the stepper motor. The A4988 specifically can drive up to 1 amp continuous, and up to 2 with extra cooling. The chip also handles the chore of remembering the correct sequence of H bridge changes to make your stepper motor move. You only need to tell the driver which direction and when to step.
Click for a larger version.
The wire to Arduino pin 2 controls the direction of movement. The wire on pin 4 controls when the step happens. The wire on pin 6 controls the enable feature. When the chip is not enabled the motor doesn’t use power, saving energy.
Words of caution
- Never change the circuit wiring while the power is on.
- Some very rare times the motor power can spike very briefly, frying the driver. A 47uF (or greater) capacitor will protect the driver. I have put a 100uF capacitor in the picture below.
- Make sure to have a common ground – A wire that connects the 12v motor ground to the 5v Arduino ground. Without it the motor may not step when you expect.
Clone the a4988tester Github repository and load A4988tester.ino into your Arduino UNO. You should see the stepper motor move forward and backward even amounts as soon as 12v power is connected. Open the Arduino Serial Window at 57600 baud to see messages from your Arduino, then follow along in the code to understand how it works.
The A4988 chip supports microstepping – splitting each step into fractions of steps. At most the A4988 will support 1/16th steps. In the circuit above you can see three pins on the bottom left edge of the A4988 that are unused. Putting 5 volts to these pins will change the microstepping settings. The pins (from left to right) are MS1, MS2, and MS3.
Try it yourself
Can you double the number of steps in one direction?
Can you add a button to control the direction, or the stepping?
Can you add code to listen for typed instructions that will move when you want?
Can you add wires and turn on the microstepping?
Got more questions? Ask in our forums, we’re happy to help.
Here are the parts I used to make this tutorial.