Introduction: Setting Up Fixed Distance by Board L293D for Arduino

Picture of Setting Up Fixed Distance by Board L293D for Arduino

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 www.ICStation.com. 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.

#include
int inputPin=13;

int outputPin=2;

AF_DCMotor motor1(1, MOTOR12_64KHZ);

AF_DCMotor motor2(2, MOTOR12_64KHZ);

void setup()
{

Serial.begin(9600);

pinMode(inputPin, INPUT);

pinMode(outputPin, OUTPUT);

motor1.setSpeed(150);

motor2.setSpeed(180);

Serial.println("Motor test!");

}

void loop()
{

digitalWrite(outputPin, LOW);

delayMicroseconds(2);

digitalWrite(outputPin, HIGH);

delayMicroseconds(10);

digitalWrite(outputPin, LOW);

int distance = pulseIn(inputPin, HIGH);

distance= distance/58;

Serial.println(distance);

delay(50);

if (distance = 50)

{

Serial.print("tack");

motor1.run(RELEASE);

motor2.run(RELEASE);

}

if (distance < 120 )

{

Serial.print("tick");

motor1.run(FORWARD);

motor2.run(FORWARD);

}

if (distance > 50)

{

Serial.print("tock");

motor1.run(BACKWARD);

motor2.run(BACKWARD);

}

}

Comments

About This Instructable

137views

0favorites

License:

Bio: www.ICStation.com is a top store of electronic, which specializes in all kinds of IC products, such IC accessories, Module, Robots, Development Board, Transistor ... More »
More by ICStation:DIY 3D Christmas Tree Kit With RGB Flashing LEDsBuild a Colorful LED Tower Display Rhythm Lamp Light DIY KitsDIY Energy Saving LED Lamp Kit Installation
Add instructable to: