In our previous tutorial, we saw how to interface the LCD with 8051 in 4-bit mode. In this tutorial, we are going to learn DC Motor Interfacing with 8051. Let’s run….
Suggestion to read
Introduction
When we talk about controlling the robot, the first thing comes into the mind is controlling DC motors. Interfacing DC motor to the microcontroller is very important concept in Robotic applications. By interfacing DC motor to the microcontroller, we can do many things like controlling the direction of the motor, controlling the speed of the motor. This article describes you how to control the DC motor using AT89C51 controller.
A DC motor in simple words is a device that converts electrical energy (direct current system) into mechanical energy. It is of vital importance for the industry today.
The maximum output current of microcontroller pin is 15mA at 5V. But the power requirements of most of DC motors is out of reach of the microcontroller and even the back emf (electro motive force) which is produced by the motor may damage the microcontroller. Hence it is not good to interface the DC motor directly to the controller. So use motor driver circuit in between of DC motor and controller.
DC Motor Interfacing with 8051
Circuit Diagram
- Input 1 – Port 2.0
- Input 2 – Port 2.1
- Enable 1 – Port 2.2
- Enable 2 – Port 2.3
- Input 3 – Port 2.4
- Input 4 – Port 2.5
Working Algorithm
Forward
- EN Pin High (En1 = 1 or En2 = 1)
- Input 1 or Input 3 Pin High (In1 = 1 or In3=1)
- Input 2 or Input 4 Pin Low (In2 = 0 or In4 = 0)
Reverse
- EN Pin High (En1 = 1 or En2 = 1)
- Input 1 or Input 3 Pin Low (In1 = 0 or In3=0)
- Input 2 or Input 4 Pin Low (In2 = 1 or In4 = 1)
Code
In this code, the First motor will rotate forward and the second motor will rotate reverse.
#include<reg51.h> sbit in1=P2^0; sbit in2=P2^1; sbit en1=P2^2; sbit en2=P2^3; sbit in3=P2^4; sbit in4=P3^5; void forward(); void reverse(); void main() { en1=1; en2=1; while(1) { forward(); reverse(); } } void forward() { in1=1; in2=0; } void reverse() { in4=1; in3=0; }
Output
[ Please find the output image ]
Notes:
- The maximum current capacity of L293 is 600mA/channel. So do not use a motor that consumes more than that.
- The supply voltage range of L293 is between 4.5 and 36V DC. So you can use a motor falling in that range.
- Mostly in Robotic application, we will use DC gear Motor. So the same logic is used for that Gear motor also.
Tasks
Just try these Tasks.
- Connect Switch in any port pin. Connect one DC Motor. The motor should rotate whenever I turn on the switch.
- If i send “F” from serial communication Motor rotate Forward direction. If I send “R”, it should rotate reverse.
- Program to run a motor based on the external Interrupt
In our next tutorial, we will interface the relay to the 8051.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related concepts. And also, I wanted to share my knowledge with everyone in a more straightforward way with easy practical examples. I strongly believe that learning by doing is more powerful than just learning by reading. I love to do experiments. If you want to help or support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!