DC MOTOR INTERFACING WITH 8051 MICROCONTROLLER



DC MOTOR INTERFACING WITH 8051 MICROCONTROLLERIn many projects of embedded systems, we may need to control a DC motor using controller.  It is not good to connect DC motor directly to the microcontroller. Since the maximum current that can be sink from 8051 microcontroller is 15 mA at 5v. But a DC Motor needs much more currents. It also needs more voltages as 6v, 12v, 24v etc., (depending upon the type of motor used). One more thing to notice is that the back emf produced by the motor may affect the proper functioning of the microcontroller and reversing the direction can damage the controller. Due to these reasons we can’t connect a DC Motor directly to a microcontroller. This article will demonstrate how to control the DC motor using AT89C51 Microcontroller.



MOTOR DRIVER for dc motor interfacing with 8051 microcontroller

To overcome the problems in their interfacing, a motor Driver IC is connected between microcontroller and DC motor. Motor driver is a little current amplifier. It takes a low current signal and gives out a high current signal which can drive a motor. It can also control the direction of motor. We can use any dual H-bridge IC like L293D or L298.

The main differences between L293D and L298 are:



CHARACTERISTICSL298L293D
Max. output current per channel2A0.6A
Peak max. output current per channel 3A1A
Protection diodes across motorsUse externallyInternally available


L298 motor driver is already explained in separate article. In this article, we will use L293D since it does not need external protection diodes.

WORKING OF H-BRIDGE

H-bridge can also be made with the help of transistors and MOSFETs etc. It will be cheap but they increase the size of the design and circuit board which is mostly not required, so a small 16 pin IC is preferred for this purpose. Actually, the name “H-Bridge” is derived from the shape of the switching circuit which controls the motion of the motor. It is also known as “Full Bridge”. Basically there are four switching elements in the H-Bridge as shown in the figure below.

As we can see in the figure that there are four switching elements named as:

  • High side left
  • High side right
  • Low side right
  • Low side leftH bridge for dc motor interfacing

When these switches are turned on in pairs, the motor changes its direction accordingly. If we switch on “High side left” and “Low side right”, then motor will rotate in forward direction, as current from Power supply flows through the motor coil and goes to ground through switch low side right. This is shown in the figure below.H bridge for dc motor interfacing control

Similarly, when we switch on low side left and high side right, the current flows in opposite direction and motor rotates in backward direction. This is the basic working of H-Bridge. We can also make a small truth table according to the switching of H-Bridge explained above.

High LeftHigh RightLow LeftLow RightDescription
OnOffOffOnMotor runs clockwise
OffOnOnOffMotor runs anti-clockwise
OnOnOffOffMotor stops or decelerates
OffOffOnOnMotor stops or decelerates


So we have seen that using simple switching elements we can make our own H-Bridge. Other option is to use IC based H-bridge driver. Obviously, we will use Driver IC otherwise heat sinks will be used for MOSFETs etc.

L293D  for dc motor interfacing with 8051 microcontroller

It is designed to provide bidirectional drive currents of up to 600mA at voltages from 4.5V to 36V. It can drive inductive loads such as solenoids, relays, DC and bipolar stepping motors. It contains internally protection diodes across the motor.  

PIN DIAGRAM:L293D for dc motor interfacing with 8051 microcontroller

PIN DESCRIPTION:

L293D contains four Half H Bridge drivers. We can drive two DC Motors by single driver. 

  • VSS pin is used to provide input voltage to L293D. For 8051 interface, 5v is given to it.
  • The motor supply is given to VS pin of the L293D. It depends upon motor requirement.
  • EN1 is used to enable input pair 1 (IN1, IN2, for OUT1, OUT2) and EN2 is used to enable input pair 2 (IN3, IN4, for OUT3, OUT4). EN is connected to 5V for to enable any input.
  • Direction of motor 1 is controlled through input pins logic. IN1 and IN2 control motor connected output OUT1 and OUT2.
  • Direction of motor 2 is controlled through input pins logic. IN3 and IN4 control motor connected output OUT3 and OUT4.
  • All GND pins should be connected to ground.

CONNECTIONS:

  • P2 of 8051 microcontroller is used as output port and it gives inputs to the motor driver IC. Its lower four pins are connected to drive two DC motors.
  • P0 is used as input port. 2 Buttons are connected to its lower two pins so that whenever we can manually start and stop the motors.
  • Motor 1 is connected between OUT1 and OUT2 of L293D. Motor 2 is connected between OUT3 and OUT4 of L293D.
  • 12V battery is used to give input to the VS for motors.
  • 5V battery is used to give input to VSS for motor driver IC.

PROTEUS SIMULATIONS:dc motor interfacing with 8051 microcontroller proteus simualtion
Circuit Components:

  • AT89C51 microcontroller
  • 12 MHz Oscillator.
  • 12V DC battery.
  • 5V DC battery.
  • L293D motor driver
  • DC motor – 2.
  • 2 Ceramic capacitors – 33pF
  • 300Ω resistors – 2
  • Push buttons – 2
  • Connecting wires.


WORKING  of dc motor interfacing with 8051 microcontorller

After loading the program in the controller, the motors will not start turning until the buttons are not pressed. According to my coding:

When I press button 1, motor 1 starts rotate in clockwise direction.

When I leave button 1, motor 1 will stop.

When I press button 2, motor 2 will start rotating in Anti-clockwise direction.

When I leave button 2, motor 2 will stop.

PINS STATUS:

Enabling pin 1, if we give logic as:

Pin2 = 1, pin7 = 0, motor 1 will start turning clockwise.

Pin2 = 0, pin7 = 1, motor 1 will start turning anticlockwise

Pin2 = 1, pin7 = 1, motor 1 will stop

Pin2 = 0, pin7 = 0, motor 1 will stop


Enabling pin 9, if we give logic as:

Pin10 = 1, pin15 = 0, motor 2 will start turning clockwise

Pin10 = 0, pin15 = 1, motor 2 will start turning anticlockwise

Pin10 = 1, pin15 = 1, motor 2 will stop

Pin10 = 0, pin15 = 0, motor 2 will stop

CODE of dc motor interfacing with 8051 microcontroller

#include <REGX51.H>

void delay(void);

sbit m1_pin1 = P2^0;

sbit m1_pin2 = P2^1;

sbit m2_pin1 = P2^2;

sbit m2_pin2 = P2^3;

sbit B1 = P0^0;

sbit B2 = P0^1;

void main()

{

P2=0x00;   //output port

P0=0x03;   //input port




if (B1==1)

{

    m1_pin1 = 1;

    m1_pin2 = 0;  //Rotates Motor Clockwise

    delay();

   }

else if (B1==0)

{

    m1_pin1 = 0;

    m1_pin2 = 0;  //Stops Motor

    delay();

}
 if (B2==1)

{

    m2_pin1 = 0;

    m2_pin2 = 1;  //Rotates Motor Anticlockwise

    delay();

}

else if (B2==0)

    {

    m2_pin1 = 0;

    m2_pin2 = 0;  //Stops Motor

    delay();

}

}

void delay()

{

  int i;

  for(i=0;i<1000;i++)

  {

  }

}

APPLICATIONS:

  • This concept is used in robots to control the robot 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



2 Comments

  1. Jagdesh kumar June 7, 2017
  2. adhya nair November 3, 2017

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,395 other subscribers