Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

5th Member

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 66

WOLDIA UNIVERSITY

INSTUTUTE OF THECNOLOGY
SCHOOL OF ELECTRICAL AND COMPUTER ENGINERRING
INDUSTRIAL CONTROL STREAM
FINAL BSC PROJECT
TITLE:- DESIGN LINE FOLLOWER AND OBSTACLE AVOIDANCE
ROBOT

NAME ID NO
1- Yonas fsaha.........................................................04253/09
2- Mahder mandefro..............................................02578/09
3- Yilma mengstie….................................................04205/09
4- teame afera........................................................03697/09
5- berihun desye…..................................................1212283

Advisor: Mr. Abemelek


Submission date:July,2021Gc
Woldia, Ethiopia
Design and simulate a Line follower and obstacle avoiding woldia university
robot

DECLARATION
This is to certify the thesis entitled “Design and simulate a Line follower obstacle
avoiding robot using Arduino” is submitted by us, partial fulfillment of the requirement
for the award of B.sc degree in Electrical and computer Engineering Stream of industry
control, to woldia university.

Name ID NO Signature

1-Yonas Fsaha 04253/09


2-Mahder mandefro 02578/09
3-Yilma mengstie 04205/09
4-teame afera 03697/09
5-berihun desye 1212283

Advisor Signature Date

Mr. Abemelek

pg. i
2021 G.C
ACKNOWLEDGEMENT
First of all, we want to give special thanks to our almighty GOD, who gave us courage
strength and allowed safe health to prepare this project.

Secondly, we would like to thanks our advisor, Mr. Abemelek for his expert guidance,
constructive comments, suggestions and encouragement for this work could have been
completed. We are also grateful to Woldia University Electrical and Computer
Engineering department teachers and students for their kind full help on giving related
information. They had been a constant source of inspiration throughout our studying
period.

Finally, we would like to extend our thanks to those who helped us with different ideas
and motivation which inspire us for the successful completion of this final year BSC
thesis.
ABSTRACT
Robots are new technologies of human based performer that accomplishes a task settled
forward more accurately than human being. Robots are different types for different
purposes so that different structures. The one we focus on now is line follower with
obstacle avoiding robots. Line follower robot is a hobo car that can follow a path. It is a
machine that follows a certain line (black line on white surface). It uses a sensor for
detecting a line, ultrasonic sensor to detect obstacle, Arduino microcontroller for giving a
decision and motors to progress motion. It is designed to carry materials from one place
to another place. It operates automatically without any human interaction by sensing
color. When the robot near to the obstacle then the ultrasonic sensor gives message signal
to the Arduino to turn left or right and When the robot reaches its end point, the infrared
sensor gives message signal to it and then it stops movement. This concept can be applied
for an autonomous vehicle by applying the similar micro control method line following
robot using Arduino. microcontroller can be modified into a guidance system for
industrial robots that involving traveling in the building. Besides that, it also can apply in
automated cars running on roads. It is designed to move automatically and follow the
made plot line. The robot is used IR sensors to identify the black line avoid the robot to
steer away from its track. robot is driven using dc motors to control the movement of the
wheels. The following process is automatically controlled using infrared sensor and
ultrasonic sensor by having this automatic control system large amount of energy is
saved. This path way for saving energy the result of the simulation obtained indicate that
the system presented has the potential to control moving system to meet requirement of
industry consumption. This document is intended to describe the information regarding
the project. The Arduino coding is developed on using C programming and tested and
verified. The proposed system can be implemented on any commercial, industrial,
medical and also in educational labs.
TABLE OF CONTENT
DECLARATION i
ACKNOWLEDGEMENT ii
ABSTRACT iii
Acronym vii
CHAPTER ONE 1
INTRODUCTION 1
1.1 Background History 1
1.2 Problem Statement 2
1.3 Objectives 3
1.3.1 General Objective 3
1.3.2 Specific Objectives 3
1.4 Significance of The Project 3
1.5 Scope of The Project 4
CHAPTER TWO 5
LITRATURE REVIEW 5
2.1 Backgrounds 5
2.2 History of Robotic 5
2.3 Related Works 5
Difference between Our Project and Related Topics 7
CHAPTER THREE 8
METHODOLOGY 8
3.1 Introduction 8
3.2Block diagram of the system 8
3.3 System Components and there description 9
3.3.1 Software Component Requirement---------------------------------------------------9
3.3.1.1 1A
rduino software (c language) 9
3.3.1.2 Proteus professional 8 software--------------------------------------------------10
3.3.2 Hardware Component Requirement-------------------------------------------------12
3.3.2.1 1Ar
duino 12
3.3.2.2 2IR
Sensor 16
3.3.2.3 Motor Driver (L298N) 18
3.3.2.4Dc motor 20
3.3.2.5Ultrasonic sensor (HC-SR04) 22
3.3.2.6Potentiometer (POT) 24
3.3.2.7Servo motor 26
CHAPTER FOUR 28
SYSTEM DESIGN AND ANALYSIS 28
4.1 Overall operation of the System 28
4.2 System Design 30
4.2.1 Circuit Diagram Design 30
Connection of Arduino pins with L298N 31
Connection of Arduino pins with ultra-sonic sensor----------------------------------31
Connection of Arduino pins with Virtual terminal------------------------------------32
Connection of Arduino pins with Servo motor----------------------------------------33
4.3 System Flow Chart 34
4.4 Result Analysis and discussion 36
4.4.1 esult 36
4.4.2 Discussions 40
CHAPTER FIVE 41
CONCLUSION AND RECOMMENDATION 41
5.1 Conclusion 41
5.2 Recommendation and Future Work 41
Reference 42
Appendix 44
LIST OF FIGURE
Figure 3.1 block diagram of the system...............................................................................8
Figure 3.2 Arduino programming (IDE) software.............................................................10
Figure 3.3 Proteus software diagram.................................................................................12
Figure 3.4 Arduino Nano controller...................................................................................14
Figure 3.5 IR sensor diagram.............................................................................................16
Figure 3.6 IR transmitter....................................................................................................17
Figure 3.7 IR receiver........................................................................................................17
Figure 3.8 IR sensor working principle.............................................................................18
Figure 3.9 L298N Motor driver module............................................................................18
Figure 3.10 L298N motor driver pin description diagram.................................................19
Figure 3.11 working principal diagram of dc motor..........................................................21
Figure 3.12 Gear dc motor.................................................................................................22
Figure 3.13 Diagram of the basic ultrasonic sensor operation...........................................23
Figure 3.14 ultrasonic sensor pin configuration.................................................................23
Figure 3. 15 ultrasonic sensor working principle...............................................................24
Figure 3.16 Potentiometer diagram....................................................................................25
Figure 3.17servo motor operation......................................................................................26
Figure 3.18 pulse width modulation..................................................................................27

Figure 4.1-line follower robot moving forward.................................................................28


