Arduino – Line following robot – part 4 (Motor driver)

Part 3: Motor driver board

We used 2 gear motors with rubber wheels. 14 cm Zip/cable ties were used (2 per each motor) to fix the motors to the base plate.

It has the following features:

VoltageDC 6v
Current (no load)120 mA
Reduction rate48:1
RPM (With tire)240
Tire Diameter66 mm
Car Speed (no load)48 m/min
Motor Weight50 g

The motor driver chip L293D (D=dual direction) was a very easy chip to implement. The enable pin is used as PWM to control the speed of DC motors. We thought of 2 speed levels controlled through a jumper. Perhaps one for slow testing mode, the other for game mode!

VDD is for 6V dedicated motor power supply.

Here’s the test code. Short the pin 13 to positive supply and then to negative supply and watch the motors turn either way.

//Using L293D Motor Driver IC
#define switchPin 13 // switch input. Connect this to gnd and vcc to change motor direction
#define motorPin1 6 // L293D Input 1
#define motorPin2 7 // L293D Input 2
#define speedPin 3 // L293D enable Pin 1

int Mspeed = 90; // a variable to hold the current speed value. 0 - 255. 90 = slow mode, 255=full speed mode

void setup() {
  //set switch pin as INPUT
  pinMode(switchPin, INPUT);

  // set remaining pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(speedPin, OUTPUT);

void loop() {
  analogWrite(speedPin, Mspeed); // write speed to Enable 1 pin
  if (digitalRead(switchPin)) { // If the switch is HIGH, rotate motor clockwise
    digitalWrite(motorPin1, LOW); // set Input 1 of the L293D low
    digitalWrite(motorPin2, HIGH); // set Input 2 of the L293D high
  else { // if the switch is LOW, rotate motor anti-clockwise
    digitalWrite(motorPin1, HIGH); // set Input 1 of the L293D low
    digitalWrite(motorPin2, LOW); // set Input 2 of the L293D high