Overview of Stepper Motor
A stepper motor is a type of brushless DC motor that divides a full 360° rotation into a set number of equal steps.
The motor rotates by receiving a specific sequence of control signals, which precisely moves it step-by-step. The rotation speed can be adjusted by varying the frequency of these control signals.
For a detailed guide on stepper motors and instructions on how to use them, see the “Stepper Motor” section in the sensors and modules category.
Connection Diagram of Stepper Motor with Arduino
Interfacing Stepper Motor With Arduino UNO
Stepper Motor Control using Arduino Uno
To rotate a stepper motor alternately in clockwise and counterclockwise directions, we use a six-wire unipolar stepper motor. Although it has six wires, only four are needed for control, as the two center tap wires are connected to a 5V supply.
The motor is driven using a ULN2003 driver, which handles the power requirements.
Note: To identify the winding coils and their center tap wires, measure the resistance between the leads. The resistance measured from a center tap to a winding end will be half the resistance measured between the two ends of the winding.
Stepper Motor Code for Arduino
void setup() {
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
/* Rotation in one direction */
for(int i = 0; i<12; i++)
{
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
/* Rotation in opposite direction */
for(int j = 0; j<12; j++)
{
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}