Object Detection Using Ultrasonic
Object Detection Using Ultrasonic
JUNE 2013
ii
Signature : .......................................................................
Name : FAKHRUL ADLEE BIN NOOR AZAN
Date : 26 JUNE 2013
iii
ACKNOWLEDGEMENTS
Last but not least, I would like to express my appreciation to my family who
are always there supporting me in all aspects.
v
ABSTRACT
ABSTRAK
TABLE OF CONTENTS
DECLARATION ii
DEDICATION iii
ACKNOWLEDGEMENT iv
ABSTRACT v
ABSTRAK vi
TABLE OF CONTENTS vii
LIST OF TABLES ix
LIST OF FIGURES x
LIST OF SYMBOLS xi
LIST OF APPENDICES xii
1 INTRODUCTION 1
1.1 Introduction 1
1.2 Problem Statement 1
1.3 Objectives 2
1.4 Scope Of Work 2
3 RESEARCH METHODOLOGY 15
3.1 Introduction 15
3.2 Scope Of Study 16
3.3 Review On Previous Research 16
3.4 Section Of Methodology 17
3.5 Research Technique 17
viii
4 PROJECT MANAGEMENT 18
4.1 Introduction 18
4.2 Flowchart Of The Project 19
4.3 Timeline ForWor Progress 20
5 SYSTEM DESIGN 22
5.1 Introduction 22
5.2 Circuit Description 22
5.3 The Program 24
5.3.1 In-System Programming (ISP) 24
5.3.2 Hardware Of ISP 25
5.3.3 Software Of ISP 26
5.4 Flowchart 27
5.5 Assembly Language 29
5.6 Circuit Design 29
6 SYSTEM IMPLEMENTATION 34
6.1 Factors Affecting The Presence Of Ultrasonic Sensor 34
6.1.1 Radiation Pattern 35
6.2 Environmental Factors 37
6.2.1 Temperature 37
6.2.2 Pressure And Humidity 39
6.2.3 Medium 39
6.3 Noise 41
6.4 Errors 41
8 CONCLUSION 47
8.1 Concluding Remark 47
REFERENCES 48
ix
LIST OF TABLES
LIST OF FIGURES
LIST OF SYMBOLS
IC - Intergrated Circuit
µs - micro second
λ - wavelength of sound
m/s - metre per second
ns - nano second
m - metre
Ω - Ohm
kΩ - kilo Ohm
nF - nano Farad
f - frequency
mW - mili Watt
V - Volts
°C - degree Celcius
GND - Ground
RST - reset
kHz - kilo Hertz
MHz - Mega Hertz
xii
LIST OF APPENDICES
INTRODUCTION
1.1 Introduction
This project proposes the implementation of ultrasonic range finder. This first
chapter includes the problem statement, objectives, and scope of the project.
1.3 Objectives
From the issues that have been discussed in the previous section, the
objectives of this project were set out as below :
4. Design a simple circuit and find a suitable hardware for this project.
In this project, the ultrasonic range finder is designed through software and
hardware parts. For software part, we need to create a equation for ATmega
microcontroller calculates the range of distance. The equation is in C language and
we need to assemble it using In-System programming (ISP).
The hardware part is also important for this project. Without the hardware,
we cannot obtain the result as it has important electronic components. For the
hardware part, we need to design a basic and simple circuit besides we need to find a
suitable electronic components.
CHAPTER 2
2.1 Overview
This chapter is meant for the explaining of all the concepts involved in the
project. All major dvices and components used in the project are discussed and
explained below.
Ultrasonic sensors (also known as transceivers when they both send and
receive) work on a principle which evaluate attributes of a target by interpreting the
echoes from radio or sound waves respectively. Ultrasonic sensors generate high
frequency sound waves and evaluate the echo which is received back by the sensor.
Sensors calculate the time interval between sending the signal and receiving the echo
to determine the distance to an object.
Figure 2.2 :Ultrasonic Transmitter And Receiver Pair Used In This Project.
5
The Table 2.1 shows the datasheet of the 555 timer, the parameter rating and
the units characterized by each component.
Maximum allowable
Pd 600 mW
power dissipation
Operating ambient
TA 0 to 70 ºC
temperature range
The receiver also has the same configuration except that it has a receiver
electronic circuitry and a transducer, which converts the ultrasonic sound waves into
an electrical signal. The sound waves travel into the medium and are reflected by an
object in the path of the waves. This reflected wave is then sensed by the receiver,
which actually calculates the time of flight of the signal to find the distance.
ADD and ADDC - Add Accumulator and Add Accumulator With Carry
ADD and ADDC both add the value operand to the value of the
Accumulator, leaving the resulting value in the Accumulator. The value operand is
not affected. ADD and ADDC function identically except that ADDC adds the value
of operand as well as the value of the Carry flag whereas ADD does not add the
Carry flag to the result.
AJMP unconditionally jumps to the indicated code address. The new value
for the Program Counter is calculated by replacing the least-significant-byte of the
Program Counter with the second byte of the AJMP instruction, and replacing bits 0-
2 of the most-significant-byte of the Program Counter with 3 bits that indicate the
page of the byte following the AJMP instruction. Bits 3-7 of the most-significant-
byte of the Program Counter remain unchaged.
11
CJNE compares the value of operand1 and operand2 and branches to the
indicated relative address if operand1 and operand2 are not equal. If the two
operands are equal program flow continues with the instruction following the CJNE
instruction.
CLR clears (sets to 0) all the bit(s) of the indicated register. If the register is a
bit (including the carry bit), only the specified bit is affected. Clearing the
Accumulator sets the Accumulator's value to 0.
Divides the unsigned value of the Accumulator by the unsigned value of the
"B" register. The resulting quotient is placed in the Accumulator and the remainder
is placed in the "B" register.
JBC will branch to the address indicated by reladdr if the bit indicated by bit
addr is set. Before branching to reladdr the instruction will clear the indicated bit. If
the bit is not set program execution continues with the instruction following the JBC
instruction.
There is a reason why we use AT89S51 in this project. First of all, AT89S51
is a low-power, high-performance CMOS 8-bit microcontroller with 4K bytes of In-
System Programmable Flash memory. The device is manufactured using Atmel’s
high density nonvolatile memory technology and is compatible with the industry
13
standard 80C51 instruction set and pinout. The on-chip Flash allows the program
memory to be reprogrammed in-system or by a conventional nonvolatile memory
pro-grammer. By combining a versatile 8-bit CPU with In-System Programmable
Flash on a monolithic chip, the Atmel AT89S51 is a powerful microcontroller which
provides a highly flexible and cost effective solution to many embedded control
applications. The AT89S51 provides the following standard features: 4K bytes of
Flash, 128 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, two 16-
bit timer/counters, a five-vector two level interrupt architecture, a full duplex serial
port, on-chip oscillator, and clock circuitry. In addition, the AT89S51 is designed
with static logic for operation down to zero frequency and supports two software
selectable power saving modes. The Idle Mode stops the CPU while allowing the
RAM, timer/counters, serial port, and interrupt system to continue functioning. The
Power-down mode saves the RAM contents but freezes the oscillator, disabling all
other chip functions until the next external interrupt or hardware reset.
14
RESEARCH METHODOLOGY
3.1 Introduction
This project aim to measure a distance from any obstacles. Besides that, this
project also want to findout a distance from 0.5m up to 4m. The flow of this project
frankly start from the connection of all hardware components and after we done with
all the hardware works, we need to create the coding or C language for the
microcontroller. Actually, the hardest part of this project is to create the assembly
language because we need to find heeqution for microcontroller to to calculate the
distance travel by the ultrasonic waves.
By measuring the time taken for the whole process, it will use the arithmetic
operation that have been programmed in AT89S51 microcontroller in order to obtain
the distance. Lastly, the output will be display at LCD Module.
16
With this smaller scope of study the realization of the project objective
become achievable.
Through reading and research, there are one project or module with similar
field. It is the project made by electronic hobbyists and engineers which is “IR
Range Finder Module”. But in the end, this projects have some lack characteristics
and disadvantageous which is :
Based on this project, it needs two methodologies, which are hardware and
software (C language) parts. For hardware, the work is just to design a circuit and
find a suitable components to make sure this project is successful to produce the
result. Next, for software we need to generate and create a C language for AT89S51
microcontroller.
The programming and coding for the first of all must be test it functionality.
The platform used in this project would be ISP. The simulation should perform the
calculation for a measurement by using the speed of ultrasonic wave and time taken
for the waves to bounce back.. After conforming the functionality of the
programming then we should generate circuit like coding in the ISP.
CHAPTER 4
PROJECT MANAGEMENT
4.1 Introduction
In this chapter, there will be an explaination the flow of this project work and
how the project is working. Actually project management is very important part
because fro there, we can see and check whether our project is going well or not.
19
Flowchart is one of many ways that we can use to show and to make sure that
we are working according to our plan or not. There are several flowchart thati have
create for this project but not all of them will be shown in this chapter.
4.3 TimelineForWorkProgress
Next, is the table for the working progress for this project. This tables
includes my working and the range of time for me to finish the work.
√
Gather all
information
about the
project.
√
Design the basic
circuit of the
project.
√ √
Finish the
hardware work.
√ √
Derive an
equation and
create an C
language for
ATMega
microcontroller.
21
√
Test the project.
√ √
Check all the errors
found and fix all the
problems.
√
Prepare for
presentations and
demonstration.
SYSTEM DESIGN
5.1 Introduction
In this chapter, there will be an explaination about the working of the circuit.
There will be the function of the main components and also a diagrams for a better
understanding.
Figure 5.5 shows the full circuit of this project. The 40kHz pulse bursts from
the microcontroller are amplified by thyristor. Inverting buffer drives the ultrasonic
sensor used as the transmitter. Three inverter are connected parallel to increase the
transmitted power. This inverted output is fed to another set three inverters. Outputs
of both sets parallel inverter are applied as a push-pull drive to the ultrasonic
transmitter.
The positive going pulse is applied to one of the ultrasonic sensor and the
same pulse after 180 degree phase shift is applied to another terminal. Thus the
transmitted power is increased for the increasing the range.
23
The echo signal received by the receiver sensor after reflection is very weak.
It is amplified by operational amplifier. The rectifier functions, unlike a simple
diode, even for signal voltage of less than 0.6V. The output is filtered to accept
40kHz frequencies and fed to pin 12 of microcontroller, which is an analog
comparator.
Segment data and display-enable pulse for the display are refreshed every
5ms. Thus the LCD module appears to be continuously display. Using switch S1 we
can manually reset the microcontroller, while the power on reset signal for the
microcontroller is derived from the combination of capacitor and resistor.A 12MHz
crystal is used to generate the basic clock frequency for the microcontroller.
Figure 5.1 shows the circuit diagram of the In-System programmer (ISP)
interface, where the power to the interface is provided by the PC USB port which
can supply a maximum current of 100 mA. This programmer circuit can be used to
program the 89S series devices and the AVR series devices which are pin compatible
to 8051.
The memory buffer contains both code data and the EEPROM data for the
devices which have eeprom memory. The eeprom memory addres in buffer is started
after the code memory, so it is necessary the hex file should contains the eeprom
start address after the end of the code memory last address. The software does not
provide the erase command because this function is performed automatically during
device programming.
5.4 Flowchart
The flowchart below show for obtaining the time taken before the distance
will be calculate.
28
5.5 C Language
The functionality of this system can be divided into three main parts as
shown in the transmitter, the receiver, the microcontroller and the digital display.
The transmitter, enabled via the microcontroller, is designed to activate a 555
oscillator with a frequency of 40 KHz. The width of the pulse is 0.1 ms, every 40 ms
a pulse is transmitted.
30
Here is list of all components used in this project. There are resistors,
capacitors, IC and sockets, diode, transistors, switches and heat sink.
AT8951 (Microcontroller)
NE555 (Timer)
SYSTEM IMPLEMENTATION
All ultrasonic sensors have their specific radiation pattern associated with it.
Thisacoustic radiation pattern is a function of spatial angle called beam angle. Beam
angle, Ωis defined as the total angle between the points at which the sound power
reduces to half its peak value, commonly known as 3 dB points. The spot diameter of
the beam can be formulated as :
D = 2R tan (0.5 Ω)
Radiation pattern consists of a main lobe and side lobes. Radiation power is
dominant mainly in the front region of the sensor, so as to say that the main lobe is
directly in front of the sensor, followed by side lobes sidewise with null region in
between these lobes. Radiation pattern is mainly determined by factors such as the
frequency of operation and the size, shape and acoustic phase characteristics of the
vibrating surface. The beam pattern of the transducer is independent of its nature as a
transmitter or receiver.
36
In most of the application, side lobes are suppressed and narrow beams are
used. This suppression is achieved by the processing system and so, the radiation
pattern of the transducer may not be same as the radiation pattern of the whole
ultrasonic sensing system.The narrowness of the beam pattern is a function of the
diameter of the radiating surface to the wavelength of the sound at the operating
frequency. As the D/λ ratio increases, beam narrows out whereas as D/λ ratio
decreases, beam broadens. For most of the application narrow beam is desired and
therefore D/λ ratio should be more.Signal processing is actually the board itself. The
board still in the designing process. The board will go through few functionality
process with various signal. After the board pass the wired testing then it will be
integrate with wireless radio module. Again the board will go through few
functionality process with various type of signal.
6.2.1 Temperature
The velocity of sound in a medium varies with temperature. So, the time
taken by the sound to echo back to the receiver will vary and since this time of flight
is proportional to the measured distance. The measured distance will vary with the
variation in temperature. Thus the variation in temperature introduces errors in the
measurement.
38
The sound wave propagation speed in the air depends on the temperature. So,
to measure the distance more correctly, it is necessary to revise according to the
temperature.The sound wave propagation speed can be calculated using one of the
two formulas :
V = 331.5 + 0.6 * T[ m/sec ]
T : The temperature (°C)
Temperature (°C) in
Speed of sound (m/sec)
air
-10 325.5
0 331.5
10 337.5
20 343.5
30 349.5
40 355.5
50 361.5
In this project,the speed of sound used in this program is 340m/s because this
speed is relative to the temperature 20 ºC which is an average value. A temperature
sensor could be added to this project with a small manipulation to the program, in
order to use the right speed value. In this way, this device would be used in all
atmospheric conditions.
39
As the pressure reduces, the density of particle in the medium decreases thus
providing less and less resistance to the traveling wave. Although slightly pressure
effects the velocity of sound wave, humidity which is defined as the moisture
content in the medium basically has a very little effect on the velocity of sound but it
actually effect the radiating surface.The acoustic pressure p must satisfy the three-
dimensional wave equation.
6.2.3 Medium
Velocity of sound depends on the kind of medium the sound travels. Sound
speed varies with different medium. The Table 6.2 summarizes some of the medium
with the sound velocity in it.
40
Air 331.5
Ammonia 414.8
Argon 301.9
Chlorine 205.4
Ethylene 313.9
Helium 969.8
Hydrogen 1269.4
Methane 431.9
Neon 434.9
Nitrogen 334.06
Oxygen 317.2
6.3 Noise
6.4 Errors
In general it is desired to develop the worst case analysis to permit the design
of the hand-held ultrasonic range meter device capable of operation under all
conditions with a minimum error (maximum acceptable error is +/- 3 cm). The errors
associated with both calculations and measurements can be characterized with regard
to their accuracy and precision as shown in Figure 6.3 Accuracy refers to how
closely a computed or measured value agrees with the true value. Precision refers to
how closely individual computed or measured values agree with each other.
42
Figure 6.3: (a) The samples are inaccurate and imprecise. (b) The samples
are accurate and imprecise. (c) The samples are inaccurate and
precise. (d) The samples should be accurate and precise in order
to get the acceptable error.
CHAPTER 7
This experiment was done at a 17 ºC and that increased the error. It consisted
of measuring the distance from the device to a flat wall. Nine measurements were
done in this experiment.
% error = [ ( 50+ 75+ 100 + 150 + 200 + 250 + 300 + 350 + 400 ) – ( 53 + 77 + 103
+ 153 + 204 + 255 + 307 + 355 + 403 ) / ( 50+ 75+ 100 + 150 + 200 + 250 + 300 +
350 + 400 ) ] x 100 %
% error = 1.87 %
44
50 53 +3
75 77 +3
100 103 +3
150 153 +3
200 204 +4
250 255 +5
300 307 +7
350 355 +5
400 403 +3
There are also some figures that i have taken from the demonstration that I
have done before. It shows the distance displayed at the LCD module.
Figure 7.1 :Atmega ultrasonic range finder is calculating the distance from the sensor
to the black box.
Figure 7.2 : The distance from the sensor to the black box is 53 cm.
46
If we refer back to Figure 7.1 and Figure 7.2,we can see that there is a long
ruler and short ruler. For a long ruler, its length is 30 cm while the short ruler’s
length is 15 cm. We add for both ruler’s length and it is qual to 45 cm. There is some
gap between the sensor and the end of short ruler, which means the distance
displayed at the LCD Module is near to the actual length.
From the demonstration and testing value before, this AT89S51 Ultrasonic
Range Finder measure the range of distance from 0.5 m to 4 m with percentage error
of 1.87 %. For the range below than 0.5 m, this AT89S51 Ultrasonic Range Finder
will display no reading value and the buzzer will keep beeping and calculating for
the next distance of any obstacle.
CONCLUSION
From the result in Chapter 7, this AT89S51 Ultrasonic Range Finder have
achieved the objectives of this project. Eventhough it gives some errors, it can be
consider as a useful device. There are some limitation that i have found during the
testing of this project. This AT89S51 Ultrasonic Range Finder will gives accurate
reading of a distance if the obstacle is in black colour. The worst reading that this
AT89S51 Ultrasonic Range Finder gives is for any obstacles which are in white and
transparent such as binding cover and Tupperware.
48
REFERENCES
APPENDIX A
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
_delay_ms(1);
}
50
--------------------------------------------------------------
voiddatawr (char dat)
{
lcd_port = (((dat>> 4) & 0x0F)|LCD_EN|LCD_RS);
lcd_port = (((dat>> 4) & 0x0F)|LCD_RS);
_delay_ms(1);
lcd_port = ((dat& 0x0F)|LCD_EN|LCD_RS);
lcd_port = ((dat& 0x0F)|LCD_RS);
_delay_ms(5);
}
--------------------------------------------------------------
voidlcd_reset(void)
{
DDRD = 0XFF;
_delay_ms(1);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
_delay_ms(1);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
_delay_ms(1);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
_delay_ms(1);
lcd_port= 0x02+LCD_EN;
lcd_port = 0x02;
_delay_ms(1);
}
--------------------------------------------------------------
voidlcd_init (void)
51
{
lcd_reset();
int j=0;
charb[]={0x28,0x0C,0x06,0x80,’\0’;
while (b[j]!=’\0)
{
command(b[j]);
_delay_ms(1);
j++;
}
}
--------------------------------------------------------------
ISR(TIMER2_COMP_vect)
{
if ((count<4)) //send 2 pulse of 40
kHz
{
PORTB ^= (1<<0); //toggle the output at
the PORTB.0
count++;
if (count == 2) //start the timer1 for
time between
transmission and
received after first
pulse
{
TCNT1 = 0
TCCR1B |= (1 << CS10);
}
}
52
//x++;
}
--------------------------------------------------------------
int main(void)
{
count=0;
DDRD= 0XFF;
lcd_init();
unsigned char string[] = “Distance’;
for(int i=0; i<9; i++)
datawr(string[i]);
command(0x04); //to shift the cursor
from right to left
command(0x8D); //to jump to
8D position
DDRB = 0X01; //set PORTB.0 as output
PORTB |= (0<<0);
TCCR2 |= (1 << WGM21); //configure timer 2
for CTC mode
TIMSK |= (1 << OCIE2); //enable CTC interrupt
sei(); //enable global
interrupt
OCR2 = 196; //16000000/40000=400,
therefore current
frequency is 80 kHz
for timer interrupt
count = 0;
}
}
}