Stepper Tutorial

Stepper motor parts.
The stepper's insides

Stepper motors are similar to synchronous AC motors, or brushless DC motors. The rotor is magnetized and the stator is four pairs of electromagnets. The motor is controlled by driving current through those electromagnets, which forces the rotor to turn to align with them. Where the rotor on a brushless motor may have four poles, the rotor of the stepper motor has dozens of poles. The many closely spaced poles allow the controller to move the motor a fraction of a revolution and stop.

The wiring of a stepper motor can be 4 to 8 lead. The connections vary based on whether the motor is wired to use bipolar or unipolar drive. Bipolar drive means the voltage on two ends of the coil are first one way, and then reversed. This is generally more efficient than unipolar drive, where one end of the coil is held high and the other end is brought low to energize the coil. Bipolar motors will have 4 or 8 leads. Unipolar will have 5 or 6 leads.

The stepper motor is a Mercury Motion bipolar stepper SM-42BYG011-25. It has 200 steps per revolution (1.8° per step) and a DC resistance of 33Ω per coil. It came from Sparkfun. The data sheet is linked to on the product page. It is about the largest motor I would try to run without a dedicated supply.

The Driver

Stepper motor tutorial.

The Arduino can't supply enough current or voltage to directly drive one of these stepper motors. For that an external driver is required. These L298N driver boards will drive one stepper motor per board. Four Arduino digital outputs are required to drive a single motor.

This driver was picked up on ebay for under $3.00 delivered, and has an L298N motor driver IC, a 5V regulator, and protection diodes. All high-current connections are screw terminals. Signal level connections are header posts.

Arduino Stepper Tutorial Schematic

There are only three parts to this circuit - Arduino Uno, driver, and stepper motor. The wiring should be 26 gauge or larger on the 12V and ground lines. The driver inputs are just 5V signal level. You must provide an external 12V power supply, plugged into the Arduino power jack. If the motor is too large, you will need to run the 12V directly to the driver board, and not run it through the Arduino.

Arduino Code

The Code

The example code is very simplistic. Setting the step rate too high will cause the motor to miss steps. A proper stepper controller accelerates from a low step rate to a high rate, and then decelerates from the high rate to a low rate. This is because inertia tries to prevent the stepper from turning at first, and then tries to keep the motor turning after the electrical drive has stopped. Acceleration and deceleration help prevent dropping steps and overshoot during starts and stops without limiting the maximum speed. It takes software to build a profile and a controller to apply the profile to the drive, but very high speeds can be had. One particular drive would turn a prism 90 degrees in 30 mS from stop to stop, accelerating to 5000 steps per second and immediately decelerating to a stop. The motor just made a "click" sound at that speed.

    
#include <Stepper.h>

// change this to fit the number of 
// steps per rev for your motor.
const int stepsPerRevolution = 200;  

Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 30 rpm:
  stepper.setSpeed(30);
}

void loop() {
  // Turn clockwise one revolution
  stepper.step(stepsPerRevolution);
  delay(500);

  // Turn counterclockwise one revolution
  stepper.step(-stepsPerRevolution);
  delay(500);
}
    

Steps per Revolution vs. Degrees per Step

If you don't know your steps per revolution, but you do know the degrees per step, you can find the steps per revolution by dividing 360 degrees by the degrees per step. A 1.8° per step motor has:

360° ÷ 1.8 = 200 steps per revolution

If you know the steps per revolution, but need the degrees per step, divide 360° by the steps:

360° ÷ 200 = 1.8° per step

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.