Obstacle Avoiding Robot using Arduino and Ultrasonic Sensor
- Arduino NANO or Uno 🛒
- HC-SR04 Ultrasonic Sensor 🛒
- LM298N Motor Driver Module 🛒
- 5V DC Motors 🛒
- Battery 🛒
- Wheels 🛒
- Chassis 🛒
- Jumper Wires 🛒
Circuit Diagram
Design of Obstacle Avoiding Robot using Arduino
How Ultrasonic Sensor are often used to Avoid Obstacles
Code:
/* Obstacle Avoiding Robot Using Ultrasonic Sensor and Arduino */
int trigPin = 9; // trig pin of HC-SR04
int echoPin = 10; // Echo pin of HC-SR04 int revleft4 = 4; //reverse motion of Left motor
int fwdleft5 = 5; //forward motion of Left motor
int revright6 = 6; //reverse motion of Right motor
int fwdright7 = 7; //forward motion of Right motor long duration, distance; void setup() {
delay(random(500,2000)); // delay for random time
Serial.begin(9600);
pinMode(revleft4, OUTPUT); // set Motor pins as output
pinMode(fwdleft5, OUTPUT);
pinMode(revright6, OUTPUT);
pinMode(fwdright7, OUTPUT);
pinMode(trigPin, OUTPUT); // set trig pin as output
pinMode(echoPin, INPUT); //set echo pin as input to capture reflected waves
} void loop() { digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // send waves for 10 us
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH); // receive reflected waves
distance = duration / 58.2; // convert to distance or length in appropriate unit distance
delay(10);
// If you don't get proper movements of your robot then change or alter the pin numbers
if (distance > 19)
{
digitalWrite(fwdright7, HIGH); // move forward
digitalWrite(revright6, LOW);
digitalWrite(fwdleft5, HIGH);
digitalWrite(revleft4, LOW);
} if (distance < 18)
{
digitalWrite(fwdright7, LOW); //Stop
digitalWrite(revright6, LOW);
digitalWrite(fwdleft5, LOW);
digitalWrite(revleft4, LOW);
delay(500);
digitalWrite(fwdright7, LOW); //move backward
digitalWrite(revright6, HIGH);
digitalWrite(fwdleft5, LOW);
digitalWrite(revleft4, HIGH);
delay(500);
digitalWrite(fwdright7, LOW); //Stop
digitalWrite(revright6, LOW);
digitalWrite(fwdleft5, LOW);
digitalWrite(revleft4, LOW);
delay(100);
digitalWrite(fwdright7, HIGH);
digitalWrite(revright6, LOW);
digitalWrite(revleft4, LOW);
digitalWrite(fwdleft5, LOW);
delay(500);
} } //code END Hope you would have liked this Project!!
Applications:
- Obstacle avoiding robots are often utilized in most mobile robot navigation systems.
- They can be used for household work like automatic vacuum cleaning and many other.
- They can even be utilized in dangerous environments, where human penetration might be fatal.
Hope you would have liked this Project!!
Comments
Post a Comment
If you have any doubts ,Please let me know.