I this tutorial i am going to control the direction of dc motor using 89c51 microcontroller and l293d motor driver. Running a DC(direct current) motor in both clock and anti clock wise direction using a microcontroller is very easy. The only hurdle is that the dc motor requires more than +5 volt and nearly +100 mill Amperes of continuous direct current but microcontrollers can only output +3.3 volt to +5 volt on their input/output pins. Few methods can be utilized to overcome this problem.
Dc motor direction control with 8051 microcontroller
One method is using a transistor or mosfet at output and instead of powering the motor directly from microcontroller pin, power it with an external source connected to collector of transistor or source of mosfet. This is the cheapest method.
One another method is to use an h-bridge circuit that can provide much greater amount of current and can be used to control the direction of motors(Dc, stepper, servo).
One more advantage of using H-bridge is, we can change the polarity of the current by changing the input logic, this property of the h-bridge make’s our motor to run in both forward(clockwise) as well as backward(anti clockwise) direction.I am going to power, rotate and change the direction of motor by utilizing the second method. H-bridge circuit can be made by using four transistors or mosfets. Making an H-bridge circuit makes a lots of mess on bread board. Its better to purchase one. They are cheap and affordable.
L293D motor driver IC is a replacement of H-bridge circuit and i am going to use it in the project. L293d contains an H-bridge circuit in it. Its small in size, no extra components are required with it. Only a single chip can perform an H-bridge functionality.
L293d motor driver driving dc motor by 8051 microcontroller
L293d is also composed of this h-bridge circuit. Instead of making the circuit by your self just purchase l293d ic and you have a pretty small and efficient h-bridge circuit with you. If you don’t know about the internal structure and working of l293d motor driver just take a small tutorial. This will help you to understand the code written below.
Project Circuit Diagram
The circuit of the project is simple. Port-1 pin#0 and 1 are used to control the direction of motor rotation. An external 11.0592 mega hertz crystal is used to supply clock to 8051 microcontroller. Apply +5 volts to Pin#40 and 31 of 8051(89c51) microcontroller. Ground Pin#20 and connect crystal oscillator to Pin#18 and 20 with 30 to 33 pf capacitors in parallel to crystal. Connect a reset button to Pin#9 to drive the code from beginning. I am going to use channel-1 of l293d motor driver ic. Apply +5 volt to Pin#1 and 8 of l293d. Ground Pin#4 and 5 of l293d. Now take a wire and connect it to Pin#0 Port-1 of 8051 and other end to Pin#2 of L293D motor controller. Take one more wire connect it to Pin#1 Port-1 of microcontroller and the other end to Pin#7 of L293D motor controller. Now take two outputs from L293D Pin#3 and 6 connect them to your motor.
L293d with 8051 microcontroller interfacing/wiring circuit
8051 microcontroller dc motor direction control – Project code
The code is also very simple it is same like making an led blink. I am using keil ide to write and compile my code for the 8051 microcontroller. First i included the header file <reg51.h>. The delay function is used to give some time to motor to run in a particular direction for some time. In the main function I use the Port-1, Pin# 0 and 1 for my logic. P1=0x00 is sending eight bit value to the Port-1 in hexadecimal its binary equivalent is 00000000. The statement is making all the Port-1 eight pins low or it is initializing the Port-1 as output. P1=0x01 sends 00000001 making Pin#0 of Port-1 high and all others low. P1=0x02 sends 00000010 making Pin#1 high and others low. Whole of the logic is in continuous while loop to continuously run the motor. P1=0x00 stops the motor rotation it is important to stop the motor for few milli seconds to dismiss the back emf generated by the motor when it is spinning. Motor rotation according to pin value on port 1.
- When Pin#0 is high and Pin#1 is low, motor rotates in clock wise direction.
- When Pin#1 is high and Pin#0 is low, motor rotates in anti-clock wise direction.
- When both Pin#1 and Pin#0 are low or high motor halts.
Download the project code compiled in keil uvision. Please give us your feed back on the project. In case of any query please write them below in the comments section.
Filed Under: 8051 Microcontroller, Microcontroller Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.