Figure 4.2-line follower robot turns left.............................................................................29
Figure 4.3-line follower robot turns right..........................................................................29
Figure 4.4-line follower robot stops moving.....................................................................30
Figure 4.5-Obstacle Avoidance Robot...............................................................................30
Figure 4.6-Arduino pin configuration with motor driver L298N......................................31
Figure 4.7-Arduino pin configuration with ultrasonic sensor............................................31
Figure 4.8-Arduino configuration with IR sensor..............................................................32
Figure 4.9-Arduino pin configuration with virtual terminal..............................................32
Figure 4.10-Arduino pin configuration with servo motor..................................................33
Figure 4.11-overall system design diagram.......................................................................33
Figure 4.12-flow chart of the system.................................................................................35
Figure 4.13 The robot is moving forward..........................................................................36
Figure 4.14 the robot is turning to left and going forward.................................................37
Figure 4.15 the robot is turning to right and going forward..............................................38
Figure 4.14 the robot avoiding the obstacles.....................................................................39
Figure 4.16 the robot is stop moving, arrive at final destination.......................................40
Acronym
AC Alternative Current
CPU Control Processing Unit
DC Direct Current
EEPROM Electrically Erasable Programmable Read Only Memory
IC Integrated Circuit
IDE integrated development of environment
IR Infrared Sensor
LED Light Emitting Diode
PCB Printed Circuit Board
PFM Protentional field method
PUMA Programmable Universal Manipulation Arm
PWM Pulse Width Modulation
RAM Random Access Memory
ROM Read Only Memory
SDR Sony Dream Robots
CHAPTER ONE
INTRODUCTION
The line following robot is the self-operating intelligent machine that follows a drawn
line on a floor area and the path line can be visible as black on a white surface area; or a
white line on the black surface area. It is an autonomous robot which identify and tracks
either on a black line in white surface area or a white line in black surface area. Line
following robot must be able to detect a specified line and maintain track on it and do the
assign jobs. For performing job, the given path line must be followed by the designed and
developed robot for special situations.
To design a line follower an ultrasonic sensor is needed, which is a device that can
measure distance to an object by using sound waves. It computes the distance between
the object and the line follower by sending a sound wave at a specific frequency and
listening for that sound wave to bounce back. And uses to avoid obstacle, if it happens on
the path.

1.1 Background History


Robot is a computer-controlled machine that is programmed to move manipulate object,
and accomplish work while interacting with appropriate sensors and actuators and
mounted on it for carrying out the desired operation. In this robot infra-red sensor are
used for sensing the black or white line. Using ultrasonic sensor robot will find out the
obstacles present in front of them and move right or left from their current position and
move forward.[1]

Line follower Robots are nothing but self-thinking robots which can take decision itself
using programmed brain without any guidance from human being. There are two types of
Robots in one type robots perform action as we give signals remotely whereas second
type of Robots are self thinking robots which can detect obstacle and move forward. Line
Follower robot is a machine that follows a line, either a black line on white surface or a
white line on black surface. Nowadays, every robot is done with the help of the
microcontroller, and hence the circuit is too big and tough to understand and makes it
costly. For these reasons, in this project we have developed an intelligent Line follower
and obstacle detector robot with a simple concept with simple circuitry.[2]

1
Design and simulate a Line follower and obstacle avoiding woldia university
robot

There are two types of line follower robots: one is black line follower which follows
black line and second is white line follower which follows white line. the line following
robot is the self operating intelligent machine that follows a drawn line on a floor area
and the path line can be visible as black on a white surface area; or a white line on the
black surface area. It is an autonomous robot which identify and tracks either on a black
line in white surface area or a white line in black surface area. Line following robot must
be able to detect a specified line and maintain track on it and do the assign jobs. For
performing job, the given path line must be followed by the designed and developed
robot for special situations. The developed system composed of input, process and output
parts. First read the black/white or white/black path on considered floor and take input
signal for transmission into microcontroller (Arduino) in a process that can be asked and
made the decisions. Microcontroller decided based on the received inputs that can change
(if needed) to be made directions or speeds of the robot. It converts the result to any
directions which can be sent to the line follower speed. the system sends the first or
previous adjusted control signals to speed and directions of line follower robot. To design
a line follower an ultrasonic sensor is needed, which is a device that can measure distance
to an object by using sound waves. It computes the distance between the object and the
line follower by sending a sound wave at a specific frequency and listening for that sound
wave to bounce back. It is important to understand that some objects might not be detect
by ultrasonic sensor. This can be applied for military purposes, delivery services,
transportation systems, blind assistive applications.[3]

1.2 Problem Statement


In the industry carriers are required to carry products from one manufacturing plant to
another which are usually in different buildings or separate blocks at this time accident
are occurred because of human being are not perfectly committed for long period of work
time, inaccuracy and mistake. Conventionally, carts or trucks were used with human
drivers. The project is to automate this sector, using carts to follow a line instead of
driven by human. In industries robots are well suitable for carrying materials but the
probability of accident occurrence is high because of obstacles. This project is designed
to follow the lines to carry

pg. 2
2021 G.C
materials and avoid obstacles. Although the line following robot can follow the black line
and electrically operated without any human interaction.

In hospitals in terms of infected patients, specifically, virus-infected patients, it is always


risky to reach them as a first-person. But it is also important to offer them their medicinal
products on time at the same time. Our project can come handy in these kinds of
situations. As it can treat certain patients without the supervision or control of any human
being. It can easily follow the lines through the cabins and reach medicines to the
infected patients to their cabin.

1.3 Objectives
1.3.1 General Objective
The general objective of this project is to design, a line follower and obstacle avoiding
robot using Arduino controller.

1.3.2 Specific Objectives


 To design line follower robot with obstacle avoiding based on a predetermined
threshold distance.
 To develop control algorithm for DC motor to move the car to follow the path.
 To program Arduino source code.

1.4 Significance of The Project


 Used as automated equipment carriers in industries replacing traditional conveyer
belts.
 Developing lifestyles less dependent on human power.
 Avoid obstacles by itself.
 Reduce the energy use and the economic and social cost.
 It is very useful as it can work without any supervision. i.e., it can work as
automatic guided vehicles.
 In restaurants or hotels, the line follower obstacle avoidance robot can be used to
serve foods to the customers’ table.
 Used to reach medicines to the infected patients to their cabin and return safely.
1.5 Scope of The Project
In order to achieve the objective of the project, there are several scopes had been out
lined. The study outlines the design and development of line follower robot with obstacle
avoiding using infrared and ultrasonic sensor system that employs electronic moving
through electronic simulation. The circuit design and implementation are conducted via
pure electronic simulation using the proteus an Arduino software.
The project inhibits the conduct of the following in the entire scope of the study:
 Design a line following system using Infra-red sensor.
 Design obstacle avoiding system using ultrasonic sensor and servo motor.
 Design a line follower and obstacle detecting programming algorithm to perform
