2.14 Stepper Motor

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Overview

In this lesson, you will learn about Stepper Motor.

Components Required

Component Introduction

Stepper motor is an open-loop control motor by converting the electric pulse signal into angular displacement or line displacement. It is the main executing component in the modern digital program control system. When the stepper driver receives a pulse signal, it drives the stepper motor to rotate a fixed angle in a set direction. The rotation of stepper driver runs step by step at a fixed angle. The angular displacement can be controlled by changing the number of pulses, thereby achieving the purpose of accurate positioning. At the same time, the speed and acceleration of the rotation of the motor can be controlled by adjusting the pulse frequency so as to achieve the purpose of speed regulation.

There are two types of steppers, unipolars and bipolars, and it is very important to know which type you are working with. In this experiment, we will use a unipolar stepper.

The stepper motor is a four-phase one, which uses a unipolarity DC power supply. As long as you electrify all phase windings of the motor by an appropriate timing sequence, you can make it rotate step by step. The schematic diagram of a four-phase reactive stepper motor:

In the figure, in the middle of the motor is a rotor – a gear-shaped permanent magnet. Around the rotor, 0 to 5 are teeth. Then more outside, there are 8 magnetic poles, with each two opposite ones connected by coil winding. So they form four pairs from A to D, which is called a phase. It has four lead wires to be connected with switches SA, SB, SC, and SD. Therefore, the four phases are in parallel in the circuit, and the two magnetic poles in one phase are in series.

Here’s how a 4-phase stepper motor works:

When switch SB is power on, switch SA, SC, and SD is power off, and B-phase magnetic poles align with tooth 0 and 3 of the rotor. At the same time, tooth 1 and 4 generate staggered teeth with C- and D-phase poles. Tooth 2 and 5 generate staggered teeth with D- and A-phase poles. When switch SC is power on, switch SB, SA, and SD is power off, the rotor rotates under magnetic field of C-phase winding and that between tooth 1 and 4. Then tooth 1 and 4 align with the magnetic poles of C-phase winding. While tooth 0 and 3 generate staggered teeth with A- and B-phase poles, and tooth 2 and 5 generate staggered teeth with the magnetic poles of A- and D-phase poles. The similar situation goes on and on. Energize the A, B, C and D phases  in turn, and the rotor will rotate in the order of A, B, C and D.

The stator of Stepper Motor we use has 32 magnetic poles, so a circle needs 32 steps. The output shaft of the Stepper Motor is connected with a reduction gear set, and the reduction ratio is 1/64. So the final output shaft rotates a circle requiring a 32*64=2048 step.

ULN2003

To apply the motor in the circuit, a driver board needs to be used. Stepper Motor Driver-ULN2003 is a 7-channel inverter circuit.

That is, when the input pin is at high level, the output pin of ULN2003 is at low level, and vice versa. If we supply high level to IN1, and low level to IN2, IN3 and IN4, then the output end OUT1 is at low level, and all the other output ends are at high level.

The internal structure of the chip is shown as below.

The stepper motor driver constituted by ULN2003 chip and 4 LEDs is shown as follows. On the board, IN1,IN2,IN3 and IN4 work as input and the four LEDs, A, B, C, D are the indicators of input pin.

In addition, OUT1,OUT2, OUT3 and OUT4 are connected to SA, SB, SC and SD on the stepper motor driver. When the value of IN1 is set to a high level, A lights up;

switch SA is power on, and the stepper motor rotates one step. The similar case repeats on and on.

Fritzing Circuit

Power Supply Module is used to power the stepper motor. Get the GND of Mega 2560 Board and GND of ULN2003 connected to the cathode of the breadboard, and connect the VCC of ULN2003 to 5V OUTPUT of Power Supply.  

The wiring of ULN2003 and Mega2560 is shown as follows:

Schematic Diagram

Code

#include <Stepper.h>   
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 16;        // Adjustable range of 28BYJ-48 stepper is 0~17 rpm

//set steps and the connection with MCU
Stepper stepper(stepsPerRevolution, 2, 3, 4, 5);
 
void setup()
{
  stepper.setSpeed(rolePerMinute);
}
 
void loop()
{
  int val = 2048;
  stepper.step(val);  //Turn the motor in val steps
  delay(1000);
}

After uploading the codes to the Mega2560 board, you will be able to see that the stepper motor rotates one circle with an interval of a second and each circle takes 3.75s.

Code Analysis

By calling the library Stepper.h, you can easily drive the stepper motor.

#include <Stepper.h> 

Library Functions:

Stepper(steps, pin1, pin2, pin3, pin4)

Creates a new instance of the Stepper class that represents a particular stepper motor attached to your Arduino board.

steps: the number of steps in one revolution of your motor. If your motor gives the number of degrees per step, divide that number into 360 to get the number of steps (e.g. 360 / 3.6 gives 100 steps). (int)

Note: every circle of the stepper motor takes 2048 steps.

setSpeed(rpm)

Sets the motor speed in rotations per minute. This function doesn’t make the motor turn, just sets the speed at which it will when you call step().

rpm: the speed at which the motor should turn in rotations per minute – a positive number. (long)

Note: The stepper motor we use here rotates 17 circles a minute at most.

step(steps)

Turns the motor a specific number of steps, at a speed determined by the most recent call to setSpeed().

This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and called step(2048) on a 2048-step motor, this function would take a full minute to run. For better control, keep the speed high and only go a few steps with each call to step().

steps: the number of steps to turn the motor – positive to turn one direction, negative to turn the other. (int)

Phenomenon Picture