loading

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

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.

<p>there fixed</p>
<p>Hey Robert the code that you have given i the instruction have some errors. pls rectify the errors and post it. Thank you.</p>
<p>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</p><p>int trig = 12;</p><p>int echo = 13; </p><p>int red = 2;</p><p>int blue = 4;</p><p>int green = 7;</p><p>int val=200;</p><p>int potpin = A0;</p><p>void setup() {</p><p>//pins for motor controller</p><p>pinMode(11, OUTPUT);</p><p>pinMode(10, OUTPUT);</p><p>pinMode(9, OUTPUT);</p><p>pinMode(6, OUTPUT);</p><p>pinMode(red,OUTPUT);</p><p>pinMode(blue,OUTPUT);</p><p>pinMode(green,OUTPUT);</p><p>//set trig as output and echo as input for ultrasonic sensor</p><p>pinMode(trig, OUTPUT);</p><p>pinMode(echo,INPUT);</p><p>}</p><p>void loop() {</p><p>val = analogRead(potpin);</p><p>val = map(val, 0, 1028, 0, 225);</p><p>digitalWrite(trig, LOW);</p><p>delayMicroseconds(2);</p><p>digitalWrite(trig, HIGH);</p><p>delayMicroseconds(5);</p><p>digitalWrite(trig, LOW);</p><p>int duration = pulseIn(echo, HIGH);</p><p>int distance = duration / 29 / 2;</p><p>if(distance &gt; 15){</p><p> digitalWrite(blue,0);</p><p> digitalWrite(red,1);</p><p> forward(50);</p><p>}else if(distance &lt; 15){</p><p> digitalWrite(red,0);</p><p> digitalWrite(blue,1);</p><p> backward(600);</p><p> digitalWrite(red,1);</p><p> digitalWrite(green,0);</p><p> left(700);</p><p> digitalWrite(green,1);</p><p>}</p><p>}</p><p>// function for driving straight</p><p>void forward(int delay_time){</p><p> analogWrite(11, val);</p><p> digitalWrite(10, LOW);</p><p> analogWrite(9, val);</p><p> digitalWrite(6, LOW);</p><p> delay(delay_time);</p><p>}</p><p>//function for reversing</p><p>void backward(int delay_time){</p><p> digitalWrite(11, LOW);</p><p> analogWrite(10, val);</p><p> digitalWrite(9, LOW);</p><p> analogWrite(6, val);</p><p> delay(delay_time);</p><p>}</p><p>//function for turning left</p><p>void left(int delay_time){</p><p> analogWrite(11, val);</p><p> digitalWrite(10, LOW);</p><p> digitalWrite(9, LOW);</p><p> analogWrite(6, val);</p><p> delay(delay_time);</p><p>}</p><p>//function for turning right</p><p>void right(int delay_time){</p><p> digitalWrite(11, LOW);</p><p> analogWrite(10, val);</p><p> analogWrite(9, val);</p><p> digitalWrite(6, LOW);</p><p> delay(delay_time);</p><p>}</p><p>//function for stopping motors</p><p>void motors_stop(int delay_time){</p><p> digitalWrite(11, LOW);</p><p> digitalWrite(10, LOW);</p><p> digitalWrite(9,LOW);</p><p> digitalWrite(6, LOW);</p><p> delay(delay_time);</p><p>}</p>
<p>this codes are having error can u have another codes</p>
<p>problem with the code :(</p><p>sketch_may08a.ino:5:16: error: expected unqualified-id before '&lt;' token</p><p>sketch_may08a.ino:10:8: error: expected constructor, destructor, or type conversion before '(' token</p><p>sketch_may08a.ino:11:8: error: expected constructor, destructor, or type conversion before '(' token</p><p>sketch_may08a.ino:12:8: error: expected constructor, destructor, or type conversion before '(' token</p>
<p>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.? <br> Any help would be greatly appreciated, thank you.</p>
<p>Try this from Sparkfun, the SN754410 Quad Half H-Bridge. https://www.sparkfun.com/products/315</p>
<p>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?</p>
<p>If you Google HC-SR04, you will find an ample list of retailers/supply - especially eBay</p>
<p>Great project! I have to ask if it is possible to use these sensors underwater? If you waterproof them of course.</p>
<p>we can use another type of distance sensor?or the same ...for example sharp distance sensor?/</p>
Cool. Why the pot?
<p>for the speed</p>
<p>Cool, got it! Thanks</p>
<p>read... the comments!</p>
15cm
Please tell me about the code change if I want to stop it, not to divert its path
<p>i don't wanna divert the path.. I just want to <strong>stop it when any obstacles detect.. So what should be changed in the code</strong>.. and</p><p><strong>what is the unit of distance in : }else if(distance &lt; 15){</strong></p>
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.
The pot is 5k<br>
When you say documents what do you mean ???
And also can you please tell the specifications of potentiometer?
Can you please tell me about the chasis kit? I am confused about which one I should buy?
<p>Can you please send me the document also. Thanks.</p>
The pot is a speed dial to control the speed
<p>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.</p>

About This Instructable

11,144views

165favorites

License:

Bio: Robots are better than People
More by Robert 7320:Arduino L293D Obstacle Avoiding Robot 4 Simple Servo Project with Arduino 5 Simple Button and Led Projects with Arduino 
Add instructable to: