Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • 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 Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

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 feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • PCB not properly made
  • Flyback converter working incorrectly
  • voltage amplifier for a signal generator
  • What do they connect Y capacitors to in ships?
  • Two Educational Electronics Trainer Projects from Algeria – Detailed Project Overview and Seeking Technical Collaboration

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Jumper Wire Assortment From Digikey
  • How to size the capacitor for ripple
  • Getting rid of old magazines
  • Electronics and PIC Programming Assembler Update
  • PIC code for 2.42" I2C OLED Display?

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Texas Instruments adds agentic AI to CCStudio
  • onsemi adds trench SiC for power systems
  • Silanna launches matched chipset for multi-channel LiDAR
  • Renesas launches browser-based embedded development hub
  • Diodes targets EV charging current sensing

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • 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 © 2026 Arrowfly 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 Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe