Arduino Based Obstacle Avoiding Robot
by sreyamohan in Circuits > Arduino
20 Views, 0 Favorites, 0 Comments
Arduino Based Obstacle Avoiding Robot
Robotics is one of the fastest-growing fields in technology, combining electronics, programming, and mechanical design. In this project, we are designing and building an Arduino Based Obstacle Avoiding Robot that can move autonomously and avoid obstacles without human control.
The robot uses an ultrasonic sensor to detect objects in its path. When an obstacle is detected, the Arduino processes the sensor data and controls the motors through an L298N motor driver to change the direction of the robot. A servo motor is used to rotate the ultrasonic sensor and scan the surroundings for a clear path.
This project demonstrates the basic concepts of autonomous navigation, sensor interfacing, and motor control using Arduino.
Supplies
- Arduino UNO Board – 1Acts as the main controller of the robot.
- HC-SR04 Ultrasonic Sensor – 1
- Used to detect obstacles and measure distance.
- L298N Motor Driver Module – 1
- Controls the speed and direction of DC motors.
- SG90 Servo Motor – 1
- Rotates the ultrasonic sensor to scan left and right directions.
- DC Gear Motors – 2 or 4
- Provides movement to the robot.
- 12V Rechargeable Battery – 1
- Provides power to the robot.
- Power Switch – 1
- Used to turn the robot ON/OFF.
- Jumper Wires (Male-Male, Male-Female) – As required
- Used for connecting components.
- Breadboard (Optional) – 1
- For temporary circuit connections.
- Resistors (Optional)
- For additional circuit protection.
Mechanical Parts
- Robot Chassis – 1
- Base frame for mounting components.
- Robot Wheels – 2 or 4
- Provides movement.
- Motor Mounting Brackets – As required
- Holds motors firmly.
- Caster Wheel (Optional) – 1
- Provides balance and smooth movement.
- Screws and Nuts – As required
- Used for mechanical assembly.
Tools Required
- Soldering Iron and Solder Wire (Optional)
- For permanent connections.
- Wire Cutter/StripperFor preparing wires.
- Screwdriver SetFor assembling the chassis.
- USB Cable for ArduinoFor uploading the program.
- Computer/Laptop with Arduino IDEFor programming the Arduino.
OBJECTIEVES
1.To design an autonomous obstacle avoiding robot.
2.To interface ultrasonic sensors with Arduino.
3.To control DC motors using an L298N motor driver.
4.To implement automatic decision-making based on sensor input.
5.To understand basic robotics and embedded systems.
WORKING PRINCIPLE
The robot works based on ultrasonic distance measurement.
The HC-SR04 ultrasonic sensor sends ultrasonic waves and receives the reflected signal from an obstacle. Arduino calculates the distance using the time taken by the signal to return.
The working process is:
- The robot starts moving forward.
- The ultrasonic sensor continuously checks the distance.
- If no obstacle is detected, the robot continues moving.
- When an obstacle comes within the set distance:
- The robot stops.
- The servo motor rotates the ultrasonic sensor.
- The sensor checks the left and right sides.
- Arduino compares both distances.
- The robot turns towards the side with more free space.
- The robot continues moving.
MECHANICAL ASSEMBLY
1.Assemble the robot chassis.
2.Attach the DC motors to the chassis.
3.Fix wheels to the motor shafts.
4.Mount Arduino UNO and L298N motor driver.
5.Attach the servo motor at the front side.
6.Fix the ultrasonic sensor on the servo.
7.Connect all components using jumper wires.
8.Place the battery securely.
CODE
#include <Servo.h>
#define TRIG 9
#define ECHO 10
#define ENA 5
#define IN1 8
#define IN2 7
#define ENB 6
#define IN3 4
#define IN4 3
#define SERVO_PIN 11
Servo myServo;
long duration;
int distance;
int leftDistance;
int rightDistance;
void setup() {
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
analogWrite(ENA, 180);
analogWrite(ENB, 180);
myServo.attach(SERVO_PIN);
myServo.write(90); // Center position
Serial.begin(9600);
}
void loop() {
myServo.write(90);
delay(300);
distance = getDistance();
Serial.print("Front: ");
Serial.println(distance);
if (distance > 20) {
forward();
}
else {
stopRobot();
delay(300);
backward();
delay(300);
stopRobot();
// Scan Left
myServo.write(150);
delay(500);
leftDistance = getDistance();
Serial.print("Left: ");
Serial.println(leftDistance);
// Scan Right
myServo.write(30);
delay(500);
rightDistance = getDistance();
Serial.print("Right: ");
Serial.println(rightDistance);
// Return Center
myServo.write(90);
delay(300);
if (leftDistance > rightDistance) {
turnRight();
delay(430);
} else {
turnLeft();
delay(430);
}
stopRobot();
delay(200);
}
}
int getDistance() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
duration = pulseIn(ECHO, HIGH, 30000);
if (duration == 0)
return 999;
return duration * 0.0343 / 2;
}
void forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void backward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void stopRobot() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
TESTING
- Power the robot using a 12V battery.
- Place it on a flat surface.
- Check forward movement.
- Place an obstacle in front of the robot.
- Observe the robot stopping and changing direction.
- Adjust motor speed and sensor distance if required.
APPLICATIONS
1.Autonomous vehicles
2.Robotics education
3.Smart transportation systems
4.Surveillance robots
5.Industrial automation prototypes
FUTURE SCOPS
1.Add Bluetooth/WiFi control
2.Add camera-based navigation
3.Implement AI object detection
4.Add IoT-based monitoring
5.Improve navigation accuracy using multiple sensors
CONCLUSION
The Arduino Based Obstacle Avoiding Robot is a simple autonomous robotic system that demonstrates the integration of sensors, microcontrollers, and motor control. This project helps in understanding the fundamentals of robotics and provides a base for developing more advanced autonomous systems.