Introduction: Setting Up Fixed Distance by Board L293D for Arduino

About: is a top store of electronic, which specializes in all kinds of IC products, such IC accessories, Module, Robots, Development Board, Transistor, Capacitor and so on. We're located in Shenz…

Setting up fixed distance between Smart car and things by Motor Drive Shield Expansion Board L293D For Arduino

This tutorial will give code to show how to set up a fixed distance between a smart robot car and subjects by L293D board from We have that Motor drive shield and Many people think that COM port of Board L293D has been taken, actually not. You can find there is no wire connected with those pins, and we can use them a lot. PWM port(pin 10 and pin 9) can be connected with steering engine and else. Pin0,1,2 and pin 13 need to be soldered by electric iron.Pin0 is PX, pin1 is TX, and when connected with bluetooth or port WIFI module, L293D can be wireless control.

As port 2 and 13 is available, we can connect them with Ultrasonic Module for distance.

int inputPin=13;

int outputPin=2;

AF_DCMotor motor1(1, MOTOR12_64KHZ);

AF_DCMotor motor2(2, MOTOR12_64KHZ);

void setup()


pinMode(inputPin, INPUT);

pinMode(outputPin, OUTPUT);



Serial.println("Motor test!");


void loop()

digitalWrite(outputPin, LOW);


digitalWrite(outputPin, HIGH);


digitalWrite(outputPin, LOW);

int distance = pulseIn(inputPin, HIGH);

distance= distance/58;



if (distance = 50)




if (distance < 120 )




if (distance > 50)