Skip to content

Motor Control with Arduino and L293

October 28, 2009
by

So far we have been focusing on what we expect to be the most important components of our robot, but in order for things like RFID and navigation to play any kind of role, we have to make sure the basics are there, stuff that we took for granted and didn’t think twice about while writing the proposal. That is why today I researched and planned out the wiring scheme for the controls of our motors. We have decided to use the Arduino microcontroller for the purposes of testing and the preliminary stages of our project.

arduino+L293

Arduino Microcontroller and the L293D Chip

I paired the Arduino with the Texas Instruments chip equivalent of the popular L293D H-bridge chip. Here’s the pin layout of the L293.

L293D Schematic

L293D Schematic

And here’s the schematic for wiring two motors, the L293, and the Arduino.

L239Dschematic+2motors

Wiring Schematic

We are expecting on using a more powerful microcontroller than the Arduino as the main “brains” of the robots, but we can delegate the task of running the motors to the Arduino. Here’s the code I wrote for this task.

#define analogPinA 0
#define analogPinB 1
#define analogPinC 2
#define analogPinD 3

int enablePinA = 10;  //Motor A’s enable pin
int dPin_1A = 3;// Digital Pin to turn Motor A on/off
int dPin_2A = 2;

int enablePinB = 11;  //Motor B’s enable pin
int dPin_1B = 9;// Digital Pin to turn Motor B on/off
int dPin_2B = 8;

void setup()
{
pinMode(enablePinA, OUTPUT);
pinMode(dPin_1A, OUTPUT);
pinMode(dPin_2A, OUTPUT);

pinMode(enablePinB, OUTPUT);
pinMode(dPin_1B, OUTPUT);
pinMode(dPin_2B, OUTPUT);
}

void loop()
{
int analogValueA=analogRead(analogPinA);
int analogValueB=analogRead(analogPinB);
int analogValueC=analogRead(analogPinC);
int analogValueD=analogRead(analogPinD);

if(analogValueA>0  && analogValueC>0) //forward
{
digitalWrite(enablePinA, HIGH);
digitalWrite(dPin_1A, HIGH); //turn on the motor A
digitalWrite(dPin_2A, LOW);

digitalWrite(enablePinB, HIGH);
digitalWrite(dPin_1B, HIGH); //turn on the motor B
digitalWrite(dPin_2B, LOW);
}
else if(analogValueB>0  && analogValueD>0) //backward
{
digitalWrite(enablePinA, HIGH);
digitalWrite(dPin_1A, LOW); //turn on the motor A
digitalWrite(dPin_2A, HIGH);

digitalWrite(enablePinB, HIGH);
digitalWrite(dPin_1B, LOW); //turn on the motor B
digitalWrite(dPin_2B, HIGH);
}
else if(analogValueA>0 && analogValueD>0) //turn
{
digitalWrite(enablePinA, HIGH);
digitalWrite(dPin_1A, HIGH); //turn on the motor A
digitalWrite(dPin_2A, LOW);

digitalWrite(enablePinB, HIGH);
digitalWrite(dPin_1B, LOW); //turn on the motor B
digitalWrite(dPin_2B, HIGH);
}
else if(analogValueB>0 && analogValueC>0) //turn
{
digitalWrite(enablePinA, HIGH);
digitalWrite(dPin_1A, LOW); //turn on the motor A
digitalWrite(dPin_2A, HIGH);

digitalWrite(enablePinB, HIGH);
digitalWrite(dPin_1B, HIGH); //turn on the motor B
digitalWrite(dPin_2B, LOW);
}
}

No comments yet

Leave a comment

Design a site like this with WordPress.com
Get started