How to Interface Stepper Motor with 8051



Stepper motor is a variable reluctance DC motor. When correct input sequence of signal is given to the motor, it starts rotation in steps. ULN2003 is high voltage, high current Darlington arrays each containing seven open collector Darlington pairs with common emitters. Here it is used as a current driving IC. This IC is required because stepper motor require more than 60mA current and since controller doesn’t work at this current rating so this IC provides high current to the stepper motor. In the circuit port P2 as output port which provide input sequence to four input pins of ULN3003 and output of ULN2003 drives the motor.

Input sequences:
Simplest sequence
0001
0010
0100
1000
And for half step size
0001
0011
0010
0110
0100
1100
1000
1001
Circuit :

Code: 

#include<reg51.h>
sfr stepper=0xA0;

void delay(unsigned int count)
{
 int i;
 for(i=0;i<count;i++);
}

void main()
{
 while(1)
 {
  stepper=0x01;
  delay(350);
  stepper=0x02;
  delay(350);
  stepper=0x04;
  delay(350);
  stepper=0x08;
  delay(350);
 }
}
/*****************************/

/**** Half Drive Stepping ****/
#include<reg51.h>
sfr stepper=0xA0;

void delay(unsigned int count)
{ 
 int i;
 for(i=0;i<count;i++);
}

void main()
{
 while(1)
 {
  stepper=0x01;
  delay(300);
  stepper=0x03;
  delay(300);
  stepper=0x02;
  delay(300);
  stepper=0x06;
  delay(300);
  stepper=0x04;
  delay(300);
  stepper=0x0C;
  delay(300);
  stepper=0x08;
  delay(300);
  stepper=0x09;
  delay(300);
 }
}
/*****************************/