Introduction: Arduino L293D Obstacle Avoiding Robot

Picture of Arduino L293D Obstacle Avoiding Robot

What you need to make it is.

1. Arduino uno.

2. Chassis kit of some sort.

3. L293D Motor driving chip.

4. power supple i used 0.5 mah li-po battery at 7.4v

5. lots of wires

6. ultra sonic distance sensor

7. potentiometer

when you put the code in the robot it will go forward, when the ultra sonic sensor senses something it will reverse and turn left.

Step 1: Wiring

Picture of Wiring

i made this robot with a thin peace of wood 11cm x 11cm

Step 2: Code

int pwm_speed
//trig of ultrasonic sensor
int trig = 12;
//echo of ultrasonic sensor
int echo = 13; 
//int red = 2;
//int blue = 4;
//int green = 7;
int potpin = A0;
void setup() {
//pins for motor controller
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);//pinMode(red,OUTPUT);
//pinMode(blue,OUTPUT);
//pinMode(green,OUTPUT);//set trig as output and echo as input for ultrasonic sensor
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
}void loop() {
pwm_speed = analogRead(potpin);
pwm_speed = map(pwm_speed, 0, 1028, 0, 225);scan();int duration = pulseIn(echo, HIGH);
int distance = duration / 29 / 2;if(distance > 15){
   forward(100);
}else if(distance < 15){
  backward(700);
  left(500);
}}// function for driving straight
void forward(int delay_time){
  analogWrite(11, pwm_speed);
  analogWrite(10, 0);
  
  analogWrite(9, 0);
  analogWrite(6, pwm_speed);
  delay(delay_time);
}//function for reversing
void backward(int delay_time){
  analogWrite(11, 0);
  analogWrite(10, pwm_speed);
  
  analogWrite(9, pwm_speed);
  analogWrite(6, 0);
  delay(delay_time);
}//function for turning left
void left(int delay_time){
  analogWrite(11, 0);
  analogWrite(10, pwm_speed);
  
  analogWrite(9, 0);
  analogWrite(6, pwm_speed);
  delay(delay_time);
}//function for turning right
void right(int delay_time){
  analogWrite(11, pwm_speed);
  analogWrite(10, 0);
  
  analogWrite(9, pwm_speed);
  analogWrite(6, 0);
  delay(delay_time);
}//function for stopping motors
void motors_stop(int delay_time){
  
  analogWrite(11, 0);
  analogWrite(10, 0);
  
  analogWrite(9, 0);
  analogWrite(6, 0);
  delay(delay_time);
}
void scan(){
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);
}</p>

Step 3: Touble Shooting

If the robot goes the wrong way swap the motor wires around.

Comments

Robert 7320 (author)2016-12-29

there fixed

pravi1 (author)2016-12-28

Hey Robert the code that you have given i the instruction have some errors. pls rectify the errors and post it. Thank you.

Robert 7320 (author)2016-05-27

if you use this code it should work but you'll need to change the motor driver wires to pin 6 int 1 pin 9 int 2 pin 10 int 3 pin 11 int 4 int on the motor driver board and you can use a RGB led with this code and the pot for speed is A0 so the same

int trig = 12;

int echo = 13;

int red = 2;

int blue = 4;

int green = 7;

int val=200;

int potpin = A0;

void setup() {

//pins for motor controller

pinMode(11, OUTPUT);

pinMode(10, OUTPUT);

pinMode(9, OUTPUT);

pinMode(6, OUTPUT);

pinMode(red,OUTPUT);

pinMode(blue,OUTPUT);

pinMode(green,OUTPUT);

//set trig as output and echo as input for ultrasonic sensor

pinMode(trig, OUTPUT);

pinMode(echo,INPUT);

}

void loop() {

val = analogRead(potpin);

val = map(val, 0, 1028, 0, 225);

digitalWrite(trig, LOW);

delayMicroseconds(2);

digitalWrite(trig, HIGH);

delayMicroseconds(5);

digitalWrite(trig, LOW);

int duration = pulseIn(echo, HIGH);

int distance = duration / 29 / 2;

if(distance > 15){

digitalWrite(blue,0);

digitalWrite(red,1);

forward(50);

}else if(distance < 15){

digitalWrite(red,0);

digitalWrite(blue,1);

backward(600);

digitalWrite(red,1);

digitalWrite(green,0);

left(700);

digitalWrite(green,1);

}

}

