Home / Home made Projects / Microcontroller Projects / Interfacing DC motor with Microcontroller

Interfacing DC motor with Microcontroller

This article will help you to learn why DC motor can not be interfaced directly with microcontroller. How to interface face DC motor with Microcontroller. Components, Circuit diagram and program required for interfacing DC motor with microcontroller.

What are the problems of interfacing dc motor with microcontroller?

It is not possible to connect dc motor to a microcontroller directly. A microcontroller has a very low output current. On the other hand motor draws much higher current therefore connecting directly will not run the motor and destroying the microcontroller due to high currents.

Also the motor produces back emf (voltage) and voltage surges which can also damage the microcontroller. Therefore to save microcontroller from these damages, a driver or an intermediate IC is connected.

L293D Intermediate IC

L293D is a dual H bridge IC. It means two motors can be driven from one IC. The output current is as high as 600mA with peak current up to 1.2A which is a considerable current for electronic components.  To protect the microcontroller form back emf of the motor, diodes are connected at the output of the IC which prevents any current flowing back. The IC has a wide range of motor voltage (Vss) from 4V to 24V which makes it a suitable option to drive dc motor from electronic ICs.

Components for interfacing DC motor with microcontroller

Following components are needed to interface DC motor with PIC microcontroller

  • L293D
  • 5 V DC supply
  • 12 V DC supply
  • DC motor
  • Voltmeter
  • PIC microcontroller
  • Connection diagram
  • Logic state (for experiment purposes)

Connections (Circuit Diagram) for interfacing DC motor with microcontroller

The following figure shows the connection diagram to interface DC motor with microcontroller. DC motor can be connected to microcontroller through the IC L293D. It is a dual motor driver IC and it is usually driven by certain logic and output is motor. It is usually used in robotic applications. This IC can drive two motors. Both circuits are identical.

Output of the IC L293D is connected to the terminal of the DC motor. Inputs of the L293D are connected to microcontroller However for study purpose, logic states are connected to the input of the IC. Vss pin is given 5V to energize the IC.

Both ground pins GND, are connected to ground.  Vs Pin is given 12 V which the required voltage to run dc motor. EN1 is the enable input pin for circuit 1 of the IC L293D. IN1 and IN2 are the inputs based on which the motor will rotate.

L293D connection with DC motor

The LOGIC states and Program

It should be remembered that if motor will only rotate if one of its terminal is high (12V) and other is low (0V). If either both inputs are high or low, the motor will not rotate.

Following table shows the logic which should be given to the inputs of the L293D to control motor.

 
Enable Pin  EN Input 1   (IN1) Input 2  (IN2) Output rotation
0 N/A N/A No rotation
1 0 0 No rotation
1 1 1 No rotation
1 1 0 Clock wise rotation
1 0 1 Anti clockwise rotation

It can be seen from above table that if Enable pin is zero (low), motor will not rotate irrespective of the inputs. If both inputs are zero motor will not rotate. if both inputs are high motor will also not rotate because same high voltage on both terminals of motor.

If one input is high and other is low, motor will rotate.

L293D connection with DC motor 2

When En=0

Testing L293D with DC motor 1

When both inputs are equal either 0 or 1

Testing L293D with DC motor 2

When input 1 is high (clockwise rotation)Testing L293D with DC motor 3

When input 2is high (Anti clockwise rotation)

In this configuration, motor attains maximum speed of 500rpm and rotates with constant speed.  To achieve variable speed, a PWM technique is used which is explained in article

Real time connections for interfacing DC motor with microcontroller

Following figure shows the connection of DC to microcontroller P18F2520 through L293D IC. The pins of microcontroller PORT C are connected to L293D. Rest of connections is already explained. The program is written in MIKRO C and loaded in microcontroller to run the motor.

interfacing dc motor with microcontroller
The test program to run the motor for 5 seconds in clockwise direction and 5 seconds in anti clockwise direction is as follows.

void main()  
{  
TRISC=0;     // make port C as output port
while(1)  
{  
   PORTC = 0b00000101;      // making enable and input 1 as high and rest low including input 2 to rotate     motor in one direction
Delay_ms(5000);             // wait for 5 seconds
PORTC = 0b00000110;    // make input 1 as low and input 2 as high so the motor will rotate in opposite direction
Delay_ms(5000);  
} }  

Modify the program according to your requirement.  If you have any question fell free to ask in comments section. Like our page to get updates about new articles and posts.

About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Power Factor measurement using Microcontroller

The article will help the readers to use microcontroller for power factor measurement using a …

Leave a Reply

Your email address will not be published. Required fields are marked *

*