Introduction: DIY Arduino Obstacle-Avoidance Robot Made

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

Step 1: Fixing Motors and Motor Drivers to the Chassis (if Not Already )

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


Step 2: Fixing Ultrasonic Sensor

  1. Connect VCC of the ultrasonic sensor to 5V on the Arduino.
  2. Connect GND of the ultrasonic sensor to GND on the Arduino.
  3. Connect TRIG of the ultrasonic sensor to Digital pin 9 on the Arduino.
  4. Connect ECHO of the ultrasonic sensor to Digital pin 8 on the Arduino.


Step 3: Step 4: Connecting Power Supply


  1. Use a 9V battery for power.
  2. Connect the positive terminal of the battery to the VIN pin on the Arduino.
  3. Connect the negative terminal of the battery to the GND pin on the Arduino.


Step 4: 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); }

}

Step 5: Final Step



  1. Disconnect the Arduino from the computer.
  2. Connect the 9V battery to power the chassis.
  3. 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!