DIY

Auto with obstacle avoidance function

 Cars with obstacle avoidance function < img class = "aligncenter" alt = "Cars with obstacle avoidance function" src = "https://usamodelkina.ru/uploads/posts/2021-02/1613765997_bandicam-2021-02-19-23-18-22-769. jpg "/>  Cars with obstacle avoidance function  Cars with obstacle avoidance function In this article, the wizard will tell us how to build an obstacle avoidance robot. The robot is a small and simple two-wheeled vehicle that will move forward until it detects an obstacle in its path. Then he will stop, drive back a little, and then “look” left and right.
Then he will compare the distances available on both sides and turn in the direction where the available distance seems more preferable. Thus, he will be able to move in a space full of obstacles without colliding with them.
The robot uses the HC-SR04 ultrasonic sensor to determine the distance. This transducer sends out ultrasonic sound waves every 10 microseconds, and if there is any obstacle in front, the transducer receives a reflection of the signal.
Tools and materials: -Arduino UNO; -L293D expansion board; -Chassis (including motors and wheels); – Connecting wires; -Battery holder; -SG90 servo motor; -Ultrasonic sensor HC-SR04; -Soldering iron; -Glue gun;
-Nippers;
-Screwdriver;
Cars with obstacle avoidance function Cars with obstacle avoidance function Car with obstacle avoidance function Step one: base
First put together the base and add the roller wheel in front. It will act as a supporting third wheel in the front and it can rotate 360 ​​degrees freely.
Mounts motors and wheels on the chassis. We solder the wires to the motors and proceed to the next step.
Cars with obstacle avoidance function Cars with obstacle avoidance function Step two: installing arduino
Install arduino and expansion board. We fix it on double-sided tape.
Auto with obstacle avoidance function  Car with obstacle avoidance function Step three: ultrasonic sensor
Next, you need to install the servo drive and attach the ultrasonic sensor to its shaft.
Cars with obstacle avoidance function  Cars with obstacle avoidance function Auto with obstacle avoidance function Step four: connection diagram
Motors
Shield The motor has screw terminals for connecting up to four motors. Just connect the motors to any two terminals as only two motors are used.
Servo motor
The servomotor has one connecting wire with three cores. Just connect it to S1 on the expansion board.
Ultrasonic Sensor
GND Sensor: Arduino GND
VCC Sensor: Arduino + 5V
TRIP Sensor: Arduino A4
ECHO sensor: Arduino A5
Also connect the battery holder to the screw terminal of the expansion board's battery.
Car with obstacle avoidance function Step five: code
Now you need to program Arduino through Arduino IDE. The code can be downloaded below.

 ////////////////////////////////////////////////////////Arduino Obstacle Avoiding Robot v2.0 ////By Aarav Garg - 2021 ////////////////////////////////////////////////////////////including the libraries #include & lt; AFMotor.h & gt; #include & lt; NewPing.h & gt; #include & lt; Servo.h & gt; //defining pins and variables #define TRIG_PIN A4 #define ECHO_PIN A5 #define MAX_DISTANCE 200 #define MAX_SPEED 200 //sets speed of DC motors #define MAX_SPEED_OFFSET 20 #define turn_amount 500 //defining motors, servo, sensor NewPing sonar, (TRIG_ ECHO_PIN, MAX_DISTANCE); AF_DCMotor motor1 (2, MOTOR12_8KHZ); AF_DCMotor motor2 (1, MOTOR12_8KHZ); Servo myservo; //defining global variables boolean goesForward = false; int distance = 100; int speedSet = 0; void setup () & # 123; Serial.begin (9600); myservo.attach (10); myservo.write (90); delay (2000); distance = readPing (); delay (100); distance = readPing (); delay (100); distance = readPing (); delay (100); distance = readPing (); delay (100); } void loop () & # 123; int distanceR = 0; int distanceL = 0; delay (40); Serial.println (distance); if (distance & lt; = 15) & # 123; Serial.println (& # 34; Object Detected & # 34;); moveStop (); delay (100); moveBackward (); delay (300); moveStop (); delay (200); distanceR = lookRight (); Serial.print (& # 34; Distance Right = & # 34;); Serial.println (distanceR); delay (200); distanceL = lookLeft (); Serial.print (& # 34; Distance Left = & # 34;); Serial.println (distanceL); delay (200); if (distanceR & gt; = distanceL) & # 123; turnRight (); moveStop (); } else & # 123; turnLeft (); moveStop (); }} else & # 123; moveForward (); } //reseting the variable after the operations distance = readPing (); } int lookRight () & # 123; myservo.write (0); delay (500); int distance = readPing (); delay (100); myservo.write (90); return distance; } int lookLeft () & # 123; myservo.write (180); delay (500); int distance = readPing (); delay (100); myservo.write (90); return distance; delay (100); } int readPing () & # 123; delay (70); int cm = sonar.ping_cm (); if (cm == 0) & # 123; cm = 250; } return cm; } void moveStop () & # 123; motor1.run (RELEASE); motor2.run (RELEASE); } void moveForward () & # 123; if (! goesForward) & # 123; goesForward = true; motor1.run (FORWARD); motor2.run (FORWARD); for (speedSet = 0; speedSet & lt; MAX_SPEED; speedSet + = 2) //slowly bring the speed up to avoid loading down the batteries too quickly & # 123; motor1.setSpeed ​​(speedSet); motor2.setSpeed ​​(speedSet + MAX_SPEED_OFFSET); delay (5); }}} void moveBackward () & # 123; goesForward = false; motor1.run (BACKWARD); motor2.run (BACKWARD); for (speedSet = 0; speedSet & lt; MAX_SPEED; speedSet + = 2) //slowly bring the speed up to avoid loading down the batteries too quickly & # 123; motor1.setSpeed ​​(speedSet); motor2.setSpeed ​​(speedSet + MAX_SPEED_OFFSET); delay (5); }} void turnRight () & # 123; Serial.println (& # 34; Turning Right & # 34;); motor1.run (FORWARD); motor2.run (BACKWARD); delay (turn_amount); motor1.run (FORWARD); motor2.run (FORWARD); } void turnLeft () & # 123; Serial.println (& # 34; Turning Left & # 34;); motor1.run (BACKWARD); motor2.run (FORWARD); delay (turn_amount); motor1.run (FORWARD); motor2.run (FORWARD); }  

On the video you can watch the assembly and demonstration of the robot.

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button