Lesson 25 Stepper Motor

Share for us

Introduction

Stepper motors, due to their unique design, can be controlled to a high degree of accuracy without any feedback mechanisms. The shaft of a stepper, mounted with a series of magnets, is controlled by a series of electromagnetic coils that are charged positively and negatively in a specific sequence, precisely moving it forward or backward in small “steps”.

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.

SunFounder board or other MCUs cannot directly drive stepper motors. A driver circuit is necessary, so we use a stepper motor driver board (as shown in the following picture) to drive the stepper motor.

Components

– 1* SunFounder Uno board

– 1*USB data cable

– 1*Potentiometer

– 1*Stepper Motor

– 1* Stepper Motor Driver

– Several jumper wires

– 1*Breadboard

Experimental Principle

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 stepper motor by an appropriate timing sequence, you can make the motor rotate step by step. The schematic diagram of a four-phase reactive stepper motor is as shown below:

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:

At the beginning, switch Sis power on, switch SA, SC, and Sis power off, andB-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 Sis power onswitch SB, SA, and Sis power offthe 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 four-phase stepper motor has three operating modes: single four-step, double four-step, and eight-step. The step angle for the single four-step and double four-step are the same, but the driving torque for the single four-step is smaller. The step angle of the eight-step is half that of the single four-step and double four-step. Thus, the eight-step operating mode can keep high driving torque and improve control accuracy. In this experiment, we let the stepper motor work in the eight-step mode.

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 end is at high level, the output end 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. So D1 lights up, switch SA  is power on, and the stepper motor rotates one step. The similar case repeats on and on. Therefore, just give the stepper motor a specific timing sequence, it will rotate step by step. The ULN2003 here is used to provide particular timing sequences for the stepper motor.

Experimental Procedures

Step 1: Build the circuit

The wiring between Stepper Motor Driver board and SunFounder Uno board:


Stepper Motor Driver
SunFounder Uno
IN12
IN24
IN33
IN45
GNDGND
VCC5v

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorials on our website)

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Now, adjust the potentiometer, the rocker arm of the stepper motor will rotate corresponding degrees.

Code 

#include <Stepper.h>

//the steps of a circle
#define STEPS 100

//set steps and the connection with MCU
Stepper stepper(STEPS, 2, 3, 4, 5);

//available to store previous value
int previous = 0;

void setup()
{
  //speed of 180 per minute
  stepper.setSpeed(180);
}

void loop()
{
  //get analog value
  int val = analogRead(0);

  //current reading minus the reading of history
  stepper.step(val – previous);

  //store as prevous value
  previous = val;
}