DIY Arduino Obstacle-Avoidance Robot Made
by 703826 in Circuits > Arduino
214 Views, 1 Favorites, 0 Comments
DIY Arduino Obstacle-Avoidance Robot Made
.jpg)
In this Intractable, I will guide you through the process of building a Arduino-based obstacle-avoidance robot. This robotic platform uses an Arduino Uno, an ultrasonic sensor, DC motors, and an L293d motor driver to navigate and avoid obstacles in its path.
Supplies




Materials:
- Arduino Uno
- Ultrasonic sensor
- 2 x DC motors
- L293d motor driver
- 9V battery
- Caster ball
- Motor wheels
(for the Multi vibrator)
- 2- LED's
- 2 - NPN
- 4 - 330 Resistors
- 2 - 10v 100nf capacitors
Fixing Motors and Motor Drivers to the Chassis (if Not Already )
.jpg)

- Fix the DC motors onto the chassis.
- Attach wheels to the shafts of the DC motors.
- Place the L293d motor driver on or below the chassis surface.
- Connect the motor driver: IN1 and IN2 to Arduino pins 4, 5, 2, and 3.
Fixing Ultrasonic Sensor

- Connect VCC of the ultrasonic sensor to 5V on the Arduino.
- Connect GND of the ultrasonic sensor to GND on the Arduino.
- Connect TRIG of the ultrasonic sensor to Digital pin 9 on the Arduino.
- Connect ECHO of the ultrasonic sensor to Digital pin 8 on the Arduino.
Step 4: Connecting Power Supply
.jpg)
- Use a 9V battery for power.
- Connect the positive terminal of the battery to the VIN pin on the Arduino.
- Connect the negative terminal of the battery to the GND pin on the Arduino.
Step 5: Programming the Arduino
Upload the following Arduino code to control the movement of the chassis:
#define echopin 8 // echo pin
#define trigpin 9 // Trigger pin
int maximumRange = 30;
long duration, distance;
void setup() {
Serial.begin (9600);
pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT );
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT); } void loop () {
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
duration=pulseIn (echopin,HIGH);
distance= duration/58.2;
delay (50);
Serial.println(distance);
}
if (distance >= 30 ){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay (200); }
else if (distance >=15 && distance <= 25) {
digitalWrite (2,HIGH);
digitalWrite (3,LOW);
digitalWrite (4,LOW);
digitalWrite (5,LOW);
delay (1000); }
else if (distance < 15){
digitalWrite (2, LOW);
digitalWrite (3, HIGH);
digitalWrite (4, LOW);
digitalWrite (5, HIGH);
delay (1000);
digitalWrite (2,LOW);
digitalWrite (3,LOW);
digitalWrite (4,HIGH);
digitalWrite (5,LOW);
delay (1000); }
}
Final Step
- Disconnect the Arduino from the computer.
- Connect the 9V battery to power the chassis.
- Observe the chassis' movement – it should move forward until it detects an obstacle within 10 cm.
Conclusion:
Congratulations! You've successfully built an Arduino-based obstacle-avoidance chassis. Feel free to customize the code and experiment with additional features. Enjoy your robotic creation!