Obstacle Avoiding Bot Using Ultrasonic Sensor and Arduino

by alphaelectronz in Circuits > Arduino

6310 Views, 0 Favorites, 0 Comments

Obstacle Avoiding Bot Using Ultrasonic Sensor and Arduino

Obstacle avoiding bot using Ultrasonic sensor Arduino.jpg

In this tutorial we are going to make an obstacle Avoider Bot using Ultrasonic Sensor and Arduino Uno.

Components Required –

Arduino Uno – https://amzn.to/33U9phD

Ultrasonic sensor – https://amzn.to/2OULNoC

L298N Motor Driver – https://amzn.to/2qwAGZW

2x DC Motor – https://amzn.to/34SjU6i

Chassis – https://amzn.to/2s5c3Uh

Jumpers – https://amzn.to/33VssIn

OR

Buy it from Alpha Electronz - Instagram | Whatsapp | Facebook

Ultrasonic Sensor

Ultrasonic Sensor.jpg

An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves.To know more about Ultrasonic sensor Click here

L298N Motor Driver

L298N Motor Driver.jpg

L298N Motor Driver Module is responsible for providing the necessary drive current to the motors of the robotic car.

Circuit Diagram

obstacle avoiding robot circuit diagram.png

The connections of Motor Driver and ultrasonic sensor is given in the above circuit diagram.All the components are attached on the chassis.After all the placement your Bot should look something like this.

For further help on Placement and connecting Everything See the full tutorial Video at the end of the post.

Code

/* 
Obstacle Avoiding Bot using Ultrasonic Sensor and Arduino Uno.
Date - 6/12/2019
Website - <a href="http://alphaelectronz.com">http://alphaelectronz.com</a>
*/
int trigPin = 3;
int echoPin = 2;
int m1 = 5; 
int m2 = 4; 
int m3 = 7; 
int m4 = 6;
int s1 = 10;
int s2 = 11;
void setup() {
Serial.begin(9600);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
pinMode(m3, OUTPUT);
pinMode(m4, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
analogWrite(s1,170);
analogWrite(s2,170);
}
void loop() {
long duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance =(duration/2)/29.1;
Serial.print(distance);
Serial.println("CM");
delay(10);
if((distance<15))
{ 
digitalWrite(m1,LOW); 
digitalWrite(m2,LOW); 
digitalWrite(m3,LOW); //
digitalWrite(m4,LOW); 
delay(1000);
digitalWrite(m1,LOW); 
digitalWrite(m2,HIGH); 
digitalWrite(m3,LOW); //
digitalWrite(m4,HIGH);
delay(500);
digitalWrite(m1,HIGH); 
digitalWrite(m2,LOW); 
digitalWrite(m3,LOW); //
digitalWrite(m4,HIGH);
delay(700);
}
else if(distance>15) 
{
digitalWrite(m1,HIGH);
digitalWrite(m2,LOW);
digitalWrite(m3,HIGH); //HIGH
digitalWrite(m4,LOW); 
}
}

Conclusion and Output Video

How to make a DIY obstacle avoiding car at home #arduino #obstacle #ultrasonic #rover #diyproject

Note – Possible Errors due to which your bot is not working properly.

  • Check the voltages of both batteries.
  • Use 2 batteries for Motor Driver and 1 for powering Arduino.
  • Check all the connections once again

If you have any doubts or problems regarding the code and circuit. Feel free to ask in the comments section.Or contact us on Instagram | Whatsapp | Facebook