Sie sind auf Seite 1von 12

DC Motor Control | eXtreme Electronics

1 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Home
Ads by Google

Stepper Motor

DC Motor

AVR C

Motor Control

Home
Atmel AVR Tutorials
Introduction
Getting Started
Making Programmer and Development Board
Making Hello World Project
Digital Input/Output in AVRs
Interfacing Seven Segment Displays
Controlling DC Motors
Working with LCD Modules
Using Internal Peripherals
Analog To Digital Convertor
Introduction To AVR Timers
Timers in Compare Mode
Multiplexed Seven Segment Displays
Interfacing Temperature Sensor LM35
RS232 Communication Basics
RS232 Level Convertor
Using AVR USART
Serial I/O
More ...
Products
Low Cost AVR Dev Board
Microchip PIC Dev Board
xBoard MINI v2.0 (ATmega8)
xBoard v2.0 (ATmega16)
USB AVR Programmer
USB PIC Programmer
USB 8051 Programmer
More ...
Online Store
Forum
Links
Contact Us
Enquiry Form
Payment and Shipping
Motor Controller Tutorial

Free Web Tutorials from Galil, the World Leader in Motor Controllers. www.GaliLmc.com

Power Electronics Customize Your Crane! Soft Start / VFD For Crane Control www.ipandc.com
Optimize Machine Control Unbiased help for getting higher performance from your machines. ControlDesign.com

Jul-19th-2008

DC Motor Control
0

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

2 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Motor gives power to your MCU. Ya power to do physical works, for example move your robot. So it is essential to know
how to control a DC motor effectively with a MCU. We can control a DC motor easily with microcontrollers. We can start it,
stop it or make it go either in clockwise or anti clock wise direction. We can also control its speed but it will be covered in
latter tutorials.

Fig: A DC Motor

DC Motor (Intermediate and Advance users can skip this)


A DC motor is electromechanical device that converts electrical energy into mechanical energy that can be used to do many
useful works. It can produce mechanical movement like moving the tray of CD/DVD drive in and out (you may like to try it
out Go to My Computer, right click the drive icon and click "Eject"). This shows how software controls a motor. DC motors
comes in various ratings like 6V and 12V. It has two wires or pins. When connected with power supply the shaft rotates. You
can reverse the direction of rotation by reversing the polarity of input.

Control with MCUs


As the MCUs PORT are not powerful enough to drive DC motors directly so we need some kind of drivers. A very easy and
safe is to use popular L293D chips. It is a 16 PIN chip. The pin configuration is as follows.

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

3 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

L293D Dual DC Motor Controller.


This chip is designed to control 2 DC motors. There are 2 INPUT and 2 OUTPUT PINs for each motors. The connections is
as follows.
The behavior of motor for various input conditions are as follows
A

Stop

Low

Low

Clockwise

Low

High

Anticlockwise

High

Low

Stop

High

High

So you saw you just need to set appropriate levels at two PINs of the microcontroller to control the motor. Since this chip
controls two DC motors there are two more output pins (output3 and output4) and two more input pins(input3 and input4).
The INPUT3 and INPUT4 controls second motor in the same way as listed above for input A and B. There are also two
ENABLE pins they must be high(+5v) for operation, if they are pulled low(GND) motors will stop.The following program
starts the motor runs it one direction for some time and then reverses the direction.

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

4 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

#include <avr/io.h>
#include <util/delay.h>
void Wait()
{
char i;
for (i=0;i<100;i++)
_delay_loop_2(0);
}
void main()
{
//Setup port D pin 4,5 as output.
DDRD=(1<<PD4)|(1<<PD5);
while(1)
{
//Clock wise
PORTD=0B00010000;
Wait();
//Anti clock wise
PORTD=0B00100000;
Wait();
//Stop
PORTD=0;
Wait();
}
}

Assembling.
Insert the L293D chip into the breadboard. And connect as per the circuit
diagram. Now connect the DC motor. Then connect the 9V supply to the
Items Required.
breadboard this supply is used to run he motor. Also connect the 5V supply to
the breadboard this is the logical supply i.e. it defines a HIGH or 1 is 5V.
This 5V is available in the xBoard itself. Use a 2pin connector to access this. DC Motor 12V
Then connect the PD4 and PD5 pins of the MCU to the breadboard. These
will provide signals to control the motor. Use a 8 PIN connecter to get PD4
and PD5. Connect PD4 to A and PD5 to B Now burn the program into the L293D chip
MCU and power on the system. The motor will rotate and will change
directions after some times.
Breadboard.

Some wires

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

5 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Fig: L293D chip on breadboard.

Fig: A motor Connected to l293d chip.

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

6 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Fig: PD4,PD5,+5V and GND terminals on xBoard-MINI

Speed Control
The speed of DC motor can also be controlled with MCU. PWM or pulse width modulation technique is used to digitally
control speed of DC motors. I will show you how that is done in later tutorials after I introduce you with internal TIMERS of
AVR because PWM is generated using timers.
Download PDF version | Get Adobe Reader Free !!!
What's Next
Next I will show you how to interface a 16x2 character LCD Modules.

15
Share
vote now

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

7 of 12

www.globalsources.com/mag/free/

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Ads by Google

This entry was posted on Saturday, July 19th, 2008 at 11:34 am and is filed under AVR Tutorials. You can follow any responses to this entry through the
RSS 2.0 feed. You can leave a response, or trackback from your own site.

11 Responses to DC Motor Control


1. 1
Prafull Says:
Hello Sir,
I have heard of Stepper motors -they are specially used for such control- and also heard that DC motors do not give a
good response.Is it true?
March 13th, 2009 at 7:46 pm

2. 2
Varun Says:
hey..i wantd to know that if im gona use PWM to control the speed of the motor.how do interface the PWM o/p pin
of the microcontroller to the motor driver IC..
June 15th, 2009 at 4:09 pm

3. 3
Avinash Says:
Hello Varun,
Connect PWM o/p to ENABLE PIN (PIN1).
See PWM tutorial here
http://extremeelectronics.co.in/avr-tutorials/pwm-signal-generation-by-using-avr-timers-part-ii/
June 15th, 2009 at 5:01 pm

4. 4
Ashok Says:
Hi Avinash,
thanks for the Avr tutorial. im trying out this interfacing of dc motor circuit but there is no current flowing inside the
circuit kindly help me
December 24th, 2009 at 12:11 pm

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

8 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

5. 5
Stephen Says:
If you have questions about what kind of motor to choose for your DIY project here is a summary presentation of
different types of motors. You will see here how they work and in what kind of projects you can use them wisely:
http://www.microdiy.com/index.php?/tutorials/motor-tutorial-for-diy-electronics-project.html
March 17th, 2010 at 11:39 pm

6. 6
lokesh kumar k @ nitk Says:
@AVINASH
NICE WORK !!!
July 16th, 2010 at 1:50 pm

7. 7
Letters First Test Setup of OpenThermo Project Says:
[...] I discovered that, again, there are some wonderful ICs to do the job for me; in this case, the L293D motor
controller chip apparently handles an isolated power source and high-power load while accepting low-voltage logic [...]
July 16th, 2010 at 5:01 pm

8. 8
Akhil Says:
Battery symbol should be inverted in Fig: Motor Controller Using L293d chip
August 11th, 2010 at 8:16 am

9. 9
Ravi Ranjan Says:
Hello Avinash Sir,
I want to ask one simple question
Why cannt we use ULN2803 in place of L293D to drive DC motor??ULN 2803 has also current specification of
600mApmsIs anything special in L293D?
Plz do reply.
Thanks
December 28th, 2010 at 8:13 pm

10. 10
Avinash Says:
@Ravi
ULN2803 is darlinton array while L293 is a push pull driver. ULN can only sink current cannot source it, so it
cannot be used in bi-directional control of motor. By the way this site is for engineers not KG students
December 29th, 2010 at 9:20 am

11. 11
Ravi Ranjan Says:
Oh I see!!!!
But one becomes an engineer after passing through KG and
not directly by jumping the KG class..
December 31st, 2010 at 4:20 pm

Leave a Reply

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

9 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Name (required)
Mail (will not be published) (required)
Website

Notify me of followup comments via e-mail


Ads by Google
AC Motor Controller
Electric Motor
AVR Project
Micro Controller
Drive & Motor

New Products
Tags
Meta

New Products

Ads by Google
Motor PWM
Stepping Motor
PWM Controller
L298 Motor
Motor Circuit

Tags
internal peripherals microcontrollers avr programmer Multiplexing programming Timer0 remote control timer1 Seven Segment

ir isr xBoard atmega8 c ProGFX RFID usb pic programmer ks0108 PIC Development Board graphic lcd

Robotics pic tutorial pic programmer mcu interrupt pwm Timer ADC atmega16 mplab pic16f

pic16f877 pic18f hi-tech c pic18f4520 atmega32 rs232 USART lcd microchip

pic18f2550 pic18f4550 pic18 AVR pic


Meta
Log in
RSS
Comments RSS

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

10 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Wordpress
Valid XHTML
Recent Post
Comments
Video

Recent Post
Handling Text and Fonts in ProGFX
New Year 2011 Gifts!
My New Camera Tripod !
Introduction to PIC Interrupts and their Handling in C
MicroSD Module
Getting Started with Serial RFID Reader
Happy Diwali !
43 Matrix Keypad Interface AVR Tutorial
VS-2 Servo, Ultrasonic, RFID, Solarcells, Keypads, MicroSD All New Arrivals!
Interfacing Ultrasonic Rangefinder with AVR MCUs AVR Tutorial

Comments
Tilda Zumsteg: Have your thought of adding some social bookmark buttons to your web site web site? No...
Mathilde Roatch: The publish is in reality the great on this worthy subject. I match in together with...
jose albuja: hola les hago una pregunta quiero enviar comandos AT a un atmega32 por comunicacin...
Illuminator: Hi, Im new to programming MC. I need two PWM o/p, i.e one to enable 1 and another...
Chris: I apologize for my ignorance. I wasnt asking for an arithmetic lesson, just help with the C...
Phill: @Avinash, im not sure that that would work. If you divided by 1023, then the answer would be...
Binu: Hi avinash why cant you add 89S series microcontroller in this software. I have already posted...

Video

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

11 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

eXtreme Electronics

eXtremeElec
Handling Text and Fonts in ProGFX | eXtreme Electronics
http://bit.ly/dZsTG0
24 days ago reply

New Year 2011 Gifts! | eXtreme Electronics http://bit.ly/hPepIP


26 days ago reply

My New Camera Tripod ! | eXtreme Electronics http://bit.ly


/gSL0Lm
42 days ago reply

Introduction to PIC Interrupts and their Handling in C | eXtreme


Electronics http://bit.ly/hqNDi2
44 days ago reply

Join the conversation

Categories
AVR Development Board
AVR Projects
AVR Tutorials
Chitchat
Code Libraries
Code Snippets
electronics
Hardwares
Microchip PIC Tutorials
News
PIC Development Board
Programming in 'C'
RF
Robotics
Software
Tools

Navigation
Home
Forum
Shop
Links

Subscribe
Get New Articles Deliverd To Your Inbox!
Email address:

Delivered by FeedBurner

19/1/2011 8:12 AM

DC Motor Control | eXtreme Electronics

12 of 12

http://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

Comments
Tilda Zumsteg: Have your thought of adding some social bookmark buttons to your web site web site? No...
Mathilde Roatch: The publish is in reality the great on this worthy subject. I match in together with...
jose albuja: hola les hago una pregunta quiero enviar comandos AT a un atmega32 por comunicacin...
Illuminator: Hi, Im new to programming MC. I need two PWM o/p, i.e one to enable 1 and another...
Chris: I apologize for my ignorance. I wasnt asking for an arithmetic lesson, just help with the C...
Phill: @Avinash, im not sure that that would work. If you divided by 1023, then the answer would be...
Binu: Hi avinash why cant you add 89S series microcontroller in this software. I have already posted...
eXtreme Electronics 2008-2010 | See Our Privacy Policy

19/1/2011 8:12 AM

Das könnte Ihnen auch gefallen