line following and obstacle avoiding task.
 Design circuit diagram using proteus software.
CHAPTER TWO
LITRATURE REVIEW
Overview

In this chapter, the background theory of robot and also the previous project done by
other researchers will be discussed.
2.1 Backgrounds
According to the robot Institute of America, the formal definition of industrial robot is as
follows: A robot is a programmable, multi-functional manipulator designed to move
material, parts or specialized devices through variable programmed motions for the
performance of a variety of tasks [4]. Nowadays, after the massive developments we may
consider a new definition as follows: A robot is the embodiment of manipulative,
locomotive, perceptive, communicative and cognitive abilities in an artificial body,
which may or may not have a human shape. It can advantageously be deployed as a tool,
to make things in various environments [4].
2.2 History of Robotic
In 1709Jacques de Vaucanson’s most famous creation was undoubtedly "The Duck."This
mechanical device could flap its wings, eat, and digest grain. Each wing contained over
four hundred moving parts and even today it remains something of a mystery. The
original Duck has disappeared [5]. In the 18th century, miniature automatons became
popular as toys for the very rich. They were made to look and move like humans or small
animals [6]. ELEKTRO was first unveiled at the 1939 world’s fair. In 1960’sOne of the
first operational, industrial robots in North America appeared in the early 1960’s in a
candy factory in Kitchener, Ontario [7]. In 1964Artificial intelligence research
laboratories are opened at M.I.T., Stanford Research Institute (SRI), Stanford University,
and the University of Edinburgh . In 1965 Carnegie Mellon establishes the Robotics
Institute [7].
2.3 Related Works
“line follower and obstacle avoidance bot using Arduino” has been designed and
developed by Aamir attar, Aadilansari, Abhishekdesai, Shahid khan, Dipashrisonawale to
create an autonomous robot which intelligently detects the obstacle in its path and
navigates
according to the actions that user set for it. So, this system provides an alternate way to
the existing system by replacing skilled labor with robotic machinery, which in turn can
handle more patients in less time with better accuracy and a lower per capita cost.[8]
“Obstacle-avoiding robot with IR and PIR motion Sensors” has been designed and
developed by Aniket D. Adhvaryu et al has proposed that developed robot platform was
not designed for specific task but as a general wheeled autonomous platform. The design
of such robot is very flexible and various methods can be adapted for another
implementation. It shows that PIR sensors are more sensitive compared to IR sensors
while detecting human being.[9]
Obstacle Avoidance Robotic Vehicle Using Ultrasonic Sensor, Android and Bluetooth
for Obstacle Detection” has been designed and developed by Vaghela et.al has mentioned
that enormous amount of work has been done on wireless gesture controlling of robots.
[10] “Obstacle Avoidance Robot” has been designed and developed by Paul Kinsky,
Quan Zhou mentioned that robot with a few mechanical components to add two more
functions to the main body, namely the laptop holder and the camera holder. AT89S52
development board is designed, developed and tested in a large scale, which was
used to control the motors smoothly. the cameras with relatively low cost are fixed and
adjusted on the camera holder for good calibration of the computer vision. Users establish
the serial communication method between the upper laptop and the lower development
board with USB port. The laptop will send out a signal of the motor condition to the
development board.[11]
“Obstacle avoidance & light following robot” in this paper the system is controlled by the
Arduino Uno R3 module which is an advance version of a microcontroller and a part of
embedded system. It has four types of functions. The functions are light following,
obstacle detection and controlling from an android device through Bluetooth or Wi-Fi
module& capture the video clips of that area. The robot has two light detection sensors
which are prepared with LDRs and an infrared obstacle detecting sensor. The sensitivity
of the light sensor can be set by using the trim pots.[12]
“obstacle avoidance robotic vehicle using ultrasonic sensor, Arduino controller” This
project describes about an obstacle avoidance robot vehicle which is controlled by
ultrasonic sensor. The robot is made using ultrasonic sensor and it is controlled by
Arduino
microcontroller. Ultrasonic sensor fixed in front portion of the robot vehicle. This vehicle
is used for detecting obstacle and avoiding the collision. They programmed the controller
to be used with Android app.[13]
“Obstacle avoidance autonomous intelligent robot” Autonomous Intelligent robots which
will perform desired tasks in unstructured environments without continuous human
guidance. It has an infrared sensor which are used to sense the obstacles coming in
between the path of Robot. It drive two gear motors for each wheel.[14]

Difference between Our Project and Related Topics


Related work
 They used PIR sensor.
 They use Ultrasonic Sensor, Android application and Bluetooth for
Obstacle Detection
 They use AT 89S52 microcontroller for controlling purpose.
 To follow the line and avoid obstacle Bluetooth and WIFI module control
are used.
 They use Two Wheel derive robot car.
Our project
 We use Arduino Microcontroller
 We use only ultrasonic sensor to detect and avoid the obstacle
 We use Arduino Nano controller.
 We use IR sensor to follow the line.
 Programming language carried out by Arduino code using Arduino
software (IDE).
 Our system is Four Wheel drive and automatically self-control.
CHAPTER THREE
METHODOLOGY
3.1 Introduction
Working of line follower obstacle avoiding robot is very interesting. The assembly of
sensors, servo motors, Arduino controller, motor drivers and DC motors will result the
line follower robot with obstacle avoiding. Line follower robot senses a black line by
using sensor and then sends signal to Arduino. Then Arduino drives the motor according
to sensor’s output. The block diagram describes there are sensors input into controller
(Arduino). The robot uses IR sensors to sense the line and output of the sensors is analog
signal which depends on the amount of light reflected back. This analog signal is given to
the comparator to produce 0s and 1s which are fed to the controller. then controller
decides the position of robot in left or right direction and the system have ultrasonic
sensor with servo motor to avoid obstacles. Power supply also necessary condition for the
system to work.
3.2Block diagram of the system

Potentiometer
Power supply Left front motor
Right front motor

Ultrasonic sensor

Motor driver

Right IR sensor

Arduino
Left IR sensor
Left back motorRight back motor

Servo motor

Figure 3.1 block diagram of the


The basic methodology contains two phases:
Phase 1: Preparing phase
Collect previous information about the line follower robot include components,
applications, and line detection techniques and controlling method.
Phase 2: Design phase
The design phase contain software design includes proteus simulation and Arduino code
programing.

3.3 System Components and there description


3.3.1 Software Component Requirement
 Arduino software (c language)
 Proteus professional 8 software

3.3.1.1 Arduino software (c language)


