Programming the Stepper Motor

In order to get the stepper motor to work the way we want it to, we need to import a library that makes it easy to incrementally rotate the motor’s shaft in either direction at the speed we want it to move. Fortunately, controlling a stepper motor is easy thanks to Adafruit’s AFMotor motor shield library.[83] As you do with most Arduino libraries, extract the downloaded zip file, rename the extracted folder (AFMotor), and place it in the Arduino libraries folder. For more details, refer to Appendix 1, Installing Arduino Libraries.

With the AFMotor library installed, launch the Arduino IDE. Let’s write a sketch that will test the stepper motor. The code will do the following:

  1. Load the AFMotor library.

  2. Create ...

Get Programming Your Home now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.