Sunteți pe pagina 1din 32

Obstacle Avoiding Robot

B.Tech. MINI PROJECT


Submitted by

ROHIT KUMAR CHAUDHARY


(Roll no. B150982EE)
SANDEEP K KOYON
(Roll no. B130320EE)

In partial fulfillment for the award of Degree of


Bachelor of Technology
IN
Electrical Engineering

Under the guidance of,

Dr. PREETHA P

Department of Electrical Engineering


NATIONAL INSTITUTE OF TECHNOLOGY CALICUT,

NIT CAMPUS P.O., CALICUT, INDIA-673601


APRIL 2019
ACKNOWLEDGEMENT

We express our deep sense of gratitude to our respected and learned project guide, Dr.
Preetha P for the valuable help and guidance provided in the course of completion of
this project.

We are also grateful to respected Prof Dr. Saly George, Head of the Department of
Electrical Engineering and to our respected Director, Dr Sivaji Chakravorti, and NIT
Calicut for permitting us to utilize all the necessary facilities of the institution.

We are also thankful to all the other faculty and staff members of our department for
their kind co-operation and help.

Lastly we would like to express our deep appreciation to all our classmates and
indebtedness to our parents for providing us the moral support and the encouragement.

Rohit Kumar Chaudhary

Sandeep K Koyon
CERTIFICATE

This is to certify that the report entitled “OBSTACLE AVOIDING ROBOT” is a bona fide
record of the mini-project done by ROHIT KUMAR CHAUDHARY (Roll no. B150982EE)
and SANDEEP K KOYON (Roll no. B130320EE) under my supervision and guidance, in
partial fulfilment of the requirements for the award of Degree of Bachelor of Technology
in Electrical Engineering from National Institute of Technology Calicut for the academic
year 2018-2019.

(Guide)
Dr. PREETHA P
Associate Professor
Dept. of Electrical Engineering

Thesis attested by

Dr. Saly George


Professor & Head
Dept. of Electrical
Engineering
NIT Calicut
CALICUT
CONTENTS
ABSTRACT…………………………………………………………………………………………………..i
LIST OF FIGURES…………………………………………………………………………………………ii
LIST OF ABBREVIATIONS……………………………………………………………………………iii
1. INTRODUCTION…..…………………………………………………..…………………………….1

1.1 INTRODUCTION…………………………………………………………..1

2. ARDUINO………………………....…………………………………………………………………....2

2.1 ARDUINO…………………………………………………………………...2

2.2 History……………………………………………………………………….2

2.2 Development………………………………………………………………..2

2.3 Evolution…………………………………………………………………….3

3. EMBEDDED SYSTEM………………………………..……………………………………………..4

4. MICROCONTROLLER…………………………………………………..……………………….....7

5. ROBOTICS……………………………………………………………………………….....................8

5.1 Robot…………………………………………………………………….....8

5.2 What should a robot look like?.............................................................8

5.3 Robot task………………………………………………………………....9

6. COMPONENTS USED…………………………………………………………….……………….10

6.1 HARDWARE REQUIREMENTS…………………………………………………..…………………10

6.2 SOFTWARE REQUIREMENTS…………………………………………………..……...............14

7. PROJECT DESCRIPTION……………………………….……………………………………..…15

7.1 Circuit Diagram……………………………………………………………………………………………15

7.2 Circuit Explanation…………………………………………………………………………………..….16

7.3 Block Diagram……………………………………………………………………………………………..17

7.4 Working……………………………………………………………………………………………………….17

7.5 Application…………………………………………………………………………………………………..22
8. RESULT AND CONCLUSION……………………………………………………………………..19

REFERENCE……………………………………………………………………………………………….20

APPENDICES………………………………………………………………………………………………21
ABSTRACT

Obstacle detection and avoidance can be considered as the central issue in designing
mobile robots. This technology provides the robots with senses which it can use to
traverse in unfamiliar environments without damaging itself. In this work an Obstacle
Avoiding Robot is designed which can detect obstacles in its path and manoeuvre
around them without making any collision. It is a robot vehicle that works on Arduino
Microcontroller and employs ultrasonic distance sensors to detect obstacles. The
Arduino board was selected as the microcontroller platform and its software counterpart,
Arduino Software, was used to carry out the programming. The ultrasonic distance
sensors provides higher accuracy in detecting surrounding obstacles. Being a fully
autonomous robot, it successfully manoeuvred in unknown environments without any
collision. The hardware used in this project is widely available and inexpensive which
makes the robot easily replicable.

i
LIST OF FIGURES

FIGURE NO. TITLE PAGE NO.

1 BLOCK DIAGRAM OF EMBEDDED SYSTEM 5

2 LAYERED ARCHITECTURE OF AN EMBEDDED SYSTEM 6

3 WHAT SHOULD A ROBOT LOOK LIKE? 9

4 ARDUINO UNO 10

5 MOTOR SHIELD 11

6 SERVO MOTOR 12

7 DC BO MOTOR 12

8 ULTRASONIC SENSOR 13

9 CIRCUIT DIAGRAM OF OBJECT AVOIDING ROBOT 15

10 BLOCK DIAGRAM OF OBJECT AVOIDING ROBOT 17

ii
LIST OF ABBREVIATIONS

ES Embedded System

MCU Microcontroller Unit

IR Infrared Ray

I/O Ports Input Output Ports

ASIC Application- Specific Integrated Circuit

iii
CHAPTER-01
INTRODUCTION

1.1INTRODUCTION
From its initiation in the 1950s, modern robots have come a long way and rooted
itself as an immutable aid in the advancement of humankind. In the course of time,
robots took many forms, based on its application, and its size varied from a giant 51
feet to microscopic level. In the course of technological developments of robots,
one aspect remained instrumental to their function, and that is mobility. The term
“obstacle avoidance” is now used in modern robotics to denote the capability of
robot to navigate over an unknown environment without having any collision with
surrounding objects (Duino-Robotics, 2013). Obstacle avoidance in robots can bring
more flexibility in maneuvering in varying environments and would be much more
efficient as continuous human monitoring is not required.

An obstacle avoiding robot which can move without any collision by sensing
obstacles on its course with the help of ultrasonic distance sensors can be put into
diversified uses, e.g., surveying landscapes, driverless vehicles, autonomous
cleaning, automated lawn mower and supervising robot in industries. The robot
developed in this work is expected to fulfill the following objectives:
 The robot would have the capacity to detect obstacles in its path based on a
predetermined threshold distance.
 After obstacle detection, the robot would change its course to a relatively
open path by making autonomous decision.
 It would require no external control during its operation.
 It can measure the distance between itself and the surrounding objects in
real-time.
 It would be able to operate effectively in unknown environment.

1
CHAPTER – 02
ARDUINO
2.1 ARDUINO
Arduino is a popular programmable board used to create projects. It consists of a
simple hardware platform as well as a free source code editor which has a “one
click compile or upload” feature. Hence it is designed in way that one can use it
without necessarily being an expert programmer (Kushner 1987). Arduino offers an
open-source electronic prototyping platform that is easy to use and flexible for
both the software and hardware. Arduino is able to sense the environment
through receiving input from several sensors. It is also able to control its
surrounding through controlling motors, lights and other actuators. The Arduino
programming language that is based on the wiring and the Arduino development
environment that is based on the processing are used to program the
microcontroller found on the board (Banzi, 2005). Due to its open-source
environment, one is able to easily write and upload codes to the I/O board. It is
also worth to note that Arduino can be run on Linux, Mac OSX and Windows as its
environment is written in Java