The Arduino Integrated Development Environment (IDE) is a cross-platform application
(for Windows, macOS, Linux) that is written in functions from C and C++. It is used to
write and upload programs to Arduino compatible boards, but also, with the help of third-
party cores, other vendor development boards. The source code for the IDE is released
under the GNU General Public License, version 2. 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. The Arduino IDE employs the program avrdude (is a utility to
download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers
using the in-system programming technique (ISP)) to convert the executable code into a
text file in hexadecimal encoding that is loaded into the Arduino board by a loader
program in the board's firmware. By default, avrdude is used as the uploading tool to
flash the user code onto official Arduino boards.
Figure 3.2 Arduino programming (IDE) software
3.3.1.2Proteus professional 8 software
The Proteus Design Suite is a proprietary software tool suite used primarily for electronic
design automation. The software is used mainly by electronic design engineers and
technicians to create schematics and electronic prints for manufacturing boards. It was
developed in Yorkshire, England by Lab center Electronics Ltd and is available in
English, French, Spanish and Chinese languages. The Proteus Design Suite is a Windows
application for schematic capture, simulation, and PCB (Printed Circuit Board) layout
design. It can be purchased in many configurations, depending on the size of designs
being produced and the requirements for microcontroller simulation. All PCB Design
products include an auto router and basic mixed mode SPICE simulation capabilities.

Schematic Capture
Schematic capture in the Proteus Design Suite is used for both the simulation of designs
and as the design phase of a PCB layout project. It is therefore a core component and is
included with all product configurations.

Microcontroller Simulation
The micro-controller simulation in Proteus works by applying either a hex file or a debug
file to the microcontroller part on the schematic. It is then co-simulated along with any
analog and digital electronics connected to it. This enables its use in a broad spectrum of
project prototyping in areas such as motor control, temperature control and user interface
design. It also finds use in the general hobbyist community and, since no hardware is
required, is convenient to use as a training or teaching tool. Support is available for co-
simulation of:

 Microchip Technologies PIC10, PIC12, PIC16, PIC18, PIC24, dsPIC33


Microcontrollers.
 Atmel AVR (and Arduino), 8051 and ARM Cortex-M3 Microcontrollers
 NXP 8051, ARM7, ARM Cortex-M0 and ARM Cortex-M3 Microcontrollers.
 Texas Instruments MSP430, PICCOLO DSP and ARM Cortex-M3
Microcontrollers.
 Parallax Basic Stamp, Freescale HC11, 8086 Microcontrollers.
PCB Design
The PCB Layout module is automatically given connectivity information in the form of a
netlist from the schematic capture module. It applies this information, together with the
user specified design rules and various design automation tools, to assist with error free
board design.
PCB's of up to 16 copper layers can be produced with design size limited by product
configuration.

3D Verification
The 3D Viewer module allows the board under development to be viewed in 3D together
with a semi-transparent height plane that represents the boards enclosure. STEP output
can then be used to transfer to mechanical CAD software such as Solid works or
Autodesk for accurate mounting and positioning of the board.

System Benefits Integrated package with common user interface and fully context
sensitive help.
Figure 3.3 Proteus software diagram

3.3.2 Hardware Component Requirement


 Arduino
 IR sensor
 Motor driver
 Power supply unit
 Dc motor
 Ultrasonic sensor
 Servo motor
 Potentiometer

3.3.2.1 Arduino
Arduino is a single-board microcontroller, intended to make the application of interactive
objects or environments more accessible. The hardware consists of an open-source
hardware board designed around an 8-bit Atmel AVR microcontroller, 8 analog input
pins, as well as 14 digital I/O pins which allows the user to attach various extension
boards. Arduino board is an open-source platform used to make electronics projects. It
consists of both a microcontroller and a part of the software or Integrated Development
Environment (IDE) that runs on your PC, used to write & upload computer code to the
physical board. The platform of an Arduino has become very famous with designers or
students just starting out with electronics, and for an excellent cause. Arduino board has
been used for making different engineering projects and different applications. The
Arduino software is
very simple to use for beginners, yet flexible adequate for advanced users. It runs
windows, Linux and Mac. Teachers and students in the schools utilize it to design low-
cost scientific instruments to verify the principles of physics and chemistry. There are
numerous other microcontroller platforms obtainable for physical computing. The
Netmedia’s BX-24, Parallax Basic Stamp, MIT’s Handy board, Phidget and many others
present related functionality. Arduino also makes simpler the working process of
microcontroller, but it gives some advantages over other systems for teachers, students
and beginners.

Features of Arduino boards

Table 3.1 Arduino board table


Arduino System Processor Memory Digital Analogue
Board Voltage I/O I/O
Arduino 5V 16Mhz 2KB SRAM, 32KB 14 6 inputs, 0
Uno ATmega328 flash output

Arduino 3.3v 84MHz 96KBSRAM,512KB 54 12 inputs, 2


Due AT91SAM3X8E flash outputs

Arduino 5v 16MHz 8KB SRAM, 256KB 54 16 inputs, 0


Mega ATmega2560 flash output

Arduino 5v 16MHz 2.5KBS, RAM 20v 12 inputs, 0


Leonardo ATmega32u4 32KB flash output

Arduino 2.7-5.5v ATmega88168v 1KB SRAM,16KB 14 6 inputs, 0


Lily Pad or Flash out put
328v
Arduino 5v Atmel 2KB SRAM, 32KB 14 8 inputs, 0
Nano ATmega328 Flash output
From the above Arduino type we select Arduino Nano, and the reasons we select Arduino
Nano is,it is
 Cross-platform
 Simple, clear programming environment
 Inexpensive
 Open source and extensible software
 Open source and extensible hardware

The Arduino Nano is essentially an Arduino UNO shrunk into a very small profile,
making it very convenient for tight spaces and projects that may need to reduce weight
wherever possible. Like the UNO, the Nano is powered by an Atmega328 processor
operating at 16MHz, includes 32KB of program memory, 1KB of EEPROM, 2KB of
RAM, has 14 digital I/O, 6 analog inputs, and both 5V and 3.3V power rails. (Note -
Arduino Nano boards before V3.0 used the ATmega168 which essentially has half the

specs.)
Figure 3.4 Arduino Nano controller
The Nano, unlike the UNO, cannot connect to Arduino shields but it has pin headers
which make it useful for breadboard prototyping or in PCBs with the use of a socket.
Often, Arduino Nano boards are the cheapest Arduino board option available making
them cost- effective for larger projects.

Table 3.2 Arduino Nano pin description table


in Category Pin Name Details
Power Vin, 3.3V, Vin: Input voltage (6-12V). 5V: Regulated
power supply used to power microcontroller and
5V, GND
other components on the board. 3.3V: 3.3V
supply generated by on-board voltage regulator.
Maximum current draw is 50mA. GND: Ground
pins.

Reset Reset Resets the microcontroller.

Analog Pins A0 – A7 Used to measure analog voltage 0-5V

Input/output Pins D0 - D13 Can be used as input or output pins


Pins

Serial Rx, TX Used to receive and transmit TTL serial data.

External 2, 3 To trigger an interrupt.


Interrupts

PWM 3, 5, 6, 9, 11 Provides 8-bit PWM output.

SPI 10,11,12 and 13 Used for SPI communication.

