Description:
This is an obstacle avoiding robot using Arduino, it is a simple car which moves forward by its own at a certain speed, once an object or obstacle is detected, it then turns its direction and again starts moving forward in that direction. The obstacle is detected by Ultrasonic sensor HC-SR04 and all processing is done through Arduino Nano. There are total 3 wheels, 2 main wheels are connected to DC motor gear box and the third wheel is a small wheel kept alone, lonely and free without any attachments, connections, control, command, order, etc….. which is basically freely movable and gives support to the car.
In Type 1, when the Ultrasonic sensor detects an obstacle the car turns only in right direction and moves forward. That means it does not move in left direction. Still you can create changes in program and make it move in any direction you want. We also have Type 2 car if you want to check that out.
Circuit Diagram:
Components:
SR. NO. | COMPONENT | PINOUT DIAGRAM | BUY |
---|---|---|---|
1 | Arduino Nano (Other Arduinos can be used too) | ||
2 | HC-SR04 Ultrasonic Sensor Module | ||
3 | L298N Motor Driver Module | ||
4 | 2 x DC Motors with gear box | ||
5 | 9V Battery or Any battery ranging from 7V to 12V | ||
6 | Big Wheels x 2 | ||
7 | Slightly small wheels x 2 | ||
8 | Car Chassis |
Arduino Nano
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, and a power jack. The Arduino UNO is a popular choice among hobbyists and makers for its ease of use and wide range of libraries and example code.
In this project, the Arduino UNO serves as the brain of the robot car. It receives data from the HC-SR04 ultrasonic sensor, which detects obstacles in the robot’s path, and controls the DC geared motors based on the sensor data. The DC geared motors are used to move the robot car forward and backward, The Arduino UNO interprets the sensor data and control the motors accordingly to avoid obstacles.
BO DC Geared Motor
A BO DC geared motor is a type of direct current (DC) motor that uses gears to increase its torque and reduce its speed. This type of motor is commonly used in robotics and other applications that require precise control of speed and torque. They are also known for their high efficiency and reliability.
In this project, the BO DC geared motors are used to move the robot car forward and backward. The Arduino UNO controls the speed and direction of the motors based on the data received from the ultrasonic sensor. Using geared motors in the robot car project allows for fine control over the speed and direction of the robot, which is important for obstacle avoidance.
Steps and Info:
1. Get correct components as given. You can buy online or offline. I buy electronics components mostly from Amazon.
2. Start connecting the components. If you are new to connecting components in an electronic circuit, then use a Breadboard or you can straight up make connections using Jumper wires but it will create problem when there will be two or more connections needed at one pin (for example two or more different sensors 5V connection to Arduino’s 5V pin). But before soldering components on a PCB or printing a PCB for your circuit, better try using breadboard so that any errors and mistakes can be observed on breadboard and not after soldering. Or do connections in your way.
3. Now after building the circuit, download the Arduino IDE from https://www.arduino.cc/ website.
4. If you are new to Arduino IDE software, then watch this video we made specially for beginners about Arduino IDE.
5. If you know Arduino IDE then straight up copy the code we given and paste it into the Arduino IDE sketch.
6. Connect the Arduino to your Computer/device. Select a proper port, proper Arduino type and whatever other settings are. Here it is Arduino UNO. (If you don’t know what this all is then watch our video: ).
7. Compile the code and Upload it.
8. If any error occurs then try to troubleshoot it by finding/copy-pasting it into our Solve Errors page https://electronicsprojects.in/solve-errors/, or you can straight up paste the error on Internet and you know the rest. Also check if there are no spelling/syntax errors in the code. Compile the code again once to check if errors are fixed. I have given proper connections and code but still nothing is perfect.
9. Once code compiles and uploads smoothly, you can start testing the working of your circuit/project.
10. Build the car, attach Gear Box Motors below the chassis at backside and attach one small wheel at the front.
11. Fix the circuit on top of the car. Turn the car on and just let it go anywhere.
12. If it doesn’t work then check if motors are in correct position, check connections and code as well. Also you can talk with me and the community through discord. All the links to social is given at the right side of this page.
Program Code:
/* https://electronicsprojects.in Obstacle avoiding Robot using Arduino and Ultrasonic sensor (Type 1) */
int trig = 3;
int echo = 2;
int revleft7 = 7;
int fwdleft8 = 8;
int revright9 = 9;
int fwdright10 = 10;
long duration, distance;
void setup() {
delay(random(500,2000));
Serial.begin(9600);
pinMode(revleft7, OUTPUT);
pinMode(fwdleft8, OUTPUT);
pinMode(revright9, OUTPUT);
pinMode(fwdright10, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
duration = pulseIn(echo, HIGH);
distance = duration / 58.2;
delay(10);
if (distance > 19)
{
digitalWrite(fwdright10, HIGH);
digitalWrite(revright9, LOW);
digitalWrite(fwdleft8, HIGH);
digitalWrite(revleft7, LOW);
}
if (distance < 18)
{
digitalWrite(fwdright10, LOW);
digitalWrite(revright9, LOW);
digitalWrite(fwdleft8, LOW);
digitalWrite(revleft7, LOW);
delay(500);
digitalWrite(fwdright10, LOW);
digitalWrite(revright9, HIGH);
digitalWrite(fwdleft8, LOW);
digitalWrite(revleft7, HIGH);
delay(500);
digitalWrite(fwdright10, LOW);
digitalWrite(revright9, LOW);
digitalWrite(fwdleft8, LOW);
digitalWrite(revleft7, LOW);
delay(100);
digitalWrite(fwdright10, HIGH);
digitalWrite(revright9, LOW);
digitalWrite(revleft7, LOW);
digitalWrite(fwdleft8, LOW);
delay(500);
}
}
Download:
Links:
3D Printable Model STL file:
Wheels https://www.thingiverse.com/thing:3220008 | Credits to: https://www.thingiverse.com/ecureuilx/designs
Wheels https://www.thingiverse.com/thing:67296 | Credits to: https://www.thingiverse.com/jkoljo/designs