3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Ard-e: The robot with an Arduino as a brain

Step 4Ard-e on Auto: Using the Ardunio to drive the DC motors

Ard-e on Auto: Using the Ardunio to drive the DC motors
«
  • L293.jpg
  • L293hookup.gif
  • DSCF2073.JPG
  • DSCF2074.JPG
So if you wanted to use the Arduino to control the motors you cant just hook them up to one of the output pins because the Arduino wont supply enough current to drive them. To use it to drive them you need to buy a motor driving chip or a motor shield for the arduino. http://www.ladyada.net/make/mshield/ has one for $20 or you can just buy the chips that she uses from digikey http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=296-9518-5-ND . The chip that is commonly used is a L293 or other similar H bridge motor driver chip. This site has the pinout of it and some details about running a program on it http://www.me.umn.edu/courses/me2011/robot/technotes/L293/L293.html

The chip basically takes three inputs, one PWM input that sets the speed of the motor and turns it on and off and two inputs that determine the direction that the motor spins. The PWM pin is the Enable of the L293, the two pins that determine the direction of the motor spins are the Inputs 1A and 2A. The motors are connected to the outputs 1Y and 2Y. The L293 can control two DC motors so once you get it hooked up to the Arduino Ard-e can drive himself.
The data-sheet for the L293 can be found at http://www.datasheetcatalog.com/datasheets_pdf/L/2/9/3/L293.shtml

I ended up ordering two of the L293 chips from www.mouser.com and they cost me about $7. After a few hours of trial and error I finally got the Arduino to drive both of Ard-e's motors. I didn't read the data-sheet carefully enough because I originally was using 3V to try and run the L293 when it obviously (now at least its obvious) needs at least five volts. So after numerous trips to www.Arduino.cc here is the code I used to test drive Ard-e's motors:

int diraPin = 10;
int dirbPin = 9; //These two have to be opposite digital values to spin the motor if they are both HIGH or both LOW then the motor is actually braked.
int enablePin = 11; //This pin sets the speed of the motor and needs to be a PWM pin.
int dira2Pin = 2;
int dirb2Pin = 3;
int enable2Pin = 5; // These are used in the same way to drive the second motor.
int val = 0; // Variable used to set the speed of the motors.

void setup() {
pinMode(diraPin, OUTPUT);
pinMode(dirbPin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(dira2Pin, OUTPUT);
pinMode(dirb2Pin, OUTPUT);
pinMode(enable2Pin, OUTPUT); // Declares all of the pins as outputs.
}

void loop() {
val = 175; //A value used for setting the speed of the motor, about 70% of its speed.

//Spin motor 1 backward for one second
analogWrite(enablePin, val); // Set the speed of the motors with PWM
digitalWrite(diraPin, LOW);
digitalWrite(dirbPin, HIGH);

//spin motor 2 backward for one second
analogWrite(enable2Pin, val);
digitalWrite(dira2Pin, LOW);
digitalWrite(dirb2Pin, HIGH);
delay(1000); // If you switch which direction pin is high and which is low the motor will spin a different direction.

//spin motor 1 forward for one second
digitalWrite(diraPin, HIGH);
digitalWrite(dirbPin, LOW);

//spin motor 2 forward for one second
digitalWrite(dira2Pin, HIGH);
digitalWrite(dirb2Pin, LOW);
delay(1000);

// stop for a second
val=0;
analogWrite(enablePin, val);
analogWrite(enable2Pin, val);
delay(1000);
}

So to test this out on Ard-e I ended up putting a breadboard onto the addition that had previously held the pan and tilt system. I also moved the Arduino right next to the breadboard for easy prototyping. I also had to add another two AA batteries so the the L293 would have the 6V it needs to power the motors.

Heres a quick video of Ard-e running this program. One of the motors spins faster than the other so he veers towards the camera near the end of it. I don't really know why this happens...


So once you write all of the code and rearrange the components to make the Arduino boss around the L293 and get those pesky DC motors under control Ard-e's possible uses increase dramatically. All you need now are some sensors.
« Previous StepDownload PDFView All StepsNext Step »
5 comments
Nov 26, 2011. 5:01 AMfmbfla says:
"One of the motors spins faster than the other so he veers towards the camera near the end of it. I don't really know why this happens".
Would this be caused by the first motor (#1) in line with the + would cause a voltage drop to motor (# 2)?. Would placing a resistor in line with M#1 control the voltage better?
Another possible work around for this is to use the chip to control the ground circuit from the motor.


Just a thought, as most DC motors in automotive interiors use "Hot" motors and use the PCM directly or the PCM controls micro relays to control the ground to operate.

NooB.
Dec 7, 2010. 8:46 PMlcona89 says:
In the code are those declarations in the begging pin numbers?
Jun 26, 2010. 2:56 PMcdousley says:
Could i just use relays to make it drive the motors? I'm new with arduino and robots
May 19, 2010. 1:10 PMD5quar3 says:
 why are there pins coming out of the bottom of the schematic sorry im pretty new to this.
Jun 17, 2010. 9:40 AMChowmix12 says:
the pins come out the bottom to make a simple design on the schematic. When actually building this, you should use the data sheet or any other reference to match the pin numbers on the schematic.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
18
Followers
3
Author:imadami