Inbuilt LED 13 To turn on the inbuilt LED.

AREF AREF To provide reference voltage for input voltage.


3.3.2.2 IR Sensor
IR module is sensor circuit which consists IR LED / photo diode pair, potentiometer,
LM358, resisters and LED. IR sensor transmits infrared light and photodiode receives the
infrared light. Sensors used in this robot are Infrared sensor, consisting two-part infrared
signal generator and the IR receiver designed in single PCB. There are two sensors are
used as left side sensor and right side sensor. An array of a sensor is used to detect the
line, based on the sensor status. The sensors are required to detect positions of the line to
be followed with respect to the robot's position. Most widely uses sensors for the line
follower robot are photo sensors (IR). They are based on the basic observations that the
white surface reflects the light and the back surface absorbs it.

Figure 3.5 IR sensor diagram

IR Transmitter or IR LED

Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations
called as IR
LED’s. Even though an IR LED looks like a normal LED, the radiation emitted by it is
invisible to the human eye.
Figure 3.6 IR transmitter
IR Receiver or Photodiode

Infrared receivers or infrared sensors detect the radiation from an IR transmitter. IR


receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are
different from normal photo diodes as they detect only infrared radiation. Below image
shows the picture of an IR receiver or a photodiode

Figure 3.7 IR receiver


Concept of working of line follower is related to light. We use here the behavior of light
at black and white surface. When light fall on a white surface it is almost full reflected
and in case of black surface light is completely absorbed. This behavior of light is used in
building a line follower robot.
Figure 3.8 IR sensor working principle
In this line follower robot, we have used IR Transmitters and IR receivers also called
photo diodes. They are used for sending and receiving light. IR transmits infrared lights.
When infrared rays fall on white surface, it’s reflected back and catch by photodiodes
which generates some voltage changes. When IR light falls on a black surface, light is
absorbed by the black surface and no rays are reflected back, thus photo diode does not
receive any light or rays.

3.3.2.3 Motor Driver (L298N)


This L298N Motor Driver Module is a high-power motor driver module for driving DC
and Stepper Motors. This module consists of an L298 motor driver IC and a 78M05 5V
regulator. L298N Module can control up to 4 DC motors, or 2 DC motors with
directional and speed control. The L298N Motor Driver module consists of an L298
Motor Driver IC, 78M05 Voltage Regulator, resistors, capacitor, Power LED, 5V jumper
in an integrated circuit.

Figure 3.9 L298N Motor driver module


78M05 Voltage regulator will be enabled only when the jumper is placed. When the
power supply is less than or equal to 12V, then the internal circuitry will be powered by
the voltage regulator and the 5V pin can be used as an output pin to power the
microcontroller.
L298N Module Pin Configuration

Figure 3.10 L298N motor driver pin description diagram


Table 3.3 pin description table of L298N motor driver
Pin Name Description

in1 & in2 Motor A input pins. Used to control the spinning direction of
Motor

in3 & in4 Motor B input pins. Used to control the spinning direction of
Motor

ENB Enables PWM signal for Motor

ENB Enables PWM signal for Motor

out1 & Output pins of Motor


out2

out3 & Output pins of Motor


out4

12v 12V input from DC power Source

5v Supplies power for the switching logic circuitry inside L298N IC


GND Ground pin

L298 Module Features & Specifications

 Driver Model: L298N 2A


 Driver Chip: Double H Bridge L298N
 Motor Supply Voltage (Maximum): 46V
 Motor Supply Current (Maximum): 2A
 Logic Voltage: 5V
 Driver Voltage: 5-35V
 Driver Current:2A
 Logical Current:0-36mA
 Maximum Power (W): 25W
 Current Sense for each motor
 Heatsink for better performance
 Power-On LED indicator

3.3.2.4 Dc motor
The DC motor is the motor which converts the direct current into the mechanical work. It
works on the principle of Lorentz Law, which states that “the current carrying conductor
placed in a magnetic and electric field experience a force”.

Working Principle of DC Motor


A DC motor is an electrical machine which converts electrical energy into mechanical
energy. The basic working principle of the DC motor is that whenever a current carrying
conductor places in the magnetic field, it experiences a mechanical force.
Figure 3.11 working principal diagram of dc motor
The reasons to select gear motor:
a gear motor is any electric motor coupled with a gear train. Gear motors use either AC
(Alternating Current) or DC (Direct Current) power. In most cases, the gear reducer is
intended to multiply the available output torque without increasing the power
consumption of the motor while maintaining a compact size. The tradeoff for torque
multiplication is a proportional reduction in the speed of the output shaft, and reduced
overall efficiency. By utilizing the proper gear technology and ratio for specific
applications, the optimal output and speed profiles can be obtained along with the perfect
mechanical fit to unlock the maximum value of your OEM equipment. Gear dc motor
have:

 High Torque Output


 Speed Reduction
 High Resolution
 Drive Large Inertial Loads
 Shorter Positioning Time
 Downsize
 Improved Damping Characteristics
 Increased Axial and Radial Load
 Increased Rigidity
 Surface Installation of Load
Figure 3.12 Gear dc motor

3.3.2.5 Ultrasonic sensor (HC-SR04)


 ULTRA = BEYOND
 SONIC = SOUND The sound beyond human hearing range(20000Hz) is known
as ultrasonic.
Ultrasonic sensors are sensors that convert ultrasound waves to electrical signals. An
Ultrasonic sensor is a device that can measure the distance to an object by using sound
waves. It measures distance by sending out a sound wave at a specific frequency and
listening for that sound wave to bounce back. By recording the elapsed time between the
sound wave being generated and the sound wave bouncing back, it is possible to calculate
the distance between the sonar sensor and the object. The HC-SR04 ultrasonic sensor
uses sonar to determine distance to an object like bats do. It offers excellent non-contact
range detection with high accuracy and stable readings in an easy-to-use package. From
2cm to 400 cm or 1” to 13 feet. Its operation is not affected by sunlight or black material
like sharp rangefinders are (although acoustically soft materials like cloth can be difficult
to detect). It comes complete with ultrasonic transmitter and receiver module.

To find the distance to the object, simply divide the round-trip distance in half.

Distance = (speed of sound * time taken) 2/


Figure 3.13 Diagram of the basic ultrasonic sensor operation
HC-SR04 Ultrasonic Sensor – Features

 Power Supply: +5V DC


 Quiescent Current: <2mA
 Working Current: 15mA
 Ranging Distance: 2cm – 400 cm
 Resolution: 0.3 cm
 Measuring Angle: 30 degrees
 Trigger Input Pulse width: 10uS
 Dimension: 45mm x 20mm x 15mm

HC-SR04 Ultrasonic Sensor Pin Configuration

Figure 3.14 ultrasonic sensor pin configuration

Table 3.4 Pin description table


