ROBOTICS:HOW TO MAKE OBSTACLE AVOIDANCE ROBOT?

Hello,In this post let us learn how to make Obstacle Avoidance Robot .

Components required:

ARDUINO UNO*1

DC 5V BO MOTORS*2

ULTRASONIC SENSOR*1

L293D MOTOR DRIVER *1

CHASSIS

JUMPER WIRES(FEW)

WHEELS

Circuit Diagram:

 

 

 

 

 

 

 

 

 

 

Code:

#define trigPin1 8  //ultrasonic pin trigger
#define echoPin1 9  //ultrasonic pin echo
long duration, distance;
void setup() {
// put your setup code here, to
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(4, OUTPUT);   //Motor output1
pinMode(5, OUTPUT);  //Motor output2
pinMode(6, OUTPUT);  //Motor output3
pinMode(7, OUTPUT);  //Motor output4
Serial.begin(9600);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
Serial.println(distance);
if(distance <10)       //If ultrasonic distance value less than 10
{
digitalWrite(4, LOW);      //Two Motor turns anticlockwise(Reverse)
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
delay(2000);
digitalWrite(4, HIGH);     //One Motor Clockwise and other anticlockwise(Right)
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
delay(2000);
}
else
{
digitalWrite(4, HIGH);       //Two Motor turns Clockwise(Forward)
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
}
}
void SonarSensor(int trigPin,int echoPin)   //Function to measure the distance
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}

Hope you found it useful.Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *