This chapter discusses the following functions of the Stepper library:

  • Stepper()
  • setSpeed()
  • step()

The hardware needed to use these functions includes:

  • Arduino Uno
  • 1 x L293D
  • 1 x 5-V bipolar stepper motor
  • Breadboard
  • Cables

You can find the code downloads for this chapter at on the Download Code tab. The code is in the Chapter 15 download and the filename is Chapter15.ino.

Introducing Motors

Electric motors generally work by creating electromagnetic fields from coils, forcing magnets on an axle to move, therefore driving the axle. By generating electromagnetic fields, a motor turns continuously until current is removed.

Servo motors (presented in Chapter 14) function a little differently, but even if their usage is different, a servo motor is still controlled by an ordinary electric motor managed by a small microcontroller to ensure the servo motor can move to a precise position.

Stepper motors are different. They have several coils inside, and the internal axle is “toothed.” When applying current to one of the coils, the closest “tooth” is attracted to the coil, and the axle moves by a few degrees. Current is then removed from the coil and sent through another coil, again attracting a tooth and moving the axle by a few degrees. By repeating this operation, a stepper motor can be controlled to turn continuously in either direction, but this is not normally a stepper motor's main function. Stepper motors can have precise ...

Get Arduino Sketches: Tools and Techniques for Programming Wizardry now with O’Reilly online learning.

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