Stepper motor Control with Atmega16
With this project you can control a unipolar stepper motor. You can control both the speed and the direction of the motor.
The speed and direction and can changed with help of the keypad. The data's are displayed over the LCD display.
A 4x4 keypad is used for entering the speed and selecting the direction.
Load the hex file into the chip, dont forget to select the internal oscillator at 10Mhz.
Then switch on the circuit and select the direction by pressing the corresponding key (Left or Right). Then enter the speed through the numeric keys and press the Enter key to start the operation. To switch off the motor press the separate switch which is connected to the port A.0
Proteus simulation file is also added with the download file, so that you can run the program on your desktop.
Circuit Diagram
Bascom Code
$regfile = "m16def.dat"
$crystal = 1000000
Config Kbd = Portb
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , Rs = Portc.0 , E = Portc.1
Config Portd = Output
Config Porta = Input
Dim A As Byte , B As Byte , Key As Byte , C As Byte , D As Byte , E As Byte
Cls
Cursor Off
B = 0
D = 1
Q:
Locate 1 , 1
Lcd "Direction:"
Locate 2 , 1
Lcd "Speed:"
Do
'************Read Keyboard
A = Getkbd()
If A > 15 Then
Goto Q
Else
Key = Lookup(a , Dta)
If Key <= 9 Then
B = B * 10
B = B + Key
'*************Direction
If D = 0 Then Lcd B
Waitms 270
Elseif Key = 10 Then
Locate 1 , 11
Lcd "Left"
C = 1
D = 0
B = 0
Elseif Key = 11 Then
Locate 1 , 11
Lcd "Right"
C = 2
D = 0
B = 0
'****************reset
Elseif Key = 13 Then
Cls
D = 1
B = 0
Portd.0 = 0
Portd.1 = 0
Waitms 50
Goto Q
'****************Enter key
Elseif Key = 14 Then
If D = 0 Then
Select Case C
Case 1 : Gosub R
Case 2 : Gosub T
End Select
End If
End If
End If
Wait 1
Loop
End
Dta:
Data 7 , 8 , 9 , 10 , 4 , 5 , 6 , 11 , 1 , 2 , 3 , 12 , 13 , 0 , 14 , 15
R:
Do
Portd = &B00000001 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001001 : Waitms B
If Pina.0 = 1 Then
Locate 2 , 1
Lcd "Speed:"
B = 0
Lcd B ; " "
Return
End If
Loop
T:
Do
Portd = &B00001001 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000001 : Waitms B
If Pina.0 = 1 Then
Locate 2 , 1
Lcd "Speed:"
B = 0
Lcd B ; " "
Return
End If
Loop
Download
Similar Posts
- Simple calculator using avr microcontroller
- Measure negative temperature with Lm35
- Connect 2 microcontrollers through serial port

2.19.2010 at 2:58 PM
Some newbie q =) why u use uln2003? u have "free" PA pins.
Or it's some Step motor control speciality? I just whant "read you mind" about this=)
PS: sorry for my eng=)
2.20.2010 at 3:25 PM
ULN2003 is a driver IC. You cant drive a stepper motor directly from a microcontroller. A microcontroller can drive a max load of a LED.
4.06.2010 at 1:19 AM
how can i see your downloaded code so i can modify it
4.22.2010 at 10:31 AM
hi,i am learing more in this web. am wokeing in gland pharma ltd in field i faceing one problem.i.e stepper moter wokeing whit encoder single. how it wokes?
4.26.2010 at 2:15 PM
You can download the code from here avrprojects.info/.../Stepper-motor-w
5.01.2010 at 12:08 PM
hello sir
i want to make the same project its my mini project for the semister but can you please tell me that can i implement this code on atmega162 and can this code be transfered on assembly language i am finding difficulty to understand that code please
5.18.2010 at 11:14 PM
hey how can i make calculator using this programe? i cant put int value on lcd. i wanna use itoa command bt its not working
7.19.2010 at 6:52 PM
HI THERE,
can you show this code using codevision >?