Site icon Circuit Ideas for You

Arduino Based Obstacle Avoidance Robot Circuit

This project is for making a small robot car and this robot can move and avoid obstacle on road; also it uses Arduino Uno, ultrasonic sensor HC-SR04, motor driver L293D and two DC motors.

Furthermore, this Arduino Based Obstacle Avoidance Robot Circuit is simple and good for beginners and then robot check distance with ultrasonic sensor; if obstacle is near then robot stops and changes direction.

Arduino Code:

int trigPin = 9;
int echoPin = 10;
int motor1pin1 = 2;
int motor1pin2 = 3;
int motor2pin1 = 4;
int motor2pin2 = 5;
long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
if (distance > 20) {
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
} else {
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
delay(500);
}
}

Circuit Working:

Arduino Based Obstacle Avoidance Robot Circuit Diagram

Parts List:

ComponentsQuantity
Arduino UNO1
Ultrasonic Sensor HC-SR04 Module1
Motor Driver L293D1
BO Motor DC Gear Motor with wheels2
ON/OFF switch1
9V Battery1

Arduino Uno is main brain of this project and ultrasonic sensor HC-SR04 connect to Arduino pins.

Here, motor driver L293D run two DC motors, but Arduino alone cannot give enough current to motors, so a 9V battery gives power supply.

Also, ON OFF switch connect in battery positive line for easy control.

When power is ON, ultrasonic sensor keep measure distance and if distance is more than 20 cm then robot goes forward and if distance less than 20 cm then robot stops and turn.

Then after a turn the robot goes forward again and this simple logic help robot avoid obstacles.

Formulas:

The below mentioned formula is for Arduino Based Obstacle Avoidance Robot Circuit:

Ultrasonic sensor formula:

Distance = (Time x Speed of Sound) / 2

where,

So this formula gives one-way distance from sensor to obstacle.

How to Build:

To build a Arduino Based Obstacle Avoidance Robot Circuit follow the below mentioned steps for connections:

Conclusion:

To conclude, this Arduino Based Obstacle Avoidance Robot Circuit make small robot car with Arduino.

Robot use ultrasonic sensor to see obstacle, and when obstacle come near the robot stops and turn and when road is clear then robot go forward.

Moreover, it is easy project for beginner to learn sensor, motor driver and coding and even more sensor or better code can make robot smarter.

Exit mobile version