Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Driving DC-motor in both directions forward and reverse using 8051(89c51) microcontroller and with l293d H-bridge motor driver

By EG Projects May 22, 2019

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 and H-bridge circuit

L293D motor driver and H-bridge circuit

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.

  • L293d Pin out, internal structure and Working

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

L293d motor driver with 89c51 microcontroller controlling motor direction

L293d motor driver with 89c51 microcontroller controlling motor direction

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.
DC-motor code files


Filed Under: 8051 Microcontroller, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Collector Current Low side Has a large drop respect High Side during Miller during Double Pulse Test
  • Diode recovery test Irrm timing.
  • The Analog Gods Hate Me
  • How best to synchronise the UCC38C45?
  • floating node warning in LTSpice

RSS Electro-Tech-Online.com Discussions

  • The Analog Gods Hate Me
  • Display TFT ST7789 (OshonSoft Basic).
  • Fixing board, Easy question HEX SCHMITT
  • Can I make two inputs from one??
  • Home Smoke detectors are all Beeping Batteries are not dead.???

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How to monitor temperature and humidity on a TFT display with graphics
  • Tria modules integrate edge AI processing with multi-core processors
  • pSemi introduces RF switch with 52 dBm PMAX,PEAK and 90-dBm IIP3 linearity
  • XP Power launches 1.3 kW power supply with 58.9 W/cmÂł density
  • How to enable Wi-Fi provisioning in ESP32-based IoT products

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe