Obstacle Avoiding Smartcar using
Arduino and Ultrasonic Sensors
J-Component Report
Submitted by
SRIJAN SRIVASTAVA
16BEC0685
SAMARTH MEHTA
16BEE0299
SHASHANK SINGH
16BEC0746
AAKRITI MITTAL
16BEC0935
Submitted to
SUBHATHIRAI S P
Assistant Professor
in partial fulfilment of the course of
SENSORS & INSTRUMENTATION
ECE1005
For the semester
FALL 2017
VIT UNIVERSITY
Vellore, Tamil Nadu 632014
October 2017
BONAFIDE CERTIFICATE
VIT UNIVERSITY
Vellore, Tamil Nadu 632014
Certified that this project report
“Obstacle Avoiding Smartcar using Arduino and Ultrasonic Sensors”
is the bonafide work of
16BEC0685, 16BEE0299, 16BEC0746, and 16BEC0935
who carried out the project work under my supervision.
(Signature)
SUBHATHIRAI S P
Assistant Professor
Table of Contents
Obstacle Avoiding Smartcar using Arduino and Ultrasonic Sensors ..........................1
Abstract ...........................................................................................................................4
Introduction.....................................................................................................................5
Problems addressed ................................................................................................5
Solutions offered ......................................................................................................5
Components Used ..........................................................................................................6
Features of the components used ................................................................................7
Arduino Uno Microcontroller .......................................................................................7
Ultrasonic Sensor ........................................................................................................8
Testing the components .............................................................................................9
Shields....................................................................................................................... 10
Motor Shield .......................................................................................................... 10
Procedure..................................................................................................................... 11
1. Header ............................................................................................................. 12
2. Global variables .............................................................................................. 12
3. Setup Routine ................................................................................................. 12
4. Loop ................................................................................................................. 12
5. Functions ......................................................................................................... 12
Schematic .................................................................................................................... 17
Working ........................................................................................................................ 18
Applications ................................................................................................................. 19
Further implementations ......................................................................................... 19
Project Contributions .................................................................................................. 20
Cost Analysis ................................................................................................................ 20
References ................................................................................................................... 21
Abstract
Trajectory planning is one of the most important pivotal point in pick and place
tasks done by robotic manipulators. In this work, we have presented a robot,
which is compact, autonomous and fully functional.
This robot or a smartcar is built to sense any obstacle in its path, to avoid it and
resume its running involving the pre-computation of an obstacle free path.
Ultrasonic sensors were adapted to implement a real-time obstacle avoidance
system for wheeled robots, so that the robot can continually detect surroundings,
avoid obstacles, and move toward the target area.
This model has tremendous applications in vacuum cleaners, avoiding concealed
paths, parking systems, assembling automobiles and in chemical industries, in
scientific exploration, emergency rescue and in other isolated environments.
We use an Arduino UNO with a Motor Shield along with Stepper Motors to make
the car, and for sensing we incorporate an Ultrasonic Sensor which accurately and
efficiently detects any obstacles in the smart car’s path. The Arduino is coded
such that the smartcar moves backward when an obstacle arises in front of it with
a maximum limit of 50cms in ideal testing conditions.
Throughout the construction of this model, we educated ourselves to the Arduino
coding language, the Motor Shield functionality, and comprehensively, with the
working of an ultrasonic sensor and its features.
In conclusion, through this project, we aim to construct a model of a smartcar that
is beneficial to the quotidian problems of the present generation.
Introduction
Problems addressed
o Need for a robot that can perform trajectory planning effectively
o Need for a system which can detect obstacles and move in a pre-computed
path
o Need for the detection of obstacles that appear suddenly
o Need to minimize human risk regarding the upper limit of a human eye
o Need to assist the physically handicapped by incorporating cutting edge
technologies in wheelchairs
o Need to address the need for upgrade from inaccurate sensors like CCD
cameras, CMOS image sensors, laser light pens, global positioning systems,
and so on
o Need for advanced mapping devices during exploration of unknown
environments such as interplanetary exploration
Solutions offered
o Robot detects obstacles and avoids them in the trajectory
o Robot uses an Ultrasonic Sensor which is capable of detecting obstacles
which may appear suddenly, for instance, an animal in front of a wheelchair
o Robot can operate in the environment without much interference
o Robot can detect very minute details, which the human eye may neglect
o Robot can map various topographies and terrains
Components Used
Arduino Uno Micro- Chassis Ultrasonic Sensors
controller HC – SR04
Jumper Wires 5V Power Supply Castor Wheel
Wheels Stepper Motors Motor Shield
X2
Features of the components used
Arduino Uno Microcontroller
An Arduino is an open-source
microcontroller development
board. The most common version of
Arduino is the Arduino Uno. It is
relatively cheap, plugs straight into a
computer's USB port, and it is simple
to setup and use when compared to
other development boards.
Some of the key features of the Arduino Uno include:
o Open source design. Large community at arduino.cc/forum/ of people using and
troubleshooting it.
o Easy USB interface. The chip on the board plugs straight into your USB port and
registers on your computer as a virtual serial port. This allows us to serially
communicate which is an extremely easy protocol
o Convenient power management and built-in voltage regulation. 12v can easily be
regulated to both 5v and 3.3v
o Easy-to-find and cheap, microcontroller
o Countless number of hardware features like timers, PWM pins, external and
internal interrupts, and multiple sleep modes.
Some other specifications are
o A 16 MHz clock.
o 32 KB of flash memory
o 13 digital pins and 6 analogue pins.
o ICSP connector to re-bootload your chip and for bypassing the USB port and
interfacing the Arduino directly as a serial device
o LED attached to digital pin 13 for and easy debugging of code.
o Reset button to reset the program on the chip.
Ultrasonic Sensor
The Ultrasonic Sensor sends out a high-frequency
sound pulse and then times how long it takes for
the echo of the sound to reflect back. The sensor
has two openings on its front.
o Tiny speaker to transmit opening ultrasonic
waves
o Microphone to receive the ultrasonic waves
The ultrasonic sensor calculates distances by -
The speed of sound is approximately 341 meters per second in air. The ultrasonic
sensor uses this information along with the time difference between sending and
receiving the sound pulse to determine the distance to an object. It uses the
following mathematical equation:
𝑇𝑖𝑚𝑒 𝑥 𝑆𝑝𝑒𝑒𝑑 𝑜𝑓 𝑆𝑜𝑢𝑛𝑑
Distance = 2
Time = the time between when an ultrasonic wave is transmitted and when it is received
We divide this number by 2 since the sound wave has to travel to the object and back.
The limitations of an ultrasonic sensor is some objects might not be detected it
which are shaped or positioned in such a way that the sound wave bounces off the
object, but are deflected away from the sensor.
It is also possible for the object to be too small to reflect enough of the sound
wave back to the sensor to be detected.
Objects can absorb the sound wave all together (cloth, carpeting, etc), which
means that there is no way for the sensor to detect them accurately.
These are important factors to consider when designing and programming a robot
using an ultrasonic sensor
Testing the components
The Arduino has two different types of input pins, those being analog and digital. We
will focus on the Digital Input Pins.
To check the working of our ultrasonic sensor
o The serial monitor allows the computer to connect serially with the Arduino.
o It takes data that the Arduino is receiving from sensors and other devices and
displays it in real-time on the computer
o Having this ability is invaluable to debug the code and understand what
number values the chip is actually receiving.
o Navigate to File --> Examples --> 1.Basics --> AnalogReadSerial
o Click the button to engage the serial monitor which looks like a magnifying
glass. We can now see the numbers being read by the analog pin in the
serial monitor. When we turn the knob the numbers will increase and
decrease.
The numbers will be between the range of 0 and 1023. The reason for this is that the
analog pin is converting a voltage between 0 and 5V to a discreet number.
Digital inputs may be used as the basis for countless digital communication
protocols.
o By creating a 5V (HIGH) pulse or 0V (LOW) pulse, we can create a binary
signal, the basis of all computing.
o This is useful for talking to digital sensors like a PING ultrasonic sensor, or
communicating with other devices.
o For a simple example of a digital input in use, connect a switch from digital pin
2 to 5V, a 10K resistor from digital pin 2 to ground, and run the following code:
o File - Examples - 2.Digital - Button
o When the switch is pressed, the electrical connections in the switch has
less resistance than the resistor, and the electricity no longer connects
to ground. Instead, electricity flows between 5V and the digital pin.
o This is because electricity always chooses the path of least resistance.
Shields
o Shields are the expansion adapter boards that plug in over top of the Arduino
Uno and gives it special functions.
o Since the Arduino is open hardware, anyone who has the inclination is free to
make an Arduino shield for whatever task they wish to accomplish.
o Hence, there are countless number of Arduino shields available, out of which
the official ones are -
o Wireless SD Shield
o Ethernet Shield
o Motor Shield
Motor Shield
The Arduino Motor Shield allows the user
to easily control motor direction and speed
using an Arduino. Arduino pins are
straightforward and hence it makes it very
simple to incorporate a motor into a
project. It also allows you to be able to
power a motor with a separate power
supply of up to 12V.
o The motor shield has 2 channels,
which allows for the control of two DC motors, or 1 stepper motor.
o An external power supply, the motor shield can safely supply up to 12V and
2A per motor channel
o There are pins on the Arduino that are always in use by the shield.
o By addressing these pins one can select a motor channel to initiate, specify
the motor direction (polarity), set motor speed (PWM), stop and start the
motor, and monitor the current absorption of each channel .
The pin breakdown is as follows:
Function Channel A Channel B
Direction Digital 12 Digital 13
Speed (PWM) Digital 3 Digital 11
Brake Digital 9 Digital 8
Current Sensing Analog 0 Analog 1
Procedure
Getting the hardware ready
o Switch it on and off and then look in to making the LED on the left of
Arduino with the letter L next to it blink on and off for 2 seconds at a time.
o The Arduino Uno requires a male USB A to male USB B cable. Plug the USB
cable in to the Arduino and your computer, the LED will start blinking. It is
the default program stored on the chip
o The USB cable powers the device. Arduinos can also run standalone by
using a power supply in the bottom left of the board.
o Once programming is done it does not require to be constantly connected to
a machine we can opt to power it separately. This is entirely dependant on
the use case and circumstances we want to use the device in.
Getting the software ready
o Download and install the Arduino IDE (integrated development
environment). The Arduino Programmer is based on the Processing IDE and
uses a variation of the C and C++ programming languages.
o Before doing anything in the Arduino programmer, set the board-type and
serial port.
o To set the board, go to the following:
o Tools - Boards
o Select Arduino Uno.
o To set the serial port, go to the following:
Tools - Serial Port
Select the serial port that looks like:
/dev/tty.usbmodem [random numbers]
Writing the code
To write an Arduino sketch or a code, some basic knowledge about C and
Embedded C should be known.
Some important things to look out for in an Arduino code are -
o An Arduino program is called a sketch.
o All lines of code in an Arduino sketch is processed from top to bottom.
o Arduino sketches are typically broken into five parts -
1. Header Usually, the sketch starts with a header that explains what the
sketch is doing, and the author.
2. Global variables Next, global variables are defined. Often, this is where
constant names are given to the different Arduino pins.
3. Setup Routine After the initial variables are set, the Arduino begins the
setup routine. In the setup function, we set initial conditions of variables
when necessary, and run any preliminary code that we only want to run
once. This is where serial communication is initiated, which is required for
running the serial monitor.
4. Loop From the setup function, we go to the loop routine. This is the main
routine of the sketch. This is not only where your main code goes, but it
will be executed over and over, so long as the sketch continues to run
5. Functions Below the loop routine, there are often other functions listed.
These functions are user-defined and only activated when called in the
setup and loop routine
All of that said, the only two parts of the sketch which are mandatory are the
Setup and Loop routines.
o Code must be written in the Arduino Language, which is roughly based on C.
o Almost all statements written in the Arduino language must end with a ;
symbol. However, conditionals (such as if statements and for loops) do not
need a ;
o Variables are storage compartments for numbers. You can pass values into
and out of variables.
o Variables must be defined (stated in the code) before they can be used and
need to have a data type associated with it.
For this particular code,
1. First, we open the BareMinimum sketch, which can be found at:
File - Examples - 1. Basic - BareMinimum
The BareMinimum Sketch should look like this:
<pre>void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
}
2. Next, we put a header on the code, so other people know about what we are
making, why, and under what terms:
<pre>/*
Obstacle Avoiding Smartcar using Arduino and Ultrasonic Sensors
By VIT
2017
Avoids obstacles by employing an ultrasonic sensors
This code is in the Public Domain
*/
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
}
3. Then, we define the pin names, and establish variables, and write the code
<pre>/*
Obstacle Avoiding Smartcar using Arduino and Ultrasonic Sensors
By VIT
2017
Avoids obstacles by employing an ultrasonic sensors
This code is in the Public Domain
*/
#include <AFMotor.h>
AF_DCMotor right_motor(1,MOTOR12_8KHZ);
AF_DCMotor left_motor(2,MOTOR12_8KHZ);
const int trigPin = 4;
const int echoPin = 2;
String readString;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
right_motor.setSpeed(250);
left_motor.setSpeed(250);
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.41;
Serial.println(distance);
if (distance<30){
right_motor.run (BACKWARD);
left_motor.run (FORWARD);
delay(500);
else{
right_motor.run (FORWARD);
left_motor.run (BACKWARD);
delay(500);
} }
Schematic
Fig 1 Schematic
Working
o The robot is switched on by giving it 5V DC power from an external battery.
The motors starts rotating and thus the robot starts moving forward.
o During this time, the ultrasonic sensors continuously keep calculating the
distance between the robot and the reflective surface.
o This information gets processed by the ARDUINO.
o If the distance between the robot and the obstacle is less than the specified
value, the robot changes its path(moves towards the back).Here, we have
kept the minimum distance to be of 15cm.
o This process continues forever and the robot keeps moving without danger.
Applications
o The modification of this logic code is used in vacuum cleaners.
o This robot can be used for avoiding concealed paths, such as an
industrial robot in a factory is expected to avoid workers so that it won’t
hurt them
o It will be very useful in parking system.
o It can also be used in assembling automobiles and in chemical
industries.
o If there is an obstacle in the root of the robot, it can detect and avoid it.
Thus it can move without having damaged by any obstacle which makes
it more reliable
o They have great importance in scientific exploration and emergency
rescue, there may be places that are dangerous for humans or even
impossible for humans to reach directly, then we should use robots to
help us gather information to about their surrounding challenging
environments.
Further implementations –
o This technique can also be used as a vision belt for blind people by
changing the ultrasonic sensor by a kinetic sensor ,which is a type of
microwave sensor whose sensing range is very high and the output of
this sensor vary in according to the object position changes. This
technique enables blind people to navigate obstacles easily by placing
three vibratos in left, right and the centre of a belt named as Vision Belt.
o On top of obstacle avoiding robot temperature/ pressure sensors can be
added to monitor the atmospheric conditions around. This is useful in
places where the environment is not suitable for humans. Same
technology can be used in various applications by modifying the program
for example Line / Path finder Robot , automatic vacuum cleaner etc.
o They can be used as services robots, for the Low Cost Obstacle
Avoidance Robot, purpose of household work and so many other indoor
applications.
Project Contributions
S. No Name Registration Time devoted Allocation of project
Number (in weeks)
1. SRIJAN SRIVASTAVA 16BEC0685 4-5 Research
2. SAMARTH MEHTA 16BEE0299 4-5 Working model
3. AAKRITI MITTAL 16BEC0935 2-3 Presentation
4. SHASHANK SINGH 16BEC0746 1 Testing
Cost Analysis
S. No Name Cost (in INR)
1. Arduino Uno 500
2. Motor Shield 230
3. DC Motors X2 210
4. Jumper wires 90
5. Ultrasonic sensor 120
6. Chasis 50
TOTAL 1200
References
[1] A. Davids, “Urban Search and Rescue Robots: From Tragedy to
Technology”, IEEE Intelligent systems 17.2, 2002, pp. 81-83.
[2] T. Rakib, and M.A. Rashid Sarkar, "Design and fabrication of an
autonomous fire fighting robot with multisensor fire detection
using PID controller.", 5th International Conference on IEEE
Informatics, Electronics and Vision (ICIEV), 2016.
[3] T. Lozano-Perez, “Autonomous robot vehicles”, Eds. Ingemar J.
Cox, and Gordon T. Wilfong, Springer Science & Business Media,
2012.
[4] G. Song, Y. Kaijian, Z. Yaoxin, and C. Xiuzhen, "A surveillance
robot with hopping capabilities for home security", IEEE
Transactions on Consumer Electronics 55.4, 2009.
[5] H. Durrant-Whyte, and T. Bailey, "Simultaneous localization and
mapping: part I.", IEEE robotics & automation magazine 13.2,
2006, pp. 99-110.
[6] HCSR04 datasheet: http://www.micropik.com/PDF/HCSR04.pdf
[7] H. Choset, K. Nagatani, and N.A. Lazar, "The arc-transversal
median algorithm: a geometric approach to increasing ultrasonic
sensor azimuth accuracy", IEEE Transactions on Robotics and
Automation 19.3, 2003, pp. 513-521.
[8] R.O. Duda, P.E. Hart, and D.G. Stork, “Pattern classification”,
John Wiley & Sons, 2012.
[9] R.C. de Amorim, and C. Hennig, "Recovering the number of
clusters in data sets with noise features using feature rescaling
factors", Information Sciences 324, 2015, pp. 126-145.
[10] B. Ilias, S. A. A. Shukor, A. H. Adom, M. F. Ibrahim and S.
Yaacob, "A novel indoor mobile robot mapping with USB-16
ultrasonic sensor bank and NWA optimization algorithm," 2016
IEEE Symposium on Computer Applications & Industrial
Electronics (ISCAIE), Penang, 2016, pp. 189-194.