Stepper Motor Tutorial
Stepper Motor Tutorial
January 2013
Undergraduate Program
Instructor: Chaiyaporn Silawatchananai, Matthew N. Dailey
Hardware Summary
Stepper Motor: is a motor that runs in step, its rotor turns through a specific number of degrees and
then stops. It converts electronic digital signals into mechanical motion in fixed increments. Each time an
incoming pulse is applied to the motor, its shaft turns or steps a specific angular distance. The shaft can
be driven in either direction and operated at low or very high stepping rates. Therefore the stepper motor
has the capability of controlling the velocity, distance, and direction of a mechanical load. It also produces
a holding torque at standstill to prevent unwanted motion or disturbance.
One attractive feature of the stepper motor is that it responds to digital signals. It can be controlled
by computers or a computer peripheral device. The stepper motor is typically used in an open-loop system
which position is determined by counting pulses. They are used in many practical applications such as
printer, CD players, floppy discs and X-Y positioning tables.
There are two types of stepper motor: unipolar motor and bipolar motor. We can distinguish bipolar motors
from unipolar motors by measuring the coil resistance. In bipolar motors we can find two wires with equal
resistance. Alternatively 4-wire steppers are strictly Bipolar, while 5 and 6 wire motors with center-taps
are Unipolar.
Unipolar motor contains centre tapped windings. Usually centre connection of coils are tied together
and used as the power connection. By using this arrangement a magnetic poles can be reversed without
reversing the direction of current. Thus the commutation circuit can be made very simple. This ease
of operation makes Unipolar Motor popular among electronics hobbyists.
1a
1b
2a
2b
+---+---+---+----+---+---+---+-+---+---+---+----+---+---+---+
ULN2003 IC: is a high-voltage high-current Darlington transistor arrays. Each consists of seven NPN Darlington pairs that feature high-voltage outputs with common-cathode clamp diodes for switching inductive
loads. The collector-current rating of a single Darlington pair is 500 mA. Applications include relay drivers,
hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers, and logic buffers. This
IC-chip has a bunch of transistors embedded in a single housing. It allows the connection of devices and
components that need much higher current than the ones that the our Arduino board can offer.
You can connect the circuit as in the Figure 3 for bipolar stepper motor control or Figure 4 for unipolar
stepper motor control. We will use 4 outputs pins from the Arduino to control the motion of stepper motor.
Code-1: Write your program to make the motor spin and control the direction by using serial communication, the code given below is not complete, you should be able to write a complete working code.
Pin assignments
int
int
int
int
int
motorPin1
motorPin2
motorPin3
motorPin4
delayTime
=
=
=
=
=
8;
9;
10;
11;
10;
Conclusion and results: After download the compiled program on your Flash memory. Press A to
command stepper motor rotate and Press B to move in oppositive direction. When we send command
once, the stepper motor rotates for 4 steps according to moveForward function. So we can find the number
of steps per revolution. To change direction, change the control sequence. We can adjust the speed by Press
W or S which the delay time of each sequence is increased or decreased.
Code-2: Write your program to control the motor shaft to absolute position by using serial communication,
the code given below is not complete, you should be able to write a complete working code.
Pin assignment and defined variable
int motorPinS[] = {8,9,10,11};
//working variable
int delayTime = 10;
int steps = 200; //number of steps per rev
int gear = 1;
int step_counter = 0;
The setup function
int i = 0;
for(i=0; i<4; i++){
pinMode(motorPinS[i], OUTPUT);
}
Serial.begin(9600);
Define the function to tell motor to move a certain angle
void moveAngle(float angle){
int i;
int howmanysteps = angle/stepAngle();
if(howmanysteps<0){
howmanysteps = -howmanysteps;
}
if(angle>0){
for(i = 0;i<howmanysteps; i++){
Forward(i%4);
delay(delayTime);
}
}else{
for(i=0;i<howmanysteps;i++){
Backward(i%4);
delay(delayTime);
}
}
}
void moveToAngle(float angle){
moveAngle(angle-actualAngle());
}
// actual stepper motor angle
float actualAngle(){
return step_counter*stepAngle();
}
// angle made by each step
float stepAngle(){
return (360.0)/(steps*gear);
}
// backward step
void Backward(int coil){
int i;
int count2[] = {1, 2, 4, 8};
for(i=0; i<4; i++){
digitalWrite(motorPinS[3-i], count2[coil]>>i&0x01);
}
step_counter--;
}
// forward step
void Forward(int coil){
int i;
int count2[] = {1, 2, 4, 8};
for(i=0; i<4; i++){
digitalWrite(motorPinS[i], count2[coil]>>i&0x01);
}
step_counter++;
}
The loop function
byte val;
if(Serial.available()){
val = Serial.read();
switch (val) {
case 'A': moveToAngle( 0); break;
case 'B': moveToAngle( 45); break;
case 'C': moveToAngle( 90); break;
case 'D': moveToAngle(135); break;
case 'E': moveToAngle(180); break;
case 'F': moveToAngle(225); break;
case 'G': moveToAngle(270); break;
case 'H': moveToAngle(315); break;
case 'W': delayTime--; break; //increase speed
case 'S': delayTime++; break; //decrease speed
}
Serial.print(val);
}
Assignment: Write Arduino Program to rotate stepper motor for 30 degrees in every 1 seconds.
References
http://arduino.cc/en/Tutorial/StepperUnipolar
http://mechatronics.mech.northwestern.edu/design_ref/actuators/stepper_intro.html
http://silveiraneto.net/2009/03/16/bumbabot-1
Industrial Control Electronics: Devices, Systems & Application by - Terry Bartelt.