Increase your Embedded skills with our new online classes (from Just Rs750/-) for details click here

Archive

Posts Tagged ‘stepper motor controller’

AVR Microcontroller Interface with Stepper Motor

June 2nd, 2013 Comments off

AVR Microcontroller Interface with Stepper Motor:

In this Tutorial we are using atmega8 with 4 MHZ Crystal and unipolar stepper motors, ULN2003 is Darlington pair driver I.C’s used. The ULN2003 is connected to microcontroller Port PB0 to PB3, the output of the ULN2003 is connected to stepper motor 4 coils, before connection to identify the coil sequence with help of Digital Multimeter.
The voltage source for microcontroller and Motor is separately given otherwise use optocoupler because of Back E.M.F. To write software sequence for stepper motor to rotate the direction clockwise or anticlockwise. In this tutorial we use AVR Studio 4 and simulator oshonsoft, the same way you have to construct your hardware it will work, some slight modification or without modification.

Code:



//Driver for Stepper Motor Interface
//Atmega 8 with 4 MHZ crystal
//Author Embed4u Team

//website:www.embed4u.com


#include<avr/io.h>
#include<util/delay.h>


unsigned char v[]={0x09,0x05,0x06,0x0a};//stepper motor bit pattern for full step sequence Forward Direction
unsigned char w[]={0x0a,0x06,0x05,0x09};//Stepper motor for Reverse Direction
unsigned int k,l,m,n;                        //Global declaration 


void main()                 //main program start here
{
DDRB=0xff;

while(1)                  //Endless loop
{
for(n=0;n<5;n++)          //This loop for Deg of rotation
{
for(k=0;k<4;k++)         //loop for 4 values for stepper motor sequence
{
PORTB=v[k];              //Forward Direction
_delay_ms(2);            //2ms delay 
}
}
for(m=0;m<5;m++)
{
for(l=0;l<4;l++)
{
PORTB=w[l];            ////Reverse Direction  
_delay_ms(2);
}
}
}
}

Circuit:

Video: