Site icon Circuit Ideas for You

Arduino Based Obstacle Avoidance Robot Circuit

This project is for making a small robot car.

Robot can move and avoid obstacle on road.

It uses Arduino Uno, ultrasonic sensor HC-SR04, motor driver L293D and two DC motors.

This Arduino Based Obstacle Avoidance Robot Circuit is simple and good for beginners.

Robot check distance with ultrasonic sensor.

If obstacle is near then robot stops and changes direction.

Circuit Coding:

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);
}
}

Code Explanation:

Circuit Working:

Parts List:

ComponentQuantity
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.

Ultrasonic sensor HC-SR04 connect to Arduino pins.

Motor driver L293D run two DC motors.

Arduino alone cannot give enough current to motors.

9V battery gives power supply.

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

When power is ON, ultrasonic sensor keep measure distance.

If distance more than 20 cm then robot goes forward.

If distance less than 20 cm then robot stops and turn.

After a turn the robot goes forward again.

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:

This Arduino Based Obstacle Avoidance Robot Circuit make small robot car with Arduino.

Robot use ultrasonic sensor to see obstacle.

When obstacle come near the robot stops and turn.

When road is clear then robot go forward.

It is easy project for beginner to learn sensor, motor driver and coding.

More sensor or better code can make robot smarter.

References:

Obstacle Avoiding Robot using Arduino UNO and HC-SR04 Ultrasonic Sensor

Exit mobile version