Stepper motor is an electromagnetic device that converts digital pulses into mechanical shift rotation. It has high simplicity, since no brushes or contacts are presents, low cost, high reliability, high torque at low speed, and high accuracy of motion. Types of stepper motors-
- Bipolar Stepper Motor
- Unipolar Stepper Motor

The bipolar motor is activated when current in both directions through the windings and a full bridge driver is needed. The center tap on the unipolar motor allows a simple driving circuit, limiting the current flow to one direction. The main drawback with the unipolar motor is the limited capability to energize all the windings at any time, resulting in a lower torque compared to the bipolar motor. The unipolar stepper motor can be used as a bipolar motor by disconnecting the center tap.
The AVR pins cannot be used to drive the coils directly, since it can sink or source 20mA current only. So we need a driver and that is ULN2003A. It is a high voltage , high current Darlington pair array. It can be used to converts TTL(Transistor Transistor Logic) level input to desired input level.

Full Vs Half stepping control logic
Stepper motor used in full-stepping mode powers one winding at a time. On the other hand by powering both windings simultaneous, the stepper motor is trapped between the positions obtained when full-stepping, also known as half-stepping.

![]()
Arrays-
An array is a fixed-sized sequenced collection of elements of the same data type. Array is nothing but a table of collection of same data type. Following types of arrays are commonly used-

- Declaration of one dimensional array
data_type variable_name[size]=initialized;
If we doesn’t initialized at begin the default value of all array elements should be zero.

So size is number of storage that allocated in the memory location.
i.e. char name[20]=”shani”
Here name is a character array that allocated 20bit of memory space, but in this case only 0-18 position will be filled with character and 19th character will be ‘ ’(null character). Although we allocate 20bit only 5bits are initialize so other remain 14bits contents zero that is ‘ ’(null character).
After declare the array, if we do not initialize the array than each element value should be zero.
i.e. int digit[8]—–> all the value is zero
float data_point[3]={2.1,0};
The 0 and 1 value is corresponding to 2.1 and 0 and other two element is automatically become zero. If we initialize more than the size then an error occur.
i.e. char name[10]=”RUET EEE 09”
The declaration is illegal since there is an size error.
Note that all other data type are initialize inside {} but character are initialize inside “” . Also note that a collection of character i.e. character array is string that will be discuss later.
- Declaration of Two dimensional array
data_type array_name[row_size][column_size]=initialization;
i.e. double digit[3][2]
This allocate memory space 4*3bits as shown in table.
For Counter Clock Wise (CCW) direction the sequence is from 1 to 8 and for Clock Wise (CW) flow from 8 to 1.
/************************************************************************************************
*************************************************************************************************
This program will drive the sepper motor in Full stepping
/*********************************************************************************************/
/***** Stepper Motor Counter Clock Wise (CCW) Direction 1-8 *********/
/***** Stepper Motor Clock Wise (CW) Direction 8-1 *********/
/***** | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | *********/
/***** Red --- | + | + | + | + | + | + | + | + | *********/
/***** Orange --- | - | - | | | | | | - | *********/
/***** Yellow --- | | - | - | - | | | | | *********/
/***** Pink --- | | | | - | - | - | | | *********/
/***** Blue --- | | | | | | - | - | - | *********/
/*********************************************************************************************
************************************************************************************************
***********************************************************************************************/
#include "avr/io.h"
#include "util/delay.h"
#define STEPPER_DDR DDRD
#define STEPPER_PORT PORTD
#define STEP 1024 //90degree
int motor_pattern_CCW[8] = {0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
int motor_pattern_CW[8] = {0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
int main(void)
{
DDRB&=~(1<<DDB0);
STEPPER_DDR |= 0x0f; // making PORTD as output
unsigned int index=0;
while(1)
{
if(PINB&(1<<PINB0)) STEPPER_PORT = motor_pattern_CCW[index++];
else STEPPER_PORT = motor_pattern_CW[index++];
index = index % 8;
_delay_ms(10);
}
return 0;
}







Visit Today : 47
Total Visit : 28462