Stepper motor working
I will use four steep stepper motors in this project. There are usually 5 or 6 wires coming out of a four-curve stepper motor. In 5 wires, one is our vcc (external voltage) and the 4 renamed are step wires. In 6 wires, 2 are our vcc (external voltage) and the renamed four are step wires.
- To know how the stepper motor works? Here is a good tutorial.GOOD TUTORIAL FROM WIKIPEDIA.
The stepper motor works from 5 volts to 12 volts. The stepper motor I am using in this tutorial is NEMA 17. It is a bipolar stepper motor. Each step taken by the nema 17 stepper motor accounts for an increase of 1.8 degrees. Therefore, in 200 steps, nema 17 completes a rotation of 360 (200 * 1.8 = 360) degrees. Our concern in this tutorial is just rotating the stepper motor.
Stepper Motor Power Consumption
Using ULN2003 driver for stepper motor
8051 microcontroller stepper motor – Design circuit
Connect port #1 of 8051 microcontroller (89c51) four bits lower to ULN2003 driver ic. The 89c51 microcontroller is unable to produce enough voltage/current to drive a motor, so a driver IC is required to meet the motor's voltage/current requirements. The output of the ULN2003 is connected to our stepper motor. Make sure you insert the same wire into the motor that you are specifying in your code step. Make ground pin 8 ULN2003. Apply the same voltage to pin 9 of the ULN2003 that you are applying to your motor.
Stepper motor interface with 89c51 microcontroller circuit diagram is given below. Observe the steps performed by the stepper motor in the GIF image below. For each step, we have to do each step with high pins and follow the pattern shown in the GIF image. Stepper motor pins/wires are colored in yellow, brown, black and green etc. First, we need to be sure of the pitch wire pattern. The Nema 17 stepper motor pattern is shown in the GIF image.
Note: The pattern must be in the correct order to rotate the stepper motor. Pay attention to the color coding of the steepest motor wires below.
Stepper motor interface with 8051 microcontroller – Project code
The code is very simple. It is written in c++ language using keil ide as a software tool to write and compile the code. First the necessary file reg51.h is included. Then a delay function is created to provide some delays in the steps. This delay is very important, use it to avoid back emf (electrical driving force) generated by the motor, otherwise your controller will be damaged by this back emf produced by the stepper motor. You can also speed up the engine rotation by reducing the delay time. In the main function I used some commands to rotate the stepper motor. The commands are explained below. Commands are in hexadecimal format.
P1=0x01 Making the port 1 bit 0 high for the first step. Binary equivalent=00000001
P1=0x00 Making port 1 all bits 0 for the next step. Binary equivalent=00000000
P1=0x02 Making the port 1 bit 1 high for the second step. Binary equivalent=00000010
P1=0x00 Making port 1 all bits 0 for the next step. Binary equivalent=00000000
P1=0x04 Making port 1 bit 2 high for the third step. Binary equivalent=00000100
P1=0x00 Making port 1 all bits 0 for the next step. Binary equivalent=00000000
P1=0x08 Making port 1 bit 3 high for the fourth step. Binary equivalent=00001000
You can also individually declare the bits and make them high and low for enough steps. The while(1) loop is continuously running the motor clockwise. You can also reverse the direction counterclockwise by just reversing the commands, placing the last command (0x08) at the beginning and reversing the
Order in the same way for the rest of the commands.
With a slight modification in the code you can vary the speed of the stepper motor with the 89c51 microcontroller. Just decrease the delay or remove it. To rotate at a given angle, calculate the steps needed to reach the angle and place the steps in the for loop. I hope it makes sense to you.
More projects involving stepper motors and different microcontrollers are listed below. Each design is unique and a dedicated microcontroller controls the stepper motor. All projects are open source. You can modify them according to your needs.