For the Professional Maker: Use stepper motors in your next Arduino MakerPro project
March 02, 2018
Blog
When using an Arduino board, DC motors and hobby servos are relatively easy to control, but stepper motors require a bit more electronic fiddling to get working correctly.
As noted in my last post, you have several motor options when developing a MakerPro project. When using an Arduino board, DC motors and hobby servos are relatively easy to control, but stepper motors require a bit more electronic fiddling to get working correctly. This represents something of a barrier to entry, however, the benefits can be enormous. Not only can steppers give you precise control without external hardware, but they come in standard sizes like NEMA 17 that allow you to design around specific mounting holes, and know that you can replace one with something dimensionally consistent.
Costs are generally reasonable, and if you need precise control, this can actually represent a savings over buying an external encoder to use with a normal DC motor. You will, however, need a way to zero your motors to a known point—usually a simple sensor—in case they’re turned off or somehow loose steps due to mechanical binding.
As for a simple example of what can be done with these motors, you might point to GreatScott!'s peristaltic pump, which he made with a NEMA 17 servomotor in order to ensure that it had the correct dimensions. The result was something better and cheaper than other models that he could buy, and with upgraded control capabilities. Beyond that, the Grbl machine control package is routinely used with Arduino boards in order to control CNC machinery like laser engravers, CNC routers, and the like. As shown here, hacker Barton Dring actually used an Arduino Nano, along with a pair of steppers to make “Coasty” a portable coaster engraving machine. He even sells a custom control board for this device if you’d like to build your own.
As I wanted an easy hands-on intro to this technology, obtained a 28BYJ-48 motor along with a ULN2003A driver board, available together for under $2 with a bit of searching. Shipping can take several weeks, but as with many electronic components, it pays to stock up. By default, the Arduino IDE comes with a “Stepper.h” library for controlling this type of motor, and loosely following along with this example, I loaded the “stepper_oneRevolution” example sketch to see what this $2 wonder could do.
Unfortunately, even after attempting to modify the steps per revolution and various other parameters, I wasn’t able to get it to work correctly. Instead of giving up, I turned to a second tutorial found here that recommended using the AccelStepper library. This supports more features than the default library, including half-stepping mode along with acceleration capabilities, allowing servos to reach a higher speed.
With this new library setup, the stepper works quite well, but does have a limit to how fast it goes before things stop working correctly. It’s noted in the tutorial that higher speeds can be obtained with a higher voltage DC power supply. While steppers may take a bit more work to get functioning correctly, I’m excited to see how these motion components can be used to further enhance my MakerPro builds. As shown in the video below, the linked tutorial even includes footage of a robot made with these motors that is able to move in a square pattern without any external feedback.