Connecting Unipolar stepper using L293D
There are actually many ways you can interface a stepper motor to your controller, out of them the most usedinterfaces are:
Interface using L293D - H-Bridge Motor Driver
Interface using ULN2003/2004 - Darlington Arrays
We will dicuss both connection techniques one by one. The above mentioned methods need 4 controller pins for interface.
As you see in the circuit above the four pins "Controller pin 1",2,3 and 4 will control the motion and direction of thestepper motor according to the step sequece programmed in the controller.
Connecting Unipolar stepper using ULN2003/2004
As already discussed in case of L293D, Here in this circuit too the four pins "Controller pin 1",2,3 and 4 will control themotion and direction of the stepper motor according to the step sequece sent by the controller.
code
/*Program to interface stepper motor*/
#include //include at89c51 microcontoller header file
#include"lcd.h"
sbit sw1=P1^0;
sbit sw2=P1^1;
sbit sw3=P1^2;
//connect p0.0 to switch
#define motor P0 //connect lower nibble of port0 to stepper motor
void delay_ms(unsigned int);
unsigned char dir;
int i=0;
void main(void)
{
init_lcd();
display_lcd("STEPPER MOTOR");
cmd_lcd(0xc0);
display_lcd("CONTROLLING");
delay_ms(2000);
while(1) //infinite loop
{
if(sw1==0)
{
cmd_lcd(0x01);
display_lcd("FORWARD");
dir=0;
}
if(sw2==0)
{
dir=1;
cmd_lcd(0x01);
display_lcd("REVERSE");
}
if(sw3==0)
{
dir=2;
cmd_lcd(0x01);
display_lcd("STOP");
P0=0x00;
}
if(dir==0)
{
for(i=0;i<12;i++)
{
motor=0xc0; //for CCW direction "C639"
delay_ms(12);
motor=0x60;
delay_ms(12);
motor=0x30;
delay_ms(12);
motor=0x90;
delay_ms(12);
}
}
if(dir==1)
{
for(i=0;i<12;i++)
{
motor=0x90; //for CCW direction "C639"
delay_ms(12);
motor=0x30;
delay_ms(12);
motor=0x60;
delay_ms(12);
motor=0xc0;
delay_ms(12);
}
}
}
}