Hi guys. In this article, I will teach you how to build an obstacle avoiding robot. The robot will be a small and simple 2-wheeled car which will move forward until it detects an obstacle in its path. Upon doing so, it will stop, move a little back and then look towards its left and right.
Then it will compare the distances available ahead on either side and then turn towards the direction where the distance available seems to be more relatively. This way it will be able to move in an environment full of obstacles without colliding with any. This is a small representation of the concept of collision avoidance used in various applications such as warehouse robots, driverless cars etc.
To detect the distance, the robot uses the HC-SR04 ultrasonic sensor. So this sensor sends ultrasonic sound waves, every 10 microseconds, and if any obstacle is ahead, the sensor receives the echo. Based on the travel time, it knows the distance between the sensor and the object. So let's begin!
Step 1: Gather the ComponentsFirst, to begin with, we obviously need to gather the components and tools required to build the robot. Find the components and the tools required below:
Get components at one place for ease: The Arduino Robotic Kit
Individual Components:
- Arduino UNO
- L293D Motor Shield
- Chassis(including motors and wheels)
- Wires
- Battery Holder
- Micro Servo Motor SG90
- HC-SR04 Ultrasonic Sensor
- Sensor Mount (Optional)
Tools (Optional):
Gather the components and move on to the next step!
Step 2: Attach Motors and WheelsThe very first thing I did with the chassis was to add a castor wheel at the front which will act as a supportive third wheel at the front and it can rotate freely as it has 360-degree freedom. This way we can avoid the use of 4 wheels and get away with a 2-Wheeled robot.
Next what we need to do is a classic step in any vehicle-related project. Attach the motors and wheels to the chassis. There is no particular way to do this because everyone might be using a different chassis but I would like to mention one thing here: Ensure that the motors are fixed sturdily and are both levelled the same and also the wheels are pointing exactly forward. Otherwise, you might have some movement-related issue later-on.
Solder wires to the motors and move on to the next step!
Step 3: Attach Arduino and Motor ShieldAttach the Arduino board on the top of the chassis. You can attach it in any preferable way. This could be either using a few spacers and screws or directly sticking the Arduino board on the chassis using a piece of double-sided tape. Personally, I always would go with the first method because it gives it a more professional look.
Then just insert the motor shield on top of the Arduino board and you are good to go!
Step 4: Add Servo Motor and Ultrasonic SensorNow we need to add the sensing mechanism of the robot. This includes three components.
- Ultrasonic Sensor for sensing the distance ahead.
- Servo Motor for rotating the sensor towards left and right.
- The sensor-mount to fix the sensor on the servo motor.
My chassis had a cutout for attaching the servo motor so I simply had to insert it in the cutout. If yours too has one then great. If it doesn't, then just stick it on the front of the chassis using a piece of double-tape.
Then using the sensor-mount, attach the sensor to the servo motor and move ahead to the next step!
Step 5: WiringWe again have three things here. So, there are three things that we need to take care of while wiring the robot:
- Motors
The motor shield has ports for connecting up to four motors, in the form of screw terminals. Just connect the motors into any two terminals as we are using only two motors.
- Servo Motor
The servo motor has just one plug wire that has three wires in it. Just plug it into the servo terminal on the motor shield namely S1.
- Ultrasonic Sensor
Refer to the image present above for the connections of the ultrasonic sensor to the Arduino board. (or) Connections:
- Sensor GND : Arduino GND
- Sensor VCC : Arduino +5V
- Sensor TRIP : Arduino A4
- Sensor ECHO : Arduino A5
Also, connect the battery holder to the motor shield's battery screw terminals and move ahead, yet again!
Step 6: Coding ShowdownNow, it is time for the final sheet in the stack. It is time to code the robot and actually see whether the robot will work as it should, or not!
You can try to code the robot on your own for better experience and learning but you can always refer my code present below. I have also uploaded the Arduino Code file. Make sure that you have the Arduino IDE installed before trying to run your code :)
Thank You
Comments
Please log in or sign up to comment.