2.2 History
Arduino was released in 2005 by students from the Interaction Design Institute
Ivrea (IDII) as a modest tool for Mac OSX and Windows. Since then, Arduino has
been able to initiate an international-do-it yourself revolution at the electronics
industry. The open source microcontroller hardware has been designed in a way
that it can easily interface with various sensors (registering user inputs) and driving
the behaviors and responses of the external components such as speakers,
motors, and LED (responding to the user inputs). The most important feature of
Arduino is the ease of programmability hence users with little expertise are able to
use it. This aspect has made Arduino one of the most popular tools of choice for
designers and artists in creating interactive spaces and objects (Arduino Team).

2.3 Development
While discussing the development of Arduino, it is worth introducing a brief history
of microcontrollers. A revolutionary leap in the computing industry was seen in the
1960s following the development of solid state computers (including the IBM
1401), that used transistors to process its operations and a magnetic core memory
for its storage (instead of vacuum tubes), and these enabled an increase in the
compactness of the computer hardware. In addition, Jack Kilby’s invention of
2
integrated circuits in 1959 enabled circuits and transistors to be fused into tiny
chips of semiconducting materials (like silicon) as well as further miniaturization of
the computer component. The other crucial development made in the same
decade was the high level computer programming languages, written in symbolic
languages such as plain English, and this made computer codes somehow easy to
learn and read than the earlier machine languages that consisted of letters and
numbers only. This development enabled individuals with few years of expertise to
carry out the basic operations on a computer. FORTRAN (for the scientific
calculators) and COBOL (for business application) were the two main languages
that were introduced in that period.

The microprocessor was one of the greatest innovations in the history of the modern
computer in the 1970’s. Initially, the microprocessor miniaturized all the hardware
components of CPU to fit into one, tiny, integrated circuit, popularly known as the
microchip. The microchip became the major driving component of the
microcontrollers including Arduino which is made up of a microchip, input/output
hardware and memory storage hardware for sensors. The microprocessor, due to
the small form factor, was incorporated into a surfeit of electronic devices ranging
from personal computers to calculators and are still used up to date. More
programming languages were also developed in the 1970s and 80s including C, C+
+ and Java for applications in science and business. (Massimo, 2005)

2.4 Evolution
Having looked at the evolution of microcontrollers, there have been recent
incarnations of the microcontrollers that have been designed in a way to fulfill the
needs of hobbyists and casual users who happen to have a limited technical
knowledge. In other words, the microcontrollers have moved from the more
complex requirements in the scientific, business or commercial fields. Before the
invention of Arduino, the PIC microcontroller board that was introduced by
general instruments in 1985 was one of the most used tools for the electronic
enthusiasts. The reasons as to why the PIC microcontroller board was preferred
were the speed and ease of its programming through simple languages including
PBASIC. An additional reason was that it was able to store programs on a flash
memory chip that enabled the instructions on the board to be reprogrammed or
erased at will with an infinite number of possibilities. It also supported output
devices such as LEDs and motors as well as input sensors. There are other popular

3
boards for the hobbyists including BASIC Stamp and wiring which are some of the
microcontroller boards that were designed for tangible media explorations and
electronic art. The two boards share the advantages of ease of rapid prototyping
and simplicity of programming.

It was in 2005 when the Arduino team was formed in Italy and it consisted of
Barragan Massimo, David Cuartielles, Gianluca Marino, Dave Mellis and Nicholas
Zambetti. The main goal of this team was to develop an electronic prototyping
platform that would simplify the wiring platform and make it accessible to the non-
technical users especially in the creative fields. The Arduino, therefore,
incorporated several characteristics including a programming environment that is
based on the processing language that was conceived by Casey Reas and Ben Fry
and other artists and designers. Arduino also incorporated the ability to program
its board using a standard USB connection with a low price point (Wheat, 2001).

4
Chapter -03
EMBEDDED SYSTEM

3.1 EMBEDDED SYSTEM (ES)


The microprocessor-based system is built for controlling a function or range of
functions and is not designed to be programmed by the end user in the same way a
PC is defined as an embed system. An embedded system is designed to perform
one particular task albeit with different choices and options.
Embedded systems contain processing cores that are either microcontrollers or
digital signal processors. Microcontrollers generally known as "chip", which may
itself be packaged with other microcontrollers in a hybrid system of Application-
Specific Integrated Circuit (ASIC). In general, input always comes from a detector or
sensors in more specific word and meanwhile the output goes to the activator
which may start or stop the operation of the machine or the operating system.

An embedded system is a combination of both hardware and software as shown


in Fig.1. Each embedded system is unique and the hardware is highly specialized
in the application domain.The Layered architecture of an Embedded System is
shown in Fig.2.

Hardware consists of processors, microcontroller, IR sensors etc. On the other


hand, Software are just like a brain of the whole embedded system as this consists
of the programming languages used which make hardware work. As a result,
embedded systems programming can be a widely varying experience.

5
Figure1. Block diagram of Embedded System (ES consists of hardware and software part which
again consists of programming language and physical peripherals respectively).

If the history of ES is observed, it can be figured out that the grace of ES have
been enjoyed for quite a long time since they were designed around the
microprocessors than microcontrollers, which are used mostly today. There has
been a huge shift in ES from microprocessors to microcontrollers because
microprocessors do not possess any memory, ports etc., as a result, everything
must be connected externally by using peripherals like 8255, 8257, 8259 etc.
On the other hand, the microcontroller is a single silicon chip consisting of all input,
output and peripherals on it. A single microcontroller has the following features:

1. Arithmetic and logic unit


2. Memory for storing program
3. EEPROM for nonvolatile and special function registers
4. Input/output ports
5. Analog to digital converter
6. Circuits
7. Serial communication ports and many other

Figure 2. Layered architecture of an Embedded System.

A microprocessor-based system which is built for controlling a function or range of


functions and is not designed to be programmed by the end user in the same way a
PC is defined as an embedded system. An embedded system is designed to perform
one particular task albeit with different choices and options.
6
CHAPTER 4
MICRO CONTROLLER

4.1 MICRO CONTROLLER


A highly integrated chip that contains all the components comprises a controller.
Typically this includes a CPU, RAM, some form of ROM, I/O ports, and timers.
Unlike a general- purpose computer, which also includes all of these components, a
microcontroller is designed for a very specific task; to control a particular system.
As a result, the parts can be simplified and reduced, which cuts down on
production costs.
Microcontrollers are sometimes called embedded microcontrollers. This just means
that they are part of an embedded system; that is, one part of a larger device or
system.
Microcontrollers are used in automatically controlled products and devices, such as
automobile engine control systems, implantable medical devices, remote controls,
office machines, appliances, power tools, toys and other embedded systems. The
first integrated circuit was developed by Jack Kilby of Texas Instruments and Robert
Noyce of Fairchild Semiconductor in 1950.
Some microcontrollers may use four-bit words and operate at frequencies as low
as 4 kHz, for low power consumption (single-digit milliwatts or microwatts). They
generally have the ability to retain functionality while waiting for an event such as a
button press or other interrupt; power consumption while sleeping (CPU clock and
most peripherals off) may be just nanowatts, making many of them well suited for
long lasting battery applications. Other microcontrollers may serve performance-
critical roles, where they may need to act more like a digital signal processor (DSP),
with higher clock speeds and power consumption.

7
CHAPTER 5
ROBOTICS
5.1 Robotics

Robotics is the branch of technology that deals with the design, construction,
operation, and application of robots. A machine capable of carrying out a
complex series of actions automatically, esp. one programmable by a
computers is defined as a robot. Robotics must be able to perform certain
tasks assigned, within given limitations, regardless of these limitations being
human-controlled or automatic.

5.2 Robot
An electro-mechanical machine that can do the work of a person and that
works automatically or is controlled by a computer is defined as a Robot. It is
a device that can perform automatically or through some controlling devices.
A robot is defined as " a machine capable of carrying out a complex series of
actions automatically, especially one programmable by a computer.” (Oxford
Dictionary, 2013)

5.3 What should a Robot look like?


According to the survey conducted by the Swiss Institute of Technology in
Lausanne in 2008 among 240 people (Swiss Federal Institute of Technology,
2008), this is the general concept of what a robot should look like (Fig. 3):

8
Figure 3. What should a Robot look like? (Swiss Federal Institute of
Technology, 2008).

Results show that for the participants in the survey a robot looks like a
machine, be it big or small. In spite of the apparent popularity of Japanese
robots such as the Sony Aibo, the Furby and Asimo, other categories (creature,
human, and animal) gathered only a small percentage.

5.4 The robot task


The task of our robot is pretty simple. The robot has to be made in such a way
that it will move forward until it detects an obstacle. On detecting an obstacle, it
will turn left or right depending on the free space available in front of it. On
detecting any obstacles through the Ultrasonic sensors, it moves towards left or
right depending on the amount of rays detected by ultrasonic sensors (left and
right) respectively. Although the task is simple, this robot is completely
autonomous.

9
CHAPTER 6
COMPONENTS USED
6.1 HARDWARE REQUIREMENT

6.1.1 Arduino Uno


 The Arduino UNO is an open-source microcontroller board based on
the Microchip ATmega328P microcontroller and developed
by Arduino.cc that is shown in Fig. 4.

FIGURE 4. ARDUINO UNO

 The board is equipped with sets of digital and analog input/output (I/O)
pins that may be interfaced to various expansion boards (shields) and
other circuits.
 The board has 14 Digital pins, 6 Analog pins, and programmable with
the Arduino IDE (Integrated Development Environment) via a type B USB
cable. It can be powered by a USB cable or by an external 9 volt battery,
though it accepts voltages between 7 and 20 volts.

10
6.1.2 MOTOR SHIELD

 The Arduino Motor Shield (FIG.5) is a shield that lets you control various
loads that a typical Arduino pin cannot drive.

FIGURE 5. MOTOR SHIELD

 Its driver used to control servo and wheel motors speed and rotation.

 To control the motor’s direction, Pin 12 (Channel A) and Pin 13 (Channel


B) are used.  To drive the motor forward* this pins needs to be brought
high. The pins can be driven low to put the motors into reverse.

 To control the motors speed Pin 3 (Channel A) and Pin 11 (Channel B)


can use PWM signals to vary the speed of the motors.  To use the PWM
feature on the Arduino the analog Write function needs to be called. 

 Another feature of the Arduino Motor Shield is the ability to determine


the amount of current the motor (or any inductive load) is drawing.
Current sensing can be useful for robotics applications, such as traction
control and determining if the robot is pushing an object. The current
sense pins are A0 (Channel A) and A1 (Channel B).  The Motor Shield will
output 3.3v on the current sense pins when the maximum channel
current (2 amps) is reached.  

11
6.1.3SERVO MOTOR 

 A servo motor (Fig.6.)is a closed-loop system that uses position feedback


to control its motion and final position.

FIGURE 6. SERVO MOTOR

 In industrial type servo motors the position feedback sensor is usually a


high precision encoder, while in the smaller RC or hobby servos the
position sensor is usually a simple potentiometer.

6.1.4 DC BO MOTORS

FIGURE 7. DC BO MOTOR

 DC motor with gear box (Fig.7.) which gives good torque and rpm at
lower voltages.
 This dc motor can run at approximately 200rpm when driven by a Dual
Li-Ion cell battery at 6 V and approximately 300 rpm when connected to
9V. 
 It is most suitable DC motor for light weight robot running on small
voltage.

12
 Ability to operate with minimum or no lubrication, due to inherent
lubricity.

6.1.5 ULTRASONIC SENSOR

FIGURE 8. ULTRASONIC SENSOR

 As the name indicates, ultrasonic sensors measure distance by using


ultrasonic waves that shown in Fig.8.
 The sensor head emits an ultrasonic wave and receives the wave
reflected back from the target.
 Ultrasonic Sensors measure the distance to the target by measuring the
time between the emission and reception.
 An optical sensor has a transmitter and receiver, whereas an ultrasonic
sensor uses a single ultrasonic element for both emission and reception.
 In a reflective model ultrasonic sensor, a single oscillator emits and
receives ultrasonic waves alternately. This enables miniaturization of the
sensor head.

13
2.2 Software Requirements

 The Arduino integrated development environment is a cross-platform


application that is written in the programming language Java.
 It is used to write and upload programs to Arduino compatible boards,
but also, with the help of 3rd party cores, other vendor development
boards.
 The Arduino IDE supports the languages C and C++ using special rules of
code structuring.
 The Arduino IDE supplies a software library from the Wiring project,
which provides many common input and output procedures. User-
written code only requires two basic functions, for starting the sketch
and the main program loop, that are compiled and linked with a
program stub main() into an executable cyclic executive program with
the GNU toolchain, also included with the IDE distribution.

14
 CHAPTER 7
PROJECT DESCRIPTION
7.1 CIRCUIT DIAGRAM:
The following image shows the circuit diagram for the obstacle avoiding robot:

FIGURE 9. CIRCUIT DIAGRAM OF OBSTACLE AVOIDING ROBOT

15
7.2 CIRCUIT EXPLANATION:

 Attach the DC Motors in the Caster wheel on the chassis.

 Then attach the Arduino on the chassis.

 Solder 4 wires in the motor shield (5V, Gnd, A4, A5) to connect the
ultrasonic sensor with Arduino.

 Then connect the motor shield with Arduino.

 Then attach the servo motor on the chassis.

 Then attach the ultrasonic sensor with the servo motor.

 Then attach the Ultrasonic sensor like this- Ultrasonic Sensor to Motor
Shield - VCC to 5v, Gnd to Gnd,Trig to A4, Echo to A5.

 Attach the Servo Motor like this- Servo Motor to Motor Shield-
Signal(yellow wire) to 5 VCC(red wire) to ‘(+ve)‘ Gnd (black wire) to ‘(-
ve)'

 Attach the right motor to the 'M3' connector of the motor shield and
the left motor to the 'M1' connector of the motor shield.

 Then attach the switch, batteries and LEDs as per the circuit diagram.

16
7.3 BLOCK DIAGRAM:

FIGURE 10. BLOCK DIAGRAM OF OBJECT AVOIDING ROBOT

7.4 WORKING
 Before going to working of the project, it is important to understand how the
ultrasonic sensor works. The basic principle behind the working of ultrasonic
sensor is as follows:
 Using an external trigger signal, the Trig pin on ultrasonic sensor is made logic
high for at least 10µs. A sonic burst from the transmitter module is sent. This
consists of 8 pulses of 40 kHz.
 The signals return back after hitting a surface and the receiver detects this
signal. The Echo pin is high from the time of sending the signal and receiving it.
This time can be converted to distance using appropriate calculations.
 The aim of this project is to implement an obstacle avoiding robot using
ultrasonic sensor and Arduino. All the connections are made as per the
circuit diagram. The working of the project is explained below.

17
 When the robot is powered on, both the motors of the robot will run
normally and the robot moves forward. During this time, the ultrasonic
sensor continuously calculates the distance between the robot and the
reflective surface.
 This information is processed by the Arduino. If the distance between the
robot and the obstacle is less than 15cm, the Robot stops and scans in left
and right directions for new distance using Servo Motor and Ultrasonic
Sensor. If the distance towards the left side is more than that of the right
side, the robot will prepare for a left turn. But first, it backs up a little bit
and then activates the Left Wheel Motor in reversed in direction. 
 Similarly, if the right distance is more than that of the left distance, the
Robot prepares right rotation.  This process continues forever and the
robot keeps on moving without hitting any obstacle.

7.5 APPLICATIONS
1. Road safety

