Interfacing DC Motor with 8051 Microcontroller
In this project, we will delve into the L293D and L298N motor drivers and explore their applications in interfacing a DC motor with an 8051 microcontroller.
When we contemplate the operation of a robot, the immediate consideration is often the control of DC motors. In robotics, establishing a connection between a DC motor and a microcontroller stands as a pivotal concept. By linking a DC motor to a microcontroller, we unlock a plethora of possibilities. For instance, we gain the ability to govern both the motor’s direction and speed. This article elucidates the process of utilizing the AT89C51 controller for the purpose of controlling a DC motor (or any 8051 Microcontroller variant).

Circuit Principle
At a 5V voltage supply, the maximum output current of a microcontroller pin is limited to 15mA. However, the power demands of most DC motors exceed the capabilities of the microprocessor, and even the reverse electromotive force (EMF) generated by the motor can potentially damage the microcontroller.
Consequently, connecting a DC motor directly to a controller is not a advisable approach. Instead, we employ a motor driver circuit to establish the connection between a DC motor and a microcontroller.
To control DC motors, we are utilizing L293D and L298N motor driver ICs. These ICs enable the simultaneous control of two DC motors. The L293D Motor Driver offers a variable motor supply voltage ranging from 4.5 to 36V, with a maximum current rating of 600mA. Meanwhile, the L298N can accommodate motor supplies up to 46V and can deliver a current of up to 3A.
A Brief Note on L293D Motor Driver
The L293D is a quadruple H-bridge motor driver that is used to drive DC motors, as the name implies. This IC is based on the H-Bridge idea. The H-bridge is a circuit that permits voltage to control the motor direction in either direction.
The L293D has four input pins. The direction of the motors is determined by the logic inputs supplied to these pins. To operate the two DC motors, EN1 and EN2 must be high.
- IN1=0 and IN2=0 -> Motor1 idle
- IN1=0 and IN2=1 -> Motor1 Anti-clock wise direction
- IN1=1 and IN2=0 -> Motor1 Clock wise direction
- IN1=1 and IN2=1 -> Motor1 idle
- IN3=0 and IN4=0 -> Motor2 idle
- IN3=0 and IN4=1 -> Motor2 Anti-clock wise direction
- IN3=1 and IN4=0 -> Motor2 Clock wise direction
- IN3=1 and IN4=1 -> Motor2 idle
A Brief Note on L298N Motor Driver
The L298N Motor Driver Module is more frequently used by driver IC’s nowadays. The current and voltage ratings of L298N are higher than that of the L293D Motor Driver.
Circuit Diagram for Interfacing DC Motor with 8051 Microcontroller and L293D
Components Required
- AT89C51 (8051 Microcontroller)
- 8051 Programmer
- programming cable
- 12V DC battery or Adaptor
- L293D motor driver
- DC motor
- Electrolytic capacitor – 10uF
- 2 Ceramic capacitors – 33pF
- 10k resistors (1/4 watt) – 4
- Push Buttons – 3
- Connecting wires.
Circuit Design
The at89c51 microcontroller and motor driver are the main components in the circuit design above. To regulate the motor directions, the motor driver input pins IN1 and IN2 are linked to P3.0 and P3.1, respectively. The output terminals of the L293D are linked to a DC motor. To drive the motor, the EN1 pin is connected to a 5V DC supply.
Switches are linked to the Microcontroller’s P2.0 and P2.1 in a pull-down configuration. The first switch rotates the motor clockwise, and the second switch rotates the motor counterclockwise. The motor driver’s 8th and 16th pins are connected to the +5V supply.
Algorithm
- Declare P2.0 and P2.1 as inputs and P3.0 and P3.1 as outputs.
- Now check weather the first button is pressed or not. If pressed, then send logic one to P3.0.
- Next check whether the second button is pressed or not. If pressed, then send logic 1 to P3.1 otherwise send 0 to port
Code
#include<reg51.h> | |
sbit switch1=P2^0; | |
sbit switch2=P2^1; | |
sbit clk=P3^0; | |
sbit anticlk=P3^1; | |
void main() | |
{ | |
switch1=switch2=1; //making P2.0 and P2.1 as inputs | |
switch1=switch2=0; | |
clk=anticlk=0; | |
while(1) | |
{ | |
if((switch1)) | |
clk=1; | |
else if((switch2)) | |
anticlk=1; | |
else | |
P3=0x00; | |
} | |
} |
Circuit Simulation Video
Circuit Diagram for Interfacing DC Motor with 8051 Microcontroller and L298N
Components Required
- AT89C51 (8051 Microcontroller)
- 8051 Programmer
- Programming cable
- 12V DC battery or Adaptor
- L298N Motor Driver Module
- 12V DC motor
- Electrolytic capacitor – 10µF
- 2 Ceramic capacitors – 33pF
- 10KΩ Resistor (1/4 watt)
- 1KΩ Resistors (1/4 watt) – 3
- 8 x 1KΩ Resistor Pack
- Push Buttons – 4
- Connecting wires.
Circuit Design
The IN1 and IN2 of the L298N Motor Driver are linked to the Microcontroller’s Port 0 Pins P0.0 and P0.1 in the same way as in the previous circuit. The Motor Driver Module’s OUT1 and OUT2 terminals are connected to a 12V DC motor.
I’ll use three Push Buttons linked to Port 0 Pins P0.5, P0.6, and P0.7 to control the direction of rotation of the motor.
Algorithm
- P0.5 and P0.6 should be inputs, whereas P0.0 and P0.1 should be outputs.
- Check to see if the first button has been pressed. If the button is pressed, send logic 1 to P0.0 and logic 0 to P0.1. The motor will rotate in a forward direction as a result of this.
- Next, look to see if the second button is pushed. If the button is pressed, send logic 1 to P0.1 and logic 0 to P0.0 to reverse the motor’s rotation.
Code
#include<reg51.h> | |
sbit mot1 = P0^0; | |
sbit mot2 = P0^1; | |
sbit forward = P0^5; | |
sbit backward = P0^6; | |
sbit stop = P0^7; | |
void main() | |
{ | |
mot1=0; | |
mot2=0; | |
forward=1; | |
backward=1; | |
stop=1; | |
while(1) | |
{ | |
if(forward==0) | |
{ | |
mot1=1; | |
mot2=0; | |
while(forward==0); | |
} | |
else if(backward==0) | |
{ | |
mot1=0; | |
mot2=1; | |
while(backward==0); | |
} | |
else if(stop==0) | |
{ | |
mot1=0; | |
mot2=0; | |
while(stop==0); | |
} | |
} | |
while(1); | |
} |
How to Operate?
- The program should be burned to the 8051 microcontrollers.
- Make the connections according to the circuit schematics.
- Make sure there is no direct power supply from the battery to the controller while making the connections.
- Turn on the board supply, and the motor should now be stationary.
- When you press the first button, the motor will rotate in a clockwise manner.
- The motor now turns in an anticlockwise direction after pressing the second button.
- Turn off the power to the board.
Applications
- This concept is used in robots to control the robot’s directions.
- Used to control the speed of the DC motor.
- It is used in the applications where we need to drive the high voltage motors.