8.3 Using the Stepper Motor
Electrical motors work on the principle of electromagnetism to drive the central shafts. As the magnetic field changes around the coils that wrap around the shaft, the change in current propels the shaft forward or backward. Stepper motors refine this principle by allowing granular control of the motor to “step” in well-defined increments. This makes these motors excellent choices for any mechanical task requiring precise control.
Stepper motors are used in ink jet printers, plotters, and disk drives; they are also found in a number of types of industrial manufacturing equipment.
The motor we will use for this project is a popular 12-volt, 350-milliamp, 200-steps per revolution bipolar stepper motor. This motor should provide enough torque to move all but the heaviest of curtains. Because the motor pulls 12 volts of power, it will need to operate from a 12-volt power supply instead of the 5 volts that the standalone Arduino board can deliver. Fortunately, the Arduino board has the electronics necessary to accept a 12-volt power supply that can power the Arduino, the motor shield, and the stepper motor.
Assuming that you have already built a working Adafruit motor shield, here are the steps needed to set up the stepper motor for programming:
-
Connect the four wires from the 12-volt bipolar stepper motor. If your stepper motor is the recommended one from Adafruit, the wiring sequence by color should be red, yellow, green, brown. Refer to the photo in Figure 32, Bipolar stepper motor wiring.
-
Attach the motor shield to the top of the Arduino Uno.
-
Plug the 12-volt power supply into the Arduino power port.
-
Connect a USB cable from the computer to the Arduino.

Figure 32. Bipolar stepper motor wiring
Now that the hardware is connected, we can focus on writing an Arduino sketch that will drive the stepper motor.