// function for driving straight

void forward(int delay_time){

analogWrite(11, val);

digitalWrite(10, LOW);

analogWrite(9, val);

digitalWrite(6, LOW);

delay(delay_time);

}

//function for reversing

void backward(int delay_time){

digitalWrite(11, LOW);

analogWrite(10, val);

digitalWrite(9, LOW);

analogWrite(6, val);

delay(delay_time);

}

//function for turning left

void left(int delay_time){

analogWrite(11, val);

digitalWrite(10, LOW);

digitalWrite(9, LOW);

analogWrite(6, val);

delay(delay_time);

}

//function for turning right

void right(int delay_time){

digitalWrite(11, LOW);

analogWrite(10, val);

analogWrite(9, val);

digitalWrite(6, LOW);

delay(delay_time);

}

//function for stopping motors

void motors_stop(int delay_time){

digitalWrite(11, LOW);

digitalWrite(10, LOW);

digitalWrite(9,LOW);

digitalWrite(6, LOW);

delay(delay_time);

}

jimilnshah (author)2016-05-25

this codes are having error can u have another codes

maria_AI (author)2016-05-08

problem with the code :(

sketch_may08a.ino:5:16: error: expected unqualified-id before '<' token

sketch_may08a.ino:10:8: error: expected constructor, destructor, or type conversion before '(' token

sketch_may08a.ino:11:8: error: expected constructor, destructor, or type conversion before '(' token

sketch_may08a.ino:12:8: error: expected constructor, destructor, or type conversion before '(' token

hiponiaE (author)2016-03-12

Hello about the L293D motor IC what are the other replacement for it.? I mean, there is no available stock of the said IC and im going to use it im project arduino and bluetooth car. So, is there other value of IC as replacement for it.?
Any help would be greatly appreciated, thank you.

keithfiore (author)hiponiaE2016-04-29

Try this from Sparkfun, the SN754410 Quad Half H-Bridge. https://www.sparkfun.com/products/315

Alexkouvel (author)2016-02-01

We have a problem. We can't find the name of the supersonic sensor . Can you give us name or can we use another one?

keithfiore (author)Alexkouvel2016-04-29

If you Google HC-SR04, you will find an ample list of retailers/supply - especially eBay

Exop (author)2016-04-29

Great project! I have to ask if it is possible to use these sensors underwater? If you waterproof them of course.

alexkat (author)2016-02-01

we can use another type of distance sensor?or the same ...for example sharp distance sensor?/

stringstretcher (author)2016-01-22

Cool. Why the pot?

for the speed

Cool, got it! Thanks

DanForceDig (author)DanForceDig2016-01-23

read... the comments!

Robert 7320 (author)2016-01-25

15cm

AbD3 (author)Robert 73202016-01-25

Please tell me about the code change if I want to stop it, not to divert its path

AbD3 (author)2016-01-25

i don't wanna divert the path.. I just want to stop it when any obstacles detect.. So what should be changed in the code.. and

what is the unit of distance in : }else if(distance < 15){

Robert 7320 (author)2016-01-24

If you want a cheap chassis kit go on ebay and seach arduino smart car kit or you can make your own with cardboard ,wood or plastis.

Robert 7320 (author)2016-01-24

The pot is 5k

Robert 7320 (author)2016-01-24

When you say documents what do you mean ???

guptaratul (author)2016-01-24

And also can you please tell the specifications of potentiometer?

guptaratul (author)2016-01-24

Can you please tell me about the chasis kit? I am confused about which one I should buy?

philipduong218 (author)2016-01-23

Can you please send me the document also. Thanks.

Robert 7320 (author)2016-01-22

The pot is a speed dial to control the speed

nayem_sarker (author)2016-01-22

can you please send me all the document needed to build this obstacle avoiding robot. I will be very pleased if you please send me.

About This Instructable

13,046views

169favorites

License:

Bio: Robots are better than People
Add instructable to: