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.
– 1 * SunFounder Uno board
– 1 * USB data cable
– 1 * Stepper Motor
– 1 * Stepper Motor Driver
– Several jumper wires
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 SB is power on, switch SA, SC, and SD is 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 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 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.
The internal schematic diagram of the Stepper Motor Driver is as follows.
Step 1: Build the circuit
The wiring between Stepper Motor Driver board and SunFounder Uno board:
|Stepper Motor Driver||SunFounder Uno|
Step 3: Compile the code
Step 4: Upload the sketch to the SunFounder Uno board
Now, you should see the rocker arm of the stepper motor spin clockwise and counterclockwise alternately.
* name:Stepper Motor
* function:you should see the rocker arm of the stepper motor spin clockwise and counterclockwise alternately.
* Stepper Motor SunFounder Uno R3
* IN1 11
* IN2 10
* IN3 9
* IN4 8
//Website:www.sunfounder.comconst int IN1=11;
const int IN2=10;
const int IN3=9;
const int IN4=8;
const char tab1 =
0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x09
const char tab2 =
0x01, 0x09, 0x08, 0x0c, 0x04, 0x06, 0x02, 0x03
// put your main code here, to run repeatedly:
}void ctlStepMotor(int angle, char speeds )
for (int j = 0; j < abs(angle) ; j++)
if (angle > 0)
for (int i = 0; i < 8; i++)
digitalWrite(IN1, ((tab1[i] & 0x01) == 0x01 ? true : false));
digitalWrite(IN2, ((tab1[i] & 0x02) == 0x02 ? true : false));
digitalWrite(IN3, ((tab1[i] & 0x04) == 0x04 ? true : false));
digitalWrite(IN4, ((tab1[i] & 0x08) == 0x08 ? true : false));
for (int i = 0; i < 8 ; i++)
digitalWrite(IN1, ((tab2[i] & 0x01) == 0x01 ? true : false));
digitalWrite(IN2, ((tab2[i] & 0x02) == 0x02 ? true : false));
digitalWrite(IN3, ((tab2[i] & 0x04) == 0x04 ? true : false));
digitalWrite(IN4, ((tab2[i] & 0x08) == 0x08 ? true : false));