Unipolar Stepper Motor

There are 5 wires. The red wire is the positive power input and should be connected to 5V.

Stepper motors comes with specifications as shown below. Few important ones are:

Voltage, Phase, torque, Angle

There are 8 different steps (these 8 steps is one step loop) for the stepper to move forward. Every step will make the shaft rotate with an angle of 5.625/64 degree.So if we want the shaft to revolve one circle, then the step loops we should make is 360/(8*5.625/64)=512(step loops).

5.625/64 is the stride angle that comes from the stepper specification

The Stepper motor needs a module which is basically a motor driver. The following diagram shows the wiring using a UNO board 

 

/* 
 One revolution of Unipolar stepper motor. 
 Using digital pins 8 - 11 of Arduino.
 
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.  
  */
void setup() {                
  // initialize the digital pin as an output.
  pinMode(8, OUTPUT); 
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}
void loop() {
  int i=0;
  //revolve one revolution clockwise
  for(i=0;i<512;i++){
  clockwiserotate();}  
  delay(1000);              // wait for a second
 //revolve one revolution counterclockwise
 for(i=0;i<512;i++){
  counterclockwiserotate();}
  delay(1000);              // wait for a second
}
void clockwiserotate() { //revolve clockwise
  step1();
  step2();
  step3();
  step4();
  step5();
  step6();
  step7();
  step8();
}
void counterclockwiserotate() { //revolve counterclockwise
  step1();
  step7();
  step6();
  step5();
  step4();
  step3();
  step2();
  step1();
}
void step1(){
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  delay(2);
}
void step2(){
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  delay(2);
}
void step3(){
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  delay(2);
}
void step4(){
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  delay(2);
}
void step5(){
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  delay(2);
}
void step6(){
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  delay(2);
}
void step7(){
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  delay(2);
}
void step8(){
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  delay(2);
}