If one car can detect near car they can avoid collision.

2. Mars rover

It takes 46 minutes to send a message to mars. So ultrasonic sensor help


to survive this billion dollar robot in continuously changing environment.

3. Fire rescue

Able move in smoke and find location of rescue.

4. Tunnel rescue

Tunnels are always filled with dirt water and waste objects. When
animals are trapped in small tunnels. We find them by using ultra sonic
sensor robots.

CHAPTER 8
RESULT

18
The outcome of the thesis is a simple, which moves around detecting
the obstacles on its way and thus making its way through the free
space avoiding all the obstacles it encounters. After the completion
of the robot, the robot can now burst ray through the transmitter,
and the receiver will detect the bounced ray that strikes the
obstacles if there are any. If there are any obstacles and IR collides
with them, then brain of the robot (micro controller) will calculate
the distance 30cm and detect object with minimum height of 10cm.

The robot is made activated after the switch on the activity board is
turned on. If there seems to have any obstacle with in the distance
set to it, it will move to the opposite direction of the obstacle
detected. That is, if the right sensor detects the object on its way, it
will turn left and start moving straight again and if left sensor
detects an obstacle, it will turn right and continue moving.
Additionally, if there seems to be obstacle all around the robot
within the detection distance, robot will keep on rotating 360°.

CONCLUSION
It gives on an opportunity to test mechanical, electronics and
programming skills.

Obstacle avoiding vehicle project also provides robot construction


experience to beginners.

19
REFERENCE
1. Ahasan, M. A., Hossain, S. A., Siddiquee, A. U., & Rahman, M. M.
(2012). Obstacles Invariant Navigation of An Autonomous Robot
based on GPS. Khulna University.
2. Arduino. (2015). Arduino Software (IDE). (Arduino) Retrieved
December 27, 2015, from
https://www.arduino.cc/en/Guide/Environment
3. Arduino. (2015). Introduction. (Arduino) Retrieved December
12,2015,from https://www.arduino.cc/en/Guide/Introduction
4. Duino-Robotics. (2013). Obstacle Avoidance Tutorial. (Duino-
Robotics) Retrieved November 23, 2015, from http://www.duino-
robotics.com/obstacle- avoidance.html
5. Gray, K. W. (2000). Obstacle Detection and Avoidance for an
Autonomous Farm Tractor. Utah State University.
6. Heidarsson, H. K., & Sukhatme, G. S. (2011). Obstacle Detection
and Avoidance for an Autonomous Surface Vehicle using a
Profiling Sonar. 2011 IEEE International Conference on Robotics
and Automation. Shanghai.
7. Ryther, C. A., & Madsen, O. B. (2009). Obstacle Detection and
Avoidance for Mobile Robots. Technical University of Denmark.
8. Shahdib, F., Ullah, M. W., Hasan, M. K., & Mahmud,
H. (2013). Obstacle Detection and Object Size

APPENDICES
ALGORITHM
//ARDUINO OBSTACLE AVOIDING CAR//
// Before uploading the code you have to install the necessary library//
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install //
//NewPing Library https://github.com/eliteio/Arduino_New_Ping.git //

20
//Servo Library https://github.com/arduino-libraries/Servo.git //

#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>

#define TRIG_PIN A0
#define ECHO_PIN A1
#define MAX_DISTANCE 300
#define MAX_SPEED 190 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
Servo myservo;

boolean goesForward=false;
int distance = 100;
int speedSet = 0;

void setup() {

myservo.attach(10);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}

void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);

if(distance<=20)

21
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);

if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}

int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}

int lookLeft()
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);

22
return distance;
delay(100);
}

int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;
}

void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

void moveForward() {

if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid
loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
}
}
}

void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);

23
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid
loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet);
motor3.setSpeed(speedSet);
motor4.setSpeed(speedSet);
delay(5);
}
}

void turnRight() {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}

void turnLeft() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}

24

S-ar putea să vă placă și