Pin Pin Name Description
Number
1 VCC The VCC pin powers the sensor, typically with +5V
2 Trigger Trigger pin is an Input pin. This pin has to
be kept high for 10us to initialize
measurement by sending US wave.
3 Echo Echo pin is an Output pin. This pin goes
high for a period of time which will be
equal to the time taken for the US wave to
return back to the sensor.
4 Ground This pin is connected to the Ground of the system.

HC-SR04 Ultrasonic Sensor Working principle


The ultrasonic sensor uses sonar to determine the distance to an object. Here’s what
happens:
 the transmitter (trig pin) sends a signal: a high-frequency sound
 when the signal finds an object, it is reflected and

 the transmitter (echo pin) receives it.

Figure 3. 15 ultrasonic sensor working principle


3.3.2.6 Potentiometer (POT)
The instrument designs for measuring the unknown voltage by comparing it with the
known voltage, such type of instrument is known as the potentiometer. In other words,
the potentiometer is the three terminal devices used for measuring the potential
differences by manually varying the resistances. The known voltage is drawn by the cell
or any other supply sources. Characteristics of Potentiometer are:
 The potentiometer is very accurate because its works on the comparing method
rather than the deflection pointer method for determining the unknown voltages.
 It measures the null or balance point which does not require power for the
measurement.
 The working of the potentiometer is free from the source resistance because no
current flows through the potentiometer when it is balanced.

Working principle of Potentiometer


The working principle of the potentiometer is explained through the circuit shown below.
Consider S is the switch used for connecting or disconnecting the galvanometer from the
potentiometer. The battery through the rheostat and slide wire supply the working
current. The working current may vary by changing the setting of the rheostat.

Figure 3.16 Potentiometer diagram


The method of findings the unknown voltage depends on the sliding position of the
contact at which the galvanometer shows the zero deflection. The zero or null deflection
of galvanometer shows that the potential of the unknown source E and the voltage drops
E1 across the sliding wires are equal. Thus, the potential of the unknown voltage is
evaluated by knowing the voltage drop across the ac portion of the sliding wire. The slide
wire has the uniform cross-section and resistance across the entire length. As the
resistance of the sliding wire is known, then it is easily controlled by adjusting the
working current. The process of equalizing the working voltage as that of voltage drop is
known as the standardization.
3.3.2.7 Servo motor
A servomotor is a rotary actuator or linear actuator that allows for precise control of angular
or linear position, velocity and acceleration. It also requires a relatively sophisticated
controller, often a dedicated module designed specifically for use with servomotors.
There are two types of servo motors: AC and DC. AC servos can handle higher current
surges and tend to be used in industrial machinery. DC servos are not designed for high
current surges and are usually better suited for smaller applications. Generally speaking,
DC motors are less expensive than their AC counterparts. These are also servo motors
that have been built specifically for continuous rotation, making it an easy way to get
your robot moving. They feature two ball bearings on the output shaft for reduced friction
and easy access to the rest-point adjustment potentiometer.

Controlling of servo motor


Usually, a servomotor turns 90 degrees in either direction hence maximum movement can
be 180 degrees. However, a normal servo motor cannot rotate any further to a build in
mechanical stop. We take three wires are out of a servo: positive, ground and control
wire. A servo motor is control by sending a pulse width modulated (PWM) signal
through the control wire. A pulse is sent every 20 milliseconds. Width of the pulses
determine the position of the shaft. for A pulse of 1ms will move the shaft anticlockwise
at -90 degree, a pulse of 1.5ms will move the shaft at the neutral position that is 0 degree
and a pulse of 2ms will move shaft clockwise at +90 degree.
When we command a servo motor to move by applying pulse of appropriate width, the
shaft moves to and holds the require position of the shaft. However, the motor resists to
change. Pulses need repetition for the motor to hold the position.

Figure 3.17servo motor operation


Pulse width modulation
Pulse width modulation is a method to generate periodic square wave of various
frequencies (time period) or duty cycles. Pulse width Modulation or PWM is one of the
powerful techniques used in control systems today. They are not only employed in wide
range of control application which includes: speed control, power control, measurement
and communication.
Basic Principle of PWM
Pulse width modulation is a method used to generate periodic square wave of various
frequencies (time period) or duty cycles. Periodic square wave has two levels (high or
low), with some constant frequencies and duty cycle. Pulse-width Modulation is achieved
with the help of a square wave whose duty cycle is changed to get a varying voltage
output as a result of average value of waveform.

Figure 3.18 pulse width modulation


CHAPTER FOUR
SYSTEM DESIGN AND ANALYSIS
4.1 Overall operation of the System
The IR sensor detect surface and the ultrasonic sensor detect obstacle, when the sensor
detects black surface it gives high pulse to the Arduino, for white surface it detects give
low signal to Arduino based on program embedded into Arduino control the direction of
the robot. To accomplish these things, we prepare some logic to drive the robot
effectively on black surface with background of white surface. If the left sensor and right
sensor detect white surface and obstacle sensor detects no obstacle, then the robot moves
forward. If the left sensor detects white surface and right sensor detects black surface and
obstacle sensor detects no obstacle, then the robot turns right. If the left sensor detects
black and right sensor detects white surface and obstacle sensor detects no obstacle, then
the robot turns left. If the left and right sensor both detects black line, then the robot
stops. If the obstacle sensor detects obstacle, then the robot stops whatever the left and
right sensors values.

The robot uses the Ultrasonic distance sensor to measure the distance in front of it. When
this distance reduces to a particular level, the robot interprets it to mean the presence of
an obstacle in its path. When the robot detects an obstacle in its path, it stops, goes
backward for a few cm, looks around (right and left) by using servo motor then turn
towards the direction that shows more free space in front of it.
In this project we are using two IR sensor modules left sensor and right sensor. When
both left and right sensor senses white then robot move forward.

Figure 4.1-line follower robot moving forward


If left sensor comes on black line, then robot turn left side until both sensor comes at white
surface and the robot goes forward direction.

Figure 4.2-line follower robot turns left

If right sensor sense black line then robot turn right side until both sensor comes at white
surface.
When white surface comes robot starts moving on forward again.

Figure 4.3-line follower robot turns right


If both sensors comes on black line, robot stops.
Figure 4.4-line follower robot stops moving
If the ultrasonic sensor sense obstacle in its path the robot stopes, move backward for a
few cm, looks around (right and left) by using servo motor then turn towards the direction
that shows more free space in front of it.

Figure 4.5-Obstacle Avoidance Robot

4.2 System Design


4.2.1 Circuit Diagram Design
There are several steps to be taken in order to ensure the project done properly. The first
step is deciding the series number of the Arduino that will be used for the project (which
is one Arduino). This step is very important to let the designer to know what number of
pins in the Arduino will be used as inputs and outputs.
Connection of Arduino pins with L298N

 The Arduino pin out D4 is connected to the input pin IN1 of L298N
 The Arduino pin out D5 is connected to the input pin IN2 of L298N
 The Arduino pin out D6 is connected to the input pin IN3 of L298N
 The Arduino pin out D7 is connected to the input pin IN4 of L298N

