Building a Robot Car

In this project, you'll build a robot car using two DC motors.
 
Parts needed:
  • Arduino
  • L293D H-Bridge driver chip
  • Two DC motors with wheels
  • Robot car chassis
  • 4 AA batteries
  • Wires
  • Breadboard
L293D H-Bridge Robot Chassis
1 Refer to the picture below to assemble the robot car chassis.

Important: DO NOT tighten the screws that attach the two motors too much, otherwise, the motor is squeezed too tight and will not turn.
Robot Chassis Build Instructions
2 Go through this tutorial first on how to control a DC motor using the L293D H-Bridge IC before you continue.
3 Make the following connections for two DC motors:
 
Arduino L293D Motor 1 & 2 6V Battery Description
11 1 Enable for motor 1
10 2 Input 1
9 7 Input 2
3 & 6 motor 1 wires Output 1 & 2
6 9 Enable for motor 2
5 10 Input 3
4 15 Input 4
11 & 14 motor 2 wires Output 3 & 4
GND 4 or 13 – negative Ground (negative)
5V 16 5V (positive) power
Vin 8 + positive 6V motor power
Two DC motor connections
4 Create a new BareMinimum program and type in this program.
int enable12Pin = 11;  // enable pin for motor 1
int in1Pin = 10;     // input 1
int in2Pin = 9;      // input 2
int enable34Pin = 6;  // enable pin for motor 2
int in3Pin = 5;     // input 3
int in4Pin = 4;      // input 4

void setup() {
   // controls for motor 1
   pinMode(enable12Pin, OUTPUT);
   pinMode(in1Pin, OUTPUT);
   pinMode(in2Pin, OUTPUT);
   // controls for motor 2
   pinMode(enable34Pin, OUTPUT);
   pinMode(in3Pin, OUTPUT);
   pinMode(in4Pin, OUTPUT);

   // go straight
   analogWrite(enable12Pin, 255);   // set maximum speed for motor 1
   analogWrite(enable34Pin, 255);   // set maximum speed for motor 2
   digitalWrite(in1Pin, HIGH);      // set direction of motor 1
   digitalWrite(in2Pin, LOW);       // the two inputs are always inverses of each other
   digitalWrite(in3Pin, HIGH);      // set direction of motor 2
   digitalWrite(in4Pin, LOW);       // the two inputs are always inverses of each other
   delay(2000);

   // turn
   digitalWrite(in1Pin, HIGH);      // set direction of motor 1
   digitalWrite(in2Pin, LOW);       // the two inputs are always inverses of each other
   digitalWrite(in3Pin, LOW);       // set direction of motor 2
   digitalWrite(in4Pin, HIGH);      // the two inputs are always inverses of each other
   delay(1000);

   // stop
   analogWrite(enable12Pin, 0);
   analogWrite(enable34Pin, 0);

}

void loop() {
}
5 Upload and run the program. The robot car should go straight , then turn, and then stop.