I spent one whole day trying to learn how to interface an L293D motor driver chip with the Arduino and control a DC motor. I did get it working in the end though. It might be a bit tricky for starters like me to do this, so I would like to share how I did it and here's the link to my blog entry on this: http://akashxav.com/2009/04/18/arduino-l293d-dc-motor/ with code, circuit diagram, videos and pics.
Components you'll need:
Arduino, DC Motor, L293D chip, an external power source for the DC motor, an LED (optional)
The L293D's datasheet can be googled and might come in handy
Thanks to Vladmir for valuable help.
P.S: When you feel everything is right but the circuit is still not working, just tighten the motor driver chip on the breadboard. Coz I spent half-a-day not knowing of this problem.
Apparently I don't know how that i- thing worked without errors. I know that 'i-' is valid in C. But shouldn't it work different from i--? I'll try running the program with i-- and see the difference
I checked my post when I edited it. I had typed-in "i--" but Wordpress seems to have converted it to a different character (to the longer dash). Just a Wordpress thing. I corrected it.
I just used the HTML code for - instead of using it directly. I was using the HTML editor not the visual one
The motor should be across pins 3 and 6 of the L293D
You should be applying a PWM signal to either pin 2 or pin 7 of the L293D, and holding the other pin LOW,
So, if PWM is to pin 2, then pin 7 should be LOW and vice versa.
well, Ya I just checked with the datasheet. PIN 6 and 7 have been exchanged.
But I was told in a previous thread that PWM is to be applied to Pin-1. It applies to the motor connected to half the chip. There's an enable pin for another motor.
I applied PWM to pin-1 and it worked fine. the video
Apparently you can pwm by applying a pwm signal either to the enable pin or as mentioned by AWOL, to either pin 2 or 7.
Anyhow, I'm trying to use AWOL's approach but am having problems with bi-directional control. I can get the motor running in the proper direction by setting the direction pin (pin 2) to LOW and pwm'ing the other (pin 7). But to set the opposite direction, I set the direction pin to HIGH and invert the pwm. In this case I get no motor rotation.
Any ideas? Maybe I need to try another IC in case I damaged it somehow?
I wrote this a while ago, to provide a simple bi-directional motor speed control with an L293D and a simple pot.
There's a dead zone in the centre of the pot's travel where the power is completely off.
It has some scary stuff in there, mucking around with the timers and such, but it gives you much more control with your PWM. It is not commented well, so to try to get to grips with it you really need to take a look at the ATMEL datasheet (start around p. 136):
I've read a lot of stuff about the best way to control a DC motor with Arduino.
Finally I decided to put the things together using a external power supply and it worked. BUT... something (wrong, strange or ok) happens.
I've connected Arduino to USB. The Arduino 5V goes to L293D 5+VCC (IC PIN 16). And the external power source goes to IC PIN 8.
When everything is power-up, it works OK. But if I power off ONLY the external supply, the motor keeps moving (slower than before).
Is it OK? When there is no external power supply the IC uses the logic supply?
Or may I have a bad-connection somewhere?
I'm not able to test your situation in my current setup easily but it sure sounds suspicious. You might try another IC.
Personally, I've had a lot of troubles with the L293D and have gone thru maybe 8 of these things. I think I'm operating close to the power dissipation limits of the device (33v, I'm not sure how much current I'm drawing).
Thus, I've moved on to the more robust L298 and have had much better results. It operates pretty much identically to the L293D, though you need to add your own protection diodes.