Figure 4.6-Arduino pin configuration with motor driver L298N

Connection of Arduino pins with ultra-sonic sensor

 The Arduino analog input pin A1 is connected with the trigger of the sensor
 The Arduino analog input pin A2 is connected with the echo of the sensor

Figure 4.7-Arduino pin configuration with ultrasonic sensor


Connection of Arduino pins with IR sensor
 The Arduino pin input D9 is connected with the IR left sensor
 The Arduino input pin D10 is connected with the IR right sensor

Figure 4.8-Arduino configuration with IR sensor


Connection of Arduino pins with Virtual terminal
 The Arduino pin output D0 is connected with the virtual terminal
TXD.
 The Arduino pin output D1 is connected with the virtual terminal
RXD.

Figure 4.9-Arduino pin configuration with virtual terminal


Connection of Arduino pins with Servo motor
 Ground a brown wire connected to the ground of the system
 Power a red wire typically connected to +5v
 Orange wire connected with Arduino pin 12, through this wire PWM signal is
given to drive the motor.

Figure 4.10-Arduino pin configuration with servo motor

Figure 4.11-overall system design diagram


4.3 System Flow Chart
This section describes briefly the working of the system with the help of flow chart.
There are three sensors, ultrasonic sensor, right IR sensor and left IR sensors they sense
obstacle and black line on the white surface. When sensor starts reading signal can be
converted to digital then algorithm generate PWM and actuate motor driver.
start

Initializing

yes
Stop MD<SD
No

Backward

IR
Yes
forward
Stop R=0
IR L=0

No
U.S look right

IR R=O Yes
U.S look left Turn left
IR L=1
No
Forward
No
DR>=DL

Yes

Turn left Turn right


IR R=1 Yes
Turn right
IR L=0
Stop Stop
No
Forward

Turn right
Turn left
IR R=1 StFopigur
No Yes
4.12-flow chart of the system IR F=1 e
4.4 Result Analysis and discussion
4.4.1 Result
Condition-1:-
In this case when ultrasonic sensor measures distance of greater than set distance(in our
project greater than 12) and both left and right IR sensors senses white surface(0 binary
number) , then the robot goes forward direction.

Figure 4.13 The robot is moving forward


Condition-2:-

In this case when ultrasonic sensor measures distance of greater than set distance(in our
project greater than 12) and left IR sensor sense black surface(1 binary number) and right
IR sensor sense white surface(0 binary number) ,then the robot turning to the left
direction and after some delay goes forward.
Figure 4.14 the robot is turning to left and going forward
Condition-3:-

In this case when ultrasonic sensor measures distance of greater than set distance(in our
project greater than 12) and right IR sensor sense black surface(1 binary number) and left
IR sensor sense white surface(0 binary number) ,then the robot turning to the right
direction and after some delay goes forward.
Figure 4.15 the robot is turning to right and going forward

Condition-4:-
In this case when distance measured by ultrasonic sensor is less than or equal to set
distance(in our project <=12), then the robot stops moving and move backward direction
for some cm and calculate the left and right distance by using servo motor to move the
ultrasonic sensor +90 and -90 degree. If the right distance is greater than or equal to the
distance calculated in the left, then the robot turns to the right, goes forward, turn to the
left to follow the line and goes forward. If the left distance is greater than or equal to the
distance calculated in the right, then the robot turns to the left direction, goes forward,
turn to the right to follow the line and goes forward.
Figure 4.14 the robot avoiding the obstacles

Condition -5:-
In this case when distance measured by ultrasonic sensor is greater than set distance(in
our project greater than 12) and both right IR sensor and left IR sensor senses black(1
binary number) surface, then the robot stops moving and the robot is at final destination.
Figure 4.16 the robot is stop moving, arrive at final destination
4.4.2 Discussions
As we see from previous result analysis our robot moves forward direction, turning to
right and left to fallow the designing line(line path),avoiding obstacles and stop moving if
it is at final destination. We have used the Arduino software (IDE) to run the code, and
the program is run successfully. By using C language code, we have achieved some what
a desired result. We use proteus software to simulate our design circuit, and this shows
how the processed that controls the position and motion with required direction.
We use other components like motor driver and four DC motors. Motor driver used for
driving motors by controlling of direction and speed of the DC motors. DC motor uses
for moving of the robot from place to place. Arduino sends commands to this motor
driver and then it drive motors.

We use IR and ultrasonic sensor that give signal to the Arduino controller and Arduino
gives a signal to motor driver and dc motors are rotated. During the course of designing
this system there were series of problems encountered which came on the way of
achieving the desired goals of this project. we face a problem while we designing the
programming part especially writing a program on the Arduino IDE is a big difficulty,
because we are not familiar with C language. Another problem we face when we are
doing this project is shortage of time this is due to time management.
CHAPTER FIVE
CONCLUSION AND RECOMMENDATION
5.1 Conclusion
We concluded that as we see our project line follower obstacle avoiding robot works
successfuly. We made the obstacle avoidance base line following robot in simulation. As
we show from simulation result a circuit that enabled the robot to follow line based on the
light reflected off the ground and capable of following the lines by comparing light either
side of the different. And in varies positions of obstacle the robot can avoid obstacles by
itself and have shown a good performance. Designing controlling part of the proposed
system, as being the main task of our project, has been achieved with great success,
supported by simulation results.
Our project aims robot that intelligently senses the obstacle and the edge in its path and
navigates according to the behavior that we have set for it. So, what this system provides
is an alternative to the existing system by replacing human labor with robotic machinery,
which in turn can handle more patients in less time with better accuracy and a lower cost.

5.2 Recommendation and Future Work


For the future we recommend that the robot should be moving back. After reaching the
final destination we don’t design to move back ward to the beginning place because of
shortage time, so the robot should be design to move back. Also, this system can be
improved as a firefighting robot: By adding temperature sensor, water tank and making
some changes in programming we can use this robot as firefighting robot. As well as this
system can be improved by change the power source with solar energy instead of battery.
The solar energy is a green and environmentally suitable means instead of the battery
which harms the environment. So this would help in reducing the greenhouse effect
better than electrical battery. If obstacle like robe is happen in the path the uiltrasonic
sensor can’t deteact the obstacle, for the future it need a solution for the problem.
Reference
[1] J. Warren, J. Adams, and H. Molle, “Arduino for Robotics,” in Arduino Robotics,
New York, Apress publication, pp. 51–83, 2014.

[2] Komonya, S. Tachi, K. Tanie, “A Method for Autonomous Locomotion of.


Mobile Robots,” in Journal of Robotics Society of Japan, vol. 2, p. pp.222-231,
1984.

