Stepper Motor Interfacing With ATMEGA32
Stepper Motor Interfacing With ATMEGA32
Objectives: After successfully completion of this experiment students will be able to,
● Use C language for ATMega32 microcontroller programming on AVRStudio.
● Experiment with Stepper motor interfacing with ATMega32 on ATMega32 AVR
Development Board.
Equipment required:
● Windows7 or later based host computer
● ATMega32 Development board
● USBasp Programmer
● Jumper Wires
● Stepper Motor
Software required:
Theory:
Enough of boring theory, let’s assume someone gives you a stepper motor say the famous 28-
BYJ48 and you are really curious to make it work. By this time you would have understood that
it is not possible to make these motors rotate by just powering them through a supply, so how
would you do it?
Okay, so unlike a normal DC motor this one has five wires of all fancy colors coming out of it
and why is it so? To understand this we should first know how a stepper which we already
discussed. First of all steppers motors do not rotate, they step and so they also known as step
motors. Meaning, they will move only one step at a time. These motors have a sequence of coils
present in them and these coils have to be energized in a particular fashion to make the motor
rotate. When each coil is being energized the motor takes a step and a sequence of energization
will make the motor take continuous steps, thus making it to rotate. Let us take a look at the coils
present inside the motor to know exactly know from where these wires come from.
As you can see the motor has unipolar 5-lead coil arrangement. There are four coils which
have to be energized in a particular sequence. The Red wires will be supplied with +5V and the
remaining four wires will be pulled to ground for triggering the respective coil. We use any
microcontroller to energize these coils in a particular sequence and make the motor perform the
required number of steps. Again there are many sequence you can use, normally a 4-step is used
and for more precise control an 8-step control can also be used. The sequence table for 4-step
control is shown below.
Most stepper motors will operate only with the help of a driver module. This is because the
controller module (Microcontroller/Digital circuit) will not be able to provide enough current
from its I/O pins for the motor to operate. So we will use an external module like ULN2003
module as stepper motor driver. There are a many types of driver module and the rating of one
will change based on the type of motor used. The primary principle for all driver modules will be
to source/sink enough current for the motor to operate.
INTERFACING DIAGRAM
● Here we are going to interface 6 wires Unipolar Stepper Motor with ATmega32
controller.
● Only four wires are required to control the stepper motor.
● Two common wires of stepper motor connected to 5V supply.
● ULN2003 driver is used to the driving stepper motor.
● Note that to know winding coil and their center tap leads measure resistance in between
leads. From center leads, we will get half the resistance value of that winding.
CODE:
#define F_CPU 8000000UL /* Define CPU Frequency 8MHz */
#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include delay header file */
int main(void)
{
int period;
DDRD = 0x0F; /* Make PORTD lower pins as output */
period = 100; /* Set period in between two steps */
while (1)
{
/* Rotate Stepper Motor clockwise with Half step sequence */
for(int i=0;i<12;i++)
{
PORTD = 0x09;
_delay_ms(period);
PORTD = 0x08;
_delay_ms(period);
PORTD = 0x0C;
_delay_ms(period);
PORTD = 0x04;
_delay_ms(period);
PORTD = 0x06;
_delay_ms(period);
PORTD = 0x02;
_delay_ms(period);
PORTD = 0x03;
_delay_ms(period);
PORTD = 0x01;
_delay_ms(period);
}
PORTD = 0x09; /* Last step to initial position */
_delay_ms(period);
_delay_ms(1000);
OUTPUT:
CONCLUSION:
In this experiment, we successfully interfaced a stepper motor with the ATMega32
microcontroller using the ULN2003 driver. We controlled the direction of rotation
(clockwise and anticlockwise) using both full-step and half-step sequences. This experiment
demonstrated how stepper motors operate by energizing coils in a specific pattern. It also
emphasized the importance of a driver module to supply sufficient current and isolate the
microcontroller. This kind of motor control is widely used in precision systems such as
CNC machines, 3D printers, and robotic actuators.
Experiment-12 Post Lab Exercise
Student Name: Viraj Vaghasiya
______________________________________________________________________
Enrollment No: 92301733027
_________________________________________________________________________
Answer: ULN2003
Answer: True
3) In stepper motor, what do we mean by full step sequence and half step sequence?
Answer:
Full step: Energizes two coils at once for greater torque.
Half step: Alternates between one and two coils for smoother and more precise
movement.
5) What kind of applications are there for using the stepper motor in the microcontroller
project?
Answer: Used in robotics, CNC machines, camera sliders, 3D printers, and other
automation systems requiring precise motion control.