LINE FOLLOWING AND OBSTACLE AVOIDING CAR Manan Shaileshkumar Shah

advertisement
LINE FOLLOWING AND OBSTACLE AVOIDING CAR
Manan Shaileshkumar Shah
B.E., Gujarat University, India, 2005
PROJECT
Submitted in partial satisfaction of
the requirements for the degree of
MASTER OF SCIENCE
in
ELECTRICAL AND ELECTRONIC ENGINEERING
at
CALIFORNIA STATE UNIVERSITY, SACRAMENTO
FALL
2010
LINE FOLLOWING AND OBSTACLE AVOIDING CAR
A Project
by
Manan Shaileshkumar Shah
Approved by:
__________________________________, Committee Chair
Jing Pang, Ph. D.
__________________________________, Second Reader
Preetham Kumar, Ph. D.
____________________________
Date
ii
Student: Manan Shaileshkumar Shah
I certify that this student has met the requirements for format contained in the University
format manual, and that this project is suitable for shelving in the Library and credit is to
be awarded for the Project.
__________________________, Graduate Coordinator
________________
Preetham Kumar, Ph. D.
Date
Department of Electrical and Electronic Engineering
iii
Abstract
of
LINE FOLLOWING AND OBSTACLE AVOIDING CAR
by
Manan Shaileshkumar Shah
Robots are becoming important in various fields. Robots can help humans in places
where human access is limited, like deep-sea exploration, hazardous waste site, and
thermal/nuclear power plants. Path tracing and obstacle avoiding robots are intelligent
robots that can perform desired tasks in unstructured environments by finding and
avoiding them without any human guidance. The purpose of this project is to design
autonomously driven car, which can perform path tracing and obstacle avoiding
controlled by microcontroller. IR sensors track the path and ping ultrasonic sensor sense
the obstacle on the line path. If there is any obstacle, the car will automatically divert its
position to left or right. This project is very useful for industries where automated
supervision is required.
_______________________, Committee Chair
Jing Pang, Ph. D.
_______________________
Date
iv
ACKNOWLEDGMENTS
With all due respect, I would like to thank my project advisor, Dr. Jing Pang for
assigning me very interesting project of Line Following and Object avoiding Car. She has
always encouraged me to work hard. It would be impossible to finish this project without
her valuable time, help, timely guidance and moral support. Her timely advice helped me
reach my goal and finish this project on time.
I would also like to thank Dr. Preetham Kumar for spending his valuable time on
proof reading my project report and giving valuable suggestion.
I would like to thank all my friends especially Nayan Patel, Chandrasekhar
Chukka, Nishith Shah and Siddharth Shah.
In the end, I would like to thank my family members especially my parents for
supporting me during the time of project, and providing constant support and warmth for
me to continue and successfully finish the project.
v
TABLE OF CONTENTS
Page
Acknowledgments..................................................................................................................... v
List of Tables ........................................................................................................................ viii
List of Figures .......................................................................................................................... ix
Chapter
1. INTRODUCTION .............................................................................................................. 1
1.1 Introduction............................................................................................................ 1
1.2 Organization of the Report..................................................................................... 2
2. BASIC DESIGN AND REQUIREMENTS ........................................................................ 3
2.1 Block Diagram ....................................................................................................... 3
2.2 Line Following & Obstacle Avoiding Car structure .............................................. 4
2.2.1 I.R. LED & Phototransistor ................................................................... 4
2.2.2 DC Motors ............................................................................................. 8
2.2.3 Differential Drive Mechanism ............................................................. 10
2.2.4 H-Bridge .............................................................................................. 11
3. ATMEL ATMEGA168 MICROCONTROLLER ............................................................ 16
3.1 Overview .............................................................................................................. 16
3.2 Description ........................................................................................................... 16
3.2.1 Pin Descriptions ................................................................................... 17
3.3 Block Diagram ..................................................................................................... 19
3.4 ATmega168 CCP Modules .................................................................................. 21
4. PING ULTRASONIC RANGE SENSOR ........................................................................ 24
4.1 What is PING Ultrasonic Range Sensor? ............................................................ 24
4.2 Working of Ping Ultrasonic Range Sensor ......................................................... 24
4.3 Practical Applications and Limitations ................................................................ 25
5. DESIGN OF OBSTACLE AVOIDING CAR .................................................................. 27
5.1 Implementation of Obstacle Avoiding Car ......................................................... 28
5.2 Flowchart of the Design ...................................................................................... 28
5.3 Results ................................................................................................................. 30
vi
6. CONCLUSION ................................................................................................................. 34
References…............................................................................................................................ 35
vii
LIST OF TABLES
Page
1.
Table 2.1 DC Geared Motor Specifications.…….…………………………….. 9
2.
Table 2.2 H-Bridge Operation Summary …………………………………...... 12
viii
LIST OF FIGURES
Page
1.
Figure 2.1 Block Diagram of Line Following Car….……………………………. 3
2.
Figure 2.2 IR Transmitter and Receiver..…………………………………..……. 5
3.
Figure 2.3 Line Following with Only One Sensor Pair…………….……………. 6
4.
Figure 2.4 Line Following with More than One Sensor Pair……………………. 7
5.
Figure 2.5 Line Sensor Array………….…………………………………………. 8
6.
Figure 2.6 DFRobot 6V DC Geared Motor...………………..…………………. 10
7.
Figure 2.7 Differential Drive Mechanism………………………………………. 10
8.
Figure 2.8 Ball Caster…………...…….…..……………………………………. 11
9.
Figure 2.9 Basic Structure of a H-Bridge………………………………………. 12
10.
Figure 2.10 Two Basic States of a H-Bridge……………………...……………. 13
11.
Figure 2.11 Transistors as a Switch…..……………...…………………………. 13
12.
Figure 2.12 L293D H-Bridge (Motor Driver)…………………………..………. 14
13.
Figure 2.13 DC Motor Control with H-Bridge…………………………………. 15
14.
Figure 3.1 ATmega168 Pin Configuration……..………………………………. 17
15.
Figure 3.2 External Oscillator Configuration…..………………………………. 19
16.
Figure 3.3 ATmega168 Block Diagram….……..………………………………. 20
17.
Figure 3.4 16-bit Counter/Timer Diagram.……..………………………………. 21
18.
Figure 3.5 TCCR0A Control Register..….……..………………………………. 22
19.
Figure 3.6 TCCR1B Control Register...….……..…………………………...…. 22
ix
20.
Figure 4.1 The Ping Sensor….……..………………………………………...…. 24
21.
Figure 4.2 How the Ping Sensor Works……………………………………...…. 25
22.
Figure 4.3 Limitations of Ping Ultrasonic Sensor…………………………...…. 26
23.
Figure 5.1 Circuit Diagram of Obstacle Avoiding Car……………………...…. 27
24.
Figure 5.2 Flowchart of the Design…………………..……………………...…. 29
25.
Figure 5.3 Line Following Car I.……………………..……………………...…. 30
26.
Figure 5.4 Line Following Car II……………………..……………………...…. 31
27.
Figure 5.5 Object Avoiding Car..……………………..……………………...…. 31
x
1
Chapter 1
INTRODUCTION
1.1 Introduction
Line following car is a system that traces black lines on white surfaces. There are
various sensing methods available to sense these lines. The choice of these schemes
depends upon sensing accuracy and required flexibility. In my project, I have used 6 Tx
LEDs and 6 IR sensors to accurately calculate the position of the robot on the tape.
Sensors keep sensing the line and microcontroller system will keeps maneuvering the
robot to stay on the course. In addition, microcontroller constantly keep correcting wrong
moves using feedback from previous states, making it an effective closed loop system.
The core of the car is ATMEGA168 microcontroller from ATMEL. To detect the
line, 6 IR LEDS (Tx) and 6 IR sensors (Rx) are used with distance between each sensor is
25mm. The Tx will emit the light, this light will be reflected by the black line and Rx will
receive it. These signals will be sent to microcontroller comparator.
There are many ways to move a car [1]. In addition, I used differential steering
method. It relies on two back-wheels, DC motor is connected to each of the two wheels
on the back and front wheels were kept free for easy turning. For forward drive, both
motors are given same voltage. In addition, for right turn, the voltage on the right wheel
needs to be reduced to decrease the rotation of the wheel. Exact opposite is applied for
left turn.
2
1.2 Organization of the Report
Chapter two of the report explains the fundamentals of line following and
Obstacle avoiding car structure. It explains in detail about DC Motors, Differential Drive
Mechanism and H-Bridge.
Chapter three gives information about ATmega168 microcontroller. It
summarizes the features of ATmega168 microcontroller.
It also explains about
timer/counter registers and specific application of those registers in this project.
Chapter four explains about Ping))) ultrasonic sensor used for object detecting
and avoiding. Use of this sensor in this project and the limitations are also discussed.
Chapter five contains information about the implementation of the algorithm for
object avoiding car. It discusses about various steps of algorithm in detail. Suitable
images are also provided to show output at different stages in applied algorithm.
Chapter six presents the result of the project, challenges, limitations and future
applications are discussed.
3
Chapter 2
BASIC DESIGN AND REQUIREMENTS
2.1 Block Diagram
This car it built using ATmega168, IR sensors, Motor Driver (LM293D) and
aluminum chassis [3]. At the bottom, it has line sensor array to detect the line and send
signal to microcontroller for accurate control and steering of motors. Microcontroller
ATmega168 and motor driver L293D are used to control the motors.
Figure 2.1 Block Diagram of Line Following Car
4
Basic operations for line following car are as follows:
1) Capture the black line with the help of mounted sensors on the car. The sensors used
are opto-couplers i.e. they consisting of transmitting and receiving LEDs.
2) Steer the car to track the line with differential steering method. This is achieved by
using two DC geared motors.
2.2 Line Following & Obstacle Avoiding Car Structure
Structure of the line following car can be divided into several parts as follows.
 I.R. LEDs and Phototransistor
 DC geared motors
 Motor Drivers
 ATmega168 microcontroller
 Chassis and body structure
2.2.1 I.R. LED and Phototransistor
Sensors are important components in the process of making line follower [3].
There are different types of sensors available to use for line following car. When
selecting sensors, three characteristics should be kept in mind: response time, sensitivity
and ambient light protection.
As I.R. LEDs have good response time [3], they are used as sensors in this
project. Moreover, they are less sensitive to ambient light. A photodiode has a p-i-n
structure. When an infrared photon of sufficient energy strikes on the diode, it excites an
electron and creates free electron and hole. Due to absorption in depletion region of the
5
junction, holes move toward the anode and electrons move toward the cathode, which
generates photocurrent [4]. The LED and detector have very narrow emission and
detection angles, so their placement is very important. Best method to place them is to
place them in parallel and also close to the track surface. In this case, they are placed
apart by 5-7 mm. Figure 2.2 shows a pair of similar type of I.R LED and sensor.
Figure 2.2 IR Transmitter and Receiver
To get accurate result for line tracing more than one Tx/Rx pairs are used. Use of
fewer numbers of pair will make the car wobble about the line and may not be fast
enough. Figure 2.3 & 2.4 describes this situation in detail.
6
Figure 2.3 Line Following with Only One Sensor Pair [3]
Figure 2.3 shows most basic algorithm of line following, which includes only one
sensor. The sensor is placed on the right. When sensor detects no line, it will move the
car to the left, after this, when sensor detects the line, it will move the car to right. As a
result, the car with algorithm will wobble along the line and the detection speed will also
be slow. [3]
7
Figure 2.4 Line Following with more than One Sensor Pair [3]
The modification of the method used as in Figure 2.3 is to use more number of
sensors. If the sensors are used on the both side of the line as shown in Figure 2.4, then
8
line detection will be less wavering along the line. So if left sensor senses the line then it
will move the car on the left and if right sensor sense the line then it will move the car on
the right [3]. To get more precise line tracing result, Line Sensor Array is used. In this
project, 7 sensors are totally used. They are placed in the form shown in Figure 2.5. The
sensors are mounted on a seperated board along with the biasing amplifiers and a power
is provided with 2 pin connector. Output of each sensor is connected to the main board
via an 8-pin connector to the comparators on the main board. To prevent the interference
among IR sensor, each receiving sensor is covered with black tape.
Figure 2.5 Line Sensor Array
2.2.2 DC Motors
DC motors are widely used, inexpensive, small and poweful for their size. They
are most easy to control. One DC motor requires only two singals for its operation. They
are non-polarized, means you can reverse the voltage without any damage to motor. DC
motors have +ve and –ve leads. Connecting them to a DC voltage source moves motor in
one direction (clockwise) and by reversing the polarity, the DC motor will move in
9
opposite direction (counter clockwise). The maximum speed of DC motor is specified in
rpm (rotation per minute). It has two rpms: no load and loaded. The rpm is reduces when
moving a load or decreases when load increases. Other specifications of DC motors are
voltage and current ratings. Table 2.1 shows the specifications of the motor used in the
project.
Characterisitcs
Operating Voltage
Operating Current
Speed
Torque
Value
3V to 6 V
3A Max.
180 RPM
30 gm-cm
Table 2.1 DC Geared Motor Specifications
Speed of the motor can be changed by changing the applied voltage across motor.
DC motors don’t have enough torque to drive the car directly by connecting wheels with
it. As noticed in table 2.1, the torque provide can hardly move 30 gm of weight. This is
not acceptable if requred load capacity is in Kgs. To achieve more torque by gears, the
speed will be reduced and effectively increase the torque. One more advantage of using
gearbox motors instead of DC motors is it has gears and an axle, so speed does not
change towards uphill or downhill. It is noteable that the more speed is, the less precesion
will be. Figure 2.6 shows the DC geared motor used in this project.
10
Figure 2.6 DFRobot 6V DC Geared Motor
2.2.3 Differential Drive Mechanism
This is the most common locomotion scheme used for building cars. It is a
method of controlling a car with only two polarized wheels. It is easy to build, easy to
control and permits the car to move in all directions. In this method two motors are
connected to each left and right wheels at car’s base. These two motors are responsible of
driving the car in desired direction. This system allows car to spin in its place [6].
Figure 2.7 Differential Drive Mechanism [7]
11
The term “differential” means that car’s turning speed is determined by the speed
difference between both wheels. Figure 2.7 shows in a simplified way the principle of
operation of differential drive. If both motors rotate in the same direction at equal speeds
the car will move forward or backwards based on the rotation of the wheel. If the speed
of one motor is faster then the other, the car will turn in the direction of the slower motor.
If both motor rotates in opposite directions, the car will spin in its place [7].
This kind of two wheel differential drive system needs one or more caster wheels
(free wheels) to support the rest of the chassis while freely following the movement of
the robt engaged by the two main drive wheels. In this perticular project, only one caster
was enough. It is shown in Figure 2.8.
Figure 2.8 Ball Caster
2.2.4 H-Bridge
H-Bridge is an electronic circuit which enables a voltage to be applied on either
side of the load and the H-bridge DC motors allow the car to run backwards or forwards.
H-Bridge is a configuration of 4 switches, which switch in a specific manner to control
the direction of the current through the motor. Figure 2.9 shows simplified H-bridge as
switches. The states of these four switches can be changed in order to change the voltage
across the motor, of the current flow and the rotation of motor [7] [8].
12
Figure 2.9 Basic Structure of a H-Bridge [8]
In Figure 2.9, all switches are open and the motor terminals are disconnected from
the circuit. This state allows the motor to spin freely. If we open switches S1 & S4 and
close S2 & S3 as in first part of Figure 2.10 there will be current flow across the circuit
and motor will run. But if S1, S4 are close and S2, S3 are open, the voltage across the
motor will switch around and that will cause the motor to rotate in the opposite direction.
Table 2.2 summarizes the basic operation of the H-bridge depending upon the voltage
applied across the switches [8].
S1
1
0
0
0
1
S2
0
1
0
1
0
S3
0
1
0
0
1
S4
1
0
0
1
0
Result
Motor moves right
Motor moves left
Motor free runs
Motor brakes
Motor brakes
Table 2.2 H-Bridge Operation Summary [9]
13
Figure 2.10 Two Basic States of a H-Bridge
To control the speed and direction of the DC motor from the microcontroller, this
simple H-bridge will be of no use. H-bridge which make use of transistors works best for
robotics projects. These transistors work as switch and they can control the current flow
in the motor easily. Figure 2.11 shows transistor as a switch.
Figure 2.11 Transistors as a Switch
The difference between the mechanical switch and the transistor switch is that
mechanical switch can be turned on or off mechanically but a transistors switch can be
turned on or off by applying small current at the base. For an NPN transistor, when a
small current of 20mA is applied to the base of the transistor, current will flow from
14
collector to emitter. In case of, for PNP transistor, the current will flow from emitter to
collector. For transistor to work as switch, the applied voltage at base needs to be higher
than collector voltage for NPN transistor and lower than collector voltage for PNP
transistor [9].
In this project, the H-bridge IC used is L293D. “The L293D is a monolithic
integrated, high voltage, high current, 4-channel driver” [10]. The L293D supports two
DC motors. Pin 8 is voltage for the motors and pin 16 is the +5 voltage for the chip. First
motor is connected between pin 3 and 6. The motor is turned on by sending a high signal
to both the enable (pin 1) pin and one of the two direction pins, i.e. pin 2 or pin 7. To stop
motor, the enable pin is high and both pin 2 and pin 7 are low [11].
Figure 2.12 L293D H Bridge (Motor Driver)
The same goes for the other side of the chip. When using two motors, the best
practice is to connect pins 2 and 15 togather and pin 7 and 10. Figure 2.13 shows the
control of the DC motors with L293D and microcontroller signal [11].
15
Figure 2.13 DC Motor Control with H-Bridge [11]
Motor drivers are the simplest modules that provide power amplification for lowlevel control singals like PWM and direction supplied by the user.
16
Chapter 3
ATMEL ATMEGA168 MICROCONTROLLER
3.1 Overview
ATmega168 is widely used because it supports wide range of system
development
tools
such
as
C
Compliers,
Macro
assemblers,
Program
Debugger/Simulators, In-circuit Emulators and Evaluation Kits [2].
Its features includes: 23 general purpose I/O lines, 32 general purpose working
registers, three flexible timer/counters with compare/capture/PWM mode, a SPI serial
port, 16K bytes of in-system programmable Flash with Read-while-Write capabilities.
512 bytes of EEPROM and 1K bytes SRAM. In Idle mode CPU stops working while
allowing the SRAM, timers/counters, USART, SPI port and interrupt system to continue
functioning. It also has 6 channel 10-bit ADC, a programmable watchdog timer with
internal oscillator [2].
3.2 Description
Following diagram shows the detailed pin diagram of the ATmega168.
The device is manufactured using Atmel’s high-density non-volatile memory technology.
“The on-chip ISP flash allows the program memory to be reprogrammed in-system
through an SPI serial interface, by a conventional non-volatile memory programmer, or
by an on chip boot program running the AVR core” [12].
17
Figure 3.1 ATmega168 Pin Configuration [12]
3.2.1 Pin Descriptions
VCC
Digital supply voltage.
GND
Ground voltage for the microcontroller chip.
PORT B (PB7:0)
Port B is an 8-bit bi-directional I/O Port with internal pull-up resistors. As Inputs,
Port B pins that are externally pulled low will source current if the pull-up resistors are
activated [12].
Depending on the clock selection fuse settings, PB6 can be used as input to the
inverting oscillator amplifier and input to the internal clock operating circuit [12].
18
Depending on the clock selection fuse settings, PB7 can be used as output from
inverting oscillating amplifier [12].
PORT C (PC5:0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors. As inputs,
Port C pins that are externally pulled low will source current if the pull-up resistors are
activated [12].
PC6/RESET
If the RSTDISBL register is programmed, PC6 is used as I/O pin. Behavior of
PC6 is different from other Port C pins.
If RSTDISBL is not programmed, PC6 can be used as a Reset input. A low level
on this pin for longer than the minimum pulse length will generate a reset even without
the clock signal. Shorter pulses are not guaranteed to generate a Reset [12].
PORT D (PD7:0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors. As inputs,
Port C pins that are externally pulled low will source current if the pull-up resistors are
activated. The Port D pins become tri-stated if the reset condition become active, even if
the clock is running [12].
AVCC
AVCC is the supply pin for the A/D Convertor, PC[5:0]. It should be externally
connected to VCC, even if the ADC is not used. If the ADC is used it should be connected
to VCC through low pass filter [12].
19
AREF
AREF is an analog reference pin for the A/D convertor.
XTAL1
It is an input to the inverting oscillator amplifier and the internal clock circuit [2].
XTAL2
It is an output pin from the inverting oscillator amplifier.
Oscillator Characteristics
As shown in Figure 3.2, XTAL1 is input and XTAL2 is output of an inverting
amplifier that can be configured for use as an on-chip oscillator. To use external
oscillator as clock source, XTAL2 should be left unconnected while XTAL1 is driven.
Quartz crystal or ceramic resonator can be used as oscillator.
Figure 3.2 External Oscillator Configuration
3.3 Block Diagram
Figure 3.2 shows the block diagram of the ATMEL ATmega168 microcontroller.
The AVR core has 32 general-purpose registers. All these registers are directly connected
to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in
20
one single instruction executed in one clock cycle. The resulting architecture is code
efficient [12]
Figure 3.3 ATmega168 Block Diagram
The device is manufactured using Atmel’s high-density non-volatile memory
technology. “The on-chip ISP flash allows the program memory to be reprogrammed insystem through an SPI serial interface, by a conventional non-volatile memory
programmer, or by an on chip boot program running the AVR core” [12].
21
3.4 ATmega168 CCP Modules
Each CCP (Capture/Compare/PWM) module contains a 16-bit register which can
be operate as 16-bit capture register, as a 16-bit compare register or as a 16-bit PWM
master/slave duty cycle register. The CCP modules are identical in operation, with the
exception of the operation of the special event trigger [12].
Most registers and bit references for this IC are written in general form. For
example, a lower case “n” replaces the Timer/Counter number, and a lower case “x”
replaces the output compare unit channel. When these registers or bits are defined in a
program, they are declared as TCNT2 for accessing Timer/Counter2 counter value and so
on. Figure 3.3 shows a block diagram for the 16-bit Timer/Counter [12].
Figure 3.4 16-bit Counter/Timer Diagram [12]
22
3.4.1 Registers
TCCR1A – Timer/Counter1 Control Register A
Figure 3.5 TCCR0A Control Register
Bit [7:6] – COM1A1:0 Compare Output Mode for Channel A
Bit [5:4] - COM1B1:0 Compare Output Mode for Channel B
For this project, TCCR1A register value is changing many times. Main function
used was to drive the motor in forward and reverse direction. For forward direction,
TCCR1A is set to 0x81. As a result the value of WGM[13:10] is “0101”. With this value,
the timer/counter will work in 8-bit Fast PWM and the value of COM1A[1:0] value is set
to “10” to clear OC1A port upon the compare match. For reverse driving TCCR1A is set
to 0x21 with same 8-bit Fast PWM mode. To stop the motor TCCR1A is set to 0x00.
TCCR1B – Timer/Counter1 Control Register A
Figure 3.6 TCCR1B Control Register
Bit [0:2] – CS[10:12] Clock Select Bits
For this project, I did not use any scaling of the clock. CS[10:12] is set to “001”.
23
Bit [4:3] – WGM[13:12] Waveform Generation Mode
These bits are used in conjunction with TCCR1A Control Register bits
WGM[11:10] to set the timer/counter mode as 8-bit Fast PWM.
24
Chapter 4
PING ULTRASONIC RANGE SENSOR
4.1 What is PING Ultrasonic Range Sensor?
The Ping Sensor is a device to measure the distance between sensor and the
object. With a range of 3 centimeters to 3 meters, it is easy to use in most of the robotics
projects that involve distance measure or object avoiding. Its accuracy is half centimeter
that means it can easily detect the object’s distance. Figure 4.1 shows PING Ultrasonic
Sensor [13].
Figure 4.1 The Ping Sensor [13]
4.2 Working of Ping Ultrasonic Range Sensor
Figure 4.2 shows how the Ping sensor sends a brief chirp with its ultrasonic
speaker and makes it possible for the basic stamp to measure the time it takes the echo
from the object to reach the microphone of the sensor. Controller will send a signal to
Ping sensor to start the measurement. Then, the Ping sensor waits for the controller to
start the Pulsein command. At the same time, the sensor will chirp 40 kHz tone and sends
high signal to the controller.
25
Figure 4.2 How the Ping Sensor Works [13]
When ping sensor detects the echo with its ultrasonic microphone, it changes that
high signal back to low, and the controller will store the time signal high pulse
information. That time measurement tells how long it takes sound to travel to the object
and back. With this measurement, the speed of light can be considered as reference and
the distance of the object can be measured in the desired unit (centimeter, feet etc…)
[13].
4.3 Practical Applications and Limitations
Being an Ultrasonic range sensor, Ping is really useful in various applications
such as measuring the distance of the object, then based upon distance measuring or
detecting obstacle, object avoidance can be implemented too. It can use to implement
maze-solving car [13].
When using Ping ultrasonic range sensor, position of the target object is also
important. If the object is placed as shown in Figure 4.3, then Ping microphone will not
be able to hear the reflected signal and the object detection will be a problem. Also even
if the distance between object and receiver is more than 3 meters, the object detection
26
will be a problem. Also, if Ping detector is placed very low near the surface, then it may
detect sound reflecting off the floor [13].
Figure 4.3 Limitations of Ping Ultrasonic Sensor
Moreover, the target object material also plays an important role when using Ping
ultrasonic sensor. Sound absorbing objects, objects with soft or irregular surface such as
stuffed animals and pillows may not reflect the sound with enough intensity to make
detection easy. Ping detector should not be used outside in wet environment.
“Condensation on its transducers may reduce its lifespan” [13].
27
Chapter 5
DESIGN OF OBSTACLE AVOIDING CAR
This chapter describes the behavior and architecture of the obstacle-avoiding car.
In this project, the car follows the black track using line following sensors and it also
look for the objects/obstacles coming on the path. The car will choose its own path
whereby if it meets obstacle on the path. Ping ultrasonic sensor helps measuring the
distance between the object and help in making turn.
Figure 5.1 shows the circuit diagram for the obstacle-avoiding car, Ping ultrasonic
sensor will chirp the sound at 38 KHz, but it is inaudible to human ears. Once it sends the
sound signal out, it will send high signal to INT0 pin of the controller to set the interrupt
control bit “1”.
Figure 5.1 Circuit Diagram of Obstacle Avoiding Car
28
The microphone of the ping ultrasonic sensor waits for the reflecting signal from
the object. Once it receives the echo, it will send a signal to INT0 interrupt to set INT0 to
“0”. Next, the total time for which signal was high will give the distance between sensor
and the object. If that distance is less than 10 cm, then INT0 will send a signal to OC1A
and OC1B registers to change the speed of the motors and so that motor will turn
approximately 90° right. That means the right motor connected to OC1B will rotate at
lower speed then compared to left motor which allows differential drive with right turn.
5.1 Implementation of Obstacle Avoiding Car
Figure 5.1 shows the circuit diagram for the design. In that design Vout pin of the
ultrasonic sensor is connected to pin 4 (INT0) of the microcontroller via 330 ohm
resistor. I used 0.1 μF bypass capacitor on the output pin +5 V of the voltage regulator
L7805 to smooth out the supply voltage to microcontroller. PWM output from
microcontroller is given to pin 2 of the H-bridge. H-Bridge acts as a high power switch.
This H-Bridge switches on and off at PWM frequency and controls the speed of the
motors. There is a LED connected to Vout pin and microcontroller pin so that if there is a
signal then LED will glow and it will indicate the activity of the sensor.
5.2 Flowchart of the Design
Figure 5.2 shows flowchart of the design. When program executes the timerinterrupt routine INT0 is initialized after reset. Ping ultrasonic sensor will transmit the
37Khz wave and it will send high signal to INT0 Interrupt Handler to start the counter.
29
Start
Timer-Interrupt Handler
Transmit Ultrasonic-wave at 37
Khz
No
Receive Echo
Yes
Get input from port C, copy to command
register
Calculate the distance of the Object
Distance < 10
cm ?
Yes
Turn 90
degrees
RIght
No
Continue on Route
Figure 5.2 Flowchart of the Design
Now, ultrasonic microphone will scan for the echo from the object. Once echo is
received, INT0 interrupt pin will be set low. Now the total time difference between the
signal was high will be stored in the register. And the distance between the sensor and
30
object will be calculated in reference to the speed of the light. If the calculated distance is
less than 10 cm, then controller will set OC1A to low which is connected to right motor.
So now the car will take right turn on its axis. Car has successfully avoided the obstacle
and car will continue tracing the path and keep looking for the obstacle.
5.3 Results
Figure 5.3 shows the first part of the project. Sensor array is attached at the
bottom of the car to sense the black line. Breadboard on the top of the car contains the
microcontroller and front part of the car has sensors.
Figure 5.3 Line Following Car I
31
Figure 5.4 Line Following Car II
Figure 5.4 shows the working model of the line following car. The glowing LEDs
shows that the IR sensors have detected the black tape on the floor and these sensors send
32
the data to microcontroller and microcontroller controls the motor speed of the left and
right wheel. It works on the principal of differential drive mechanism.
Figure 5.5 Object Avoiding Car
Figure 5.5 shows the second part of the project, obstacle-avoiding car. Ping
ultrasonic sensor was drawing more power, so instead of giving one 9V DC power supply
to whole car, each part were given different power supply. The code includes the
calculation of the object with the average value calibration because Ping ultrasonic sensor
is calculating distance very rapidly and there may be fluctuation is the result. The time it
took for the ultrasonic wave to travel back from the object will be in microsecond. To
calculate the distance in centimeter I took the median of the sample data taken from the
test. For every 40 cm, it took 2150 microsecond for the ultrasonic wave to comeback.
33
Therefore, distance in centimeter is calculated from the time in microsecond divided by
55.
34
Chapter 6
CONCLUSION
Line following and object avoiding car is successfully completed. Many efforts
were put into design, implementation and days of toil in front of computer writing and
debugging the code. During the project, I did a lot of research work on the architecture
and development with Atmel microcontroller. Also, I became proficient in
microcontroller programming.
In the future, more complicated control of the car can be explored. More
advanced sensors may also be utilized to control the care more accurately.
35
REFERENCES
[1] Callahan, R, "Types of steering systems used on Robots.", (2010, 09),
http://www.ehow.com/list_7374953_types-steering-systems-used-robots.html
[2] David Cook, “Robot Building for Beginners”, 2nd ed., Apress, pp 247-250, January,
2010.
[3] Alexander Stoytchev, "Some Basic Principles of Developmental Robotics", IEEE
Transactions on Autonomous Mental Development, Vol. 1, No. 2, August 2009.
[4] Newport Inc., “Optical Meters and Detectors”, User Guide, pp 1-7, Sept 2009
[5] Pakdaman, M, Sanaatiyan, M.M., “Design and Implementation of Line Follower
Robot”, Proceedings of IEEE conference, pp 2-4, Dec. 2009.
[6] Ikalogic.com, “Robot Driving Mechanism”, Retrieved on November 18, 2010 From
the World Wide Web:
http://www.ikalogic.com/tut_mech_1.php
[7] Icreator.wordpress.com, “Differential Driving Mechanism”, Retrieved on November
10, 2010 From the World Wide Web:
http://icreator.wordpress.com/
[8] Vibhor Gupta, "Working and Analysis of the H – Bridge Motor Driver Circuit
Designed for Wheeled Mobile Robots", IEEE, 2010.
[9] Ikalogic.com, “Robot Driving Mechanism”, Retrieved on November 18, 2010 From
the World Wide Web:
http://www.ikalogic.com/h_bridge_old.php
[10] Luckylarry.co.uk, “DC Motor & H-Bridge Connections”, Retrieved on November
18, 2010 From the World Wide Web:
http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-arduino-and-l293d-chip/
[11] Claudio Miklo, “DC Motor & H-Bridge Connections”, Retrieved on November 18,
2010 From the World Wide Web:
http://www.miklos.blog.br/2009/11/controlar-motores-dc-com-l293d.html
[12] Atmel Corporation, “8-bit Microcontroller with 8K Bytes In-System Programmable
Flash”, pp 1- 6, 109-137, 245-260, September 2007.
[13] Parallax Inc., “PING))) Ultrasonic Sensor”, pp 1- 6, September 2007.
Download