[3] Pakdaman, M.; Sanaatiyan, M.M, “Design and Implementation of Line Follower
Robot,” Computer and Electrical Engineering, 2009. ICCEE ‘09. Second
International Conference on, vol. vol.2, p. no., pp.585–590, 28–30, Dec. 2009.
[4] Embedded system (Raj Kamal, Pearson education, 2nd edition)

[5] Colak, I., Yildirim, D.,"Evolving a Line Following Robot to use in shopping
centers for entertainment", Industrial Electronics, 2009. IECON '09. 35th Annual
Conference of IEEE, pp.3803 - 3807, 3-5 Nov. 2009.

[6] S. E. M. Bajestani and A. Vosoughinia, "Technical report of building a line


follower robot," Electronics and Information Engineering (ICEIE), 2010
International Conference On, Kyoto, 2010, pp. V1-1-V1-5.

[7] Pakdaman, M.; Sanaatiyan, M.M., "Design and Implementation of Line Follower
Robot," Computer and Electrical Engineering, 2009. ICCEE '09. Second
International Conference on, vol.2, no., pp.585-590, 28-30 Dec. 2009.

[8] Amir attar, aadilansari, abhishek desai, shahid khan, and dip ashrisonawale, “line
follower and obstacle avoidance bot using arduino,” International Journal of
Advanced Computational Engineering and Networking, vol. 2, pp. 740–741, Aug.
1987.

[9] Aniket D. Adhvaryu et al, “Obstacle-avoiding robot with IR and PIR motion
Sensors,” IOP Conference Series: Materials Science and Engineering, vol. A247,
pp. 529–551, Apr. 2005.
[10] Vaghela Ankit1, Patel Jigar2, Vaghela Savan3, “Obstacle Avoidance Robotic
Vehicle Using Ultrasonic Sensor, Android And Bluetooth For Obstacle Detection,”
International Research Journal of Engineering and Technology (IRJET), vol. A247, pp.
29–32, 2005.
[11] Paul Kinsky,Quan Zhou, “Obstacle Avoidance Robot,” Worcester polytechnic
institute, vol. Vol. 4, pp. 279–285, 1991.

[12] Arnab Saha, Jeet Sanyal, Nousad Mondol, Santanu Ghosh, “Obstacle Avoidance
& Light Following Robot,” International Journal of Advances in Scientific Research and
Engineering (ijasre), vol. Vol. 03, no. Issue 4, May 2017.
[13] R.VAIRAVAN, S.AJITH KUMAR, L.SHABIN ASHIFF, C.GODWIN JOSE,
“obstacle avoidance robotic vehicle using ultrasonic sensor, Arduino controller,”
International Research Journal of Engineering and Technology, vol. Volume: 05, no.
Issue: 02, Feb. 2018.
[14] Ms. S.B. Burrewar , Mr. S.P. Joshi , Mr. A.P. Shingade , Mr. A.N. Shire, “Obstacle
avoidance Autonomous Intelligent Robot,” International Advanced Research Journal in
Science, Engineering and Technology, vol. Vol. 4, no. Issue 3, Jan. 2017.
Appendix
#include <Servo.h> //Servo motor library. This is standard library

#include<NewPing.h> //Ultrasonic sensor function library.

//our L298N control pins

const int LeftMotorForward = 7;

const int LeftMotorBackward = 6;

const int RightMotorForward = 5;

const int RightMotorBackward = 4;

int turn_delay = 10;

//sensor pins

#define trig_pin A1 //analog input 1

#define echo_pin A2 //analog input 2

//Sensor Connection

const int left_sensor_pin =9;

const int right_sensor_pin =10;

int turnspeed;

int left_sensor_state;

int right_sensor_state;

#define maximum_distance 200

boolean goesForward = false;


int distance;

NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function

Servo servo_motor; //our servo name

void setup(){

pinMode(RightMotorForward, OUTPUT);

pinMode(LeftMotorForward, OUTPUT);

pinMode(LeftMotorBackward, OUTPUT);

pinMode(RightMotorBackward, OUTPUT);

Serial.begin(9600);

delay(3000);

servo_motor.attach(12); //our servo pin

servo_motor.write(115);

delay(2000);

distance = readPing();

delay(100);

distance = readPing();

delay(100);

distance = readPing();
delay(100);

distance = readPing();

delay(100);

void loop(){

left_sensor_state = digitalRead(left_sensor_pin);

right_sensor_state = digitalRead(right_sensor_pin);

int distanceRight = 0;

int distanceLeft = 0;

delay(50);

if(right_sensor_state == HIGH && left_sensor_state == LOW)

turnRight();

delay(turn_delay);

if(right_sensor_state == LOW && left_sensor_state == HIGH)

turnLeft();

delay(turn_delay);
}

if(right_sensor_state == LOW && left_sensor_state == LOW)

moveForward();

delay(turn_delay);

if(right_sensor_state == HIGH && left_sensor_state == HIGH)

moveStop();

Serial.print("arrived at final destination");

while(true){

if (distance <= 12){

moveStop();

delay(300);

moveBackward();

delay(400);

moveStop();

delay(300);

distanceRight = lookRight();
delay(300);

distanceLeft = lookLeft();

delay(300);

if (distanceRight>= distanceLeft){

turnRight();

moveStop();

turnLeft();

else{ turnLeft

();

moveStop();

turnRight();

else{ moveForwa

rd();

distance = readPing();

int lookRight(){
servo_motor.write(50);

delay(500);

servo_motor.write(115);

Serial.print("ultrasonic sensor look right ");

int distance = readPing();

delay(100);

return distance;

int lookLeft(){

servo_motor.write(170);

delay(500);

servo_motor.write(115);

Serial.print("ultrasonic sensor look left ");

int distance = readPing();

delay(100);

return distance;

delay(100);

int readPing(){

delay(70);

int cm = sonar.ping_cm();
Serial.print("Distance: ");

Serial.println(cm);

if (cm==0){

cm=250;

return cm;

void moveStop(){

digitalWrite(RightMotorForward, LOW);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorBackward, LOW);

digitalWrite(LeftMotorBackward, LOW);

Serial.println("stop");

void moveForward(){

if(!goesForward){
goesForward=true;

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW);

Serial.println("Going forward");

void moveBackward(){

goesForward=false;

digitalWrite(LeftMotorBackward, HIGH);

digitalWrite(RightMotorBackward, HIGH);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorForward, LOW);
Serial.println("Move backward");

void turnRight(){

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorBackward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorForward, LOW);

delay(250);

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW);

Serial.println("Turning right");

}
void turnLeft(){

digitalWrite(LeftMotorBackward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorForward, LOW);

digitalWrite(RightMotorBackward, LOW);

delay(250);

digitalWrite(LeftMotorForward, HIGH);

digitalWrite(RightMotorForward, HIGH);

digitalWrite(LeftMotorBackward, LOW);

digitalWrite(RightMotorBackward, LOW);

Serial.println("Turning left");

You might also like