0% found this document useful (0 votes)
121 views

Object Detection Using Ultrasonic

This document describes an ultrasonic range finder project using an ATmega microcontroller. It uses ultrasonic transducers to transmit and receive ultrasonic pulses to measure the distance between the transducers and an object. The ATmega microcontroller calculates the distance based on the speed of sound and the time taken for the ultrasonic pulse to travel and return. It then displays the measured distance on an LCD module. The project aims to precisely measure distances between 0.5m to 4m with 1cm accuracy.

Uploaded by

Nimmu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Object Detection Using Ultrasonic

This document describes an ultrasonic range finder project using an ATmega microcontroller. It uses ultrasonic transducers to transmit and receive ultrasonic pulses to measure the distance between the transducers and an object. The ATmega microcontroller calculates the distance based on the speed of sound and the time taken for the ultrasonic pulse to travel and return. It then displays the measured distance on an LCD module. The project aims to precisely measure distances between 0.5m to 4m with 1cm accuracy.

Uploaded by

Nimmu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

ATMEGA ULTRASONIC RANGE FINDER

FAKHRUL ADLEE BIN NOOR AZAN

A project report submitted in partial fulfilment of the


requirements for the award of the degree of
Bachelor of Engineering (Electrical – Electronics)

Faculty of Electrical Engineering


UniversitiTeknologi Malaysia

JUNE 2013
ii

I declare that this project report entitled “ATMEGA ULTRASONIC RANGE


FINDER” is the result of my own research except as cited in references. The project
report has not been accepted for any degree and is not currently submitted in
candidature of any degree.

Signature : .......................................................................
Name : FAKHRUL ADLEE BIN NOOR AZAN
Date : 26 JUNE 2013
iii

".....To my beloved late grandfather, my grandmother, my parents,


my family members, and also my friends.
Thanks for all of your support....."
iv

ACKNOWLEDGEMENTS

First of all, I would like to express my deepest gratitude to my supervisor,


En.Zuraimi bin Yahya for giving me a chance to work with him. His guidance,
advices and encouragement has lead to the fruitful completion of the project. I’ve
learnt not only in academicwise but also in philosophies of life. All these have
unleashed my potential which pushes me to greater height.

I would like to convey my gratefulness and appreciation to those who have


helped me directly or indirectly especially my friends and my classmate. The project
and thesis would not be concrete without their help, patience and dedication.

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

Manual distance measuring is always done at the expense of human error.


Precise and fix measurement of low range distance, is the main objective for this
project. This device can measure distance in the range of 0.5m to 4m with the
accuracy of1cm.This project is used to measure the distance by using ultrasonic
sensors. It works by transmitting an ultrasonic waves at 40 kHz. Then, the tranducers
will measure the amount of time taken for a pulse of sound travel to a particular
surfaces and return as the reflected echo. After that, the circuit that have been
programmed with ATmega microcontroller will calculate the distance based on the
speed of sound at 25°C which an ambient temperature and also the time taken. The
distance then will be display on a LCD module.
vi

ABSTRAK

Pengukur jarak secara manual sentiasa dilakukan dengan mengorbankan ralat


manusia. Ketepatan dan ketetapan ukuran dari julat jarak yang dekat merupakan
objektif utama untuk projek ini. Alat ini boleh mengukur jarak dalam julat 0.5 m ke
4 m dengan ketepatan 1 cm. Projek ini digunakan untuk mengukur jarak dengan
menggunakan pengesan ultrasonik. Ia berfungsi dengan menghantar satu gelombang
ultrasonik pada frekuensi 40 kHz. Kemudian, transducer akan mengukur jumlah
masa yang diambil untuk nadi bunyi bergerak ke permukaan tertentu dan kembali
sebagai gema pantulan. Selepas itu, litar yang telah diprogramkan dengan pengawal
mikro ATmega akan mengira jarak berdasarkan kelajuan bunyi pada suhu 25° C
iaitu suhu persekitaran dan juga dengan menggunakan jumlah masa yang telah
diambil. Jarak yang dikira akan dipaparkan di modul LCD.
vii

TABLE OF CONTENTS

CHAPTER TITLE PAGE

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

2 BACKGROUND AND LITERATURE REVIEW 3


2.1 Overview 3
2.2 Ultrasonic Waves 3
2.3 Ultrasonic Transducer 4
2.4 Ultrasonic Transmitter 5
2.5 555 Timer 6
2.6 Ultrasonic Receiver 8
2.7 Atmega 8951 Microcontroller 9
2.7.1 Instruction Set 10

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

7 TESTING AND RESULTS 43


7.1 System Testing 43

8 CONCLUSION 47
8.1 Concluding Remark 47

REFERENCES 48
ix

LIST OF TABLES

TABLE NO. TITLE PAGE

2.1 Datasheet Of 555 Timer 7


4.1 Timeline For Working Progress 20
6.1 Speed Of Sound At Different Temperature 38
6.2 The Ultrasonic Wave Speed Through Different Medium 40
7.1 Distance Measurement With Error 44
x

LIST OF FIGURES

FIGURE NO. TITLE PAGE

2.1 Ultrasonic Transmitter And Receiver Pair 4


2.2 Ultrasonic Transmitter And Receiver
Used In This Project 4
2.3 The Transmitter Circuit Design 5
2.4 The 555 Timer Block Diagram 6
2.5 The Receiver Circuit Design 8
2.6 The Microcontroller Top View 9
2.7 ATmega 8951 Microcontroller Used In This Project 12
2.8 The Block Diagram Of AT89S51 Microcontroller 14
4.1 Flowchart Of Whole Project 19
5.1 Circuit Diagram Of ISP Programmer Interface 25
5.2 Main Screen Of The ISP Programer 26
5.3 Flowchart Of The Project For Obtaining The Distance 27
5.4 Printed Circuit Board Diagram Of The Circuit 30
5.5 Circuit Design With Components 31
5.6 Complete Circuit 32
6.1 Geometric Approximation Of The Ultrasonic
Beam Width 36
6.2 Beam Pattern With Respect To Amplitude 37
6.3 Sample Of Accuracy 42
7.1 ATmega Ultrasonic Range Finder Demonstration 45
7.2 The Display Of The Distance From Black Box 45
xi

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

APPENDIX TITLE PAGE

A C Language ForATmega Ultrasonic Range Finder 49-54


CHAPTER 1

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.2 Problem Statement

Nowadays, we have some difficulties in obtaining the distance that we want


to measure. Eventhough, we have a measuring tape, but this kind of tool will have a
limit for us to measure a distance. Before this, engineers have produce a range finder
module but in the end, they find out the module have many disadvantages like
limitation for distance, different result for different coloured obstacles, and need a
calibration for everytime before starts using it.
2

1.3 Objectives

From the issues that have been discussed in the previous section, the
objectives of this project were set out as below :

1. Precise and fix measurement of low range distance

2. To measure a distance at any obstacles.

3. Operating range of 0.5m up to 4 m with an accuracy of 1 cm.

4. Design a simple circuit and find a suitable hardware for this project.

1.4 Scope of Work

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

BACKGROUND AND LITERATURE REVIEW

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.

2.2 Ultrasonic Waves

There is a reason of why we used ultrasonic waves instead of another waves.


First of all, it is because of its speed. Ultrasonic waves travelled at speed of sound
which is, 343 m/s. this kind of speed is not too fast for MCU’s in ATmega to
measure accurately. So, practically it will take about 20 ns ( nano second ) to go and
bounce back from an obstacle which is 3 m away. Next, ultrasonic waves travels
more narrow, like beam than normal sound wave. This actually helps the sensor
detect the obstacles that are exactly in line with it only. Besides that, ultrasonic
waves do not disturb any humans that is nearby.
4

2.3 Ultrasonic Transducer

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.1 :Ultrasonic Transmitter And Receiver Pair

Figure 2.2 :Ultrasonic Transmitter And Receiver Pair Used In This Project.
5

2.4 Ultrasonic Transmitter

The transmitter consists of an electronics circuitry and an electromechanical


transducer.The electronic circuitry generates the required frequency electrical signal
and the electromechanical transducer converts that electrical signal into the physical
form and activates the open medium surface. This oscillating physical surface
creates the ultrasonic Waves. The oscillating surface creates a pressure variation and
ultimately a pressure wave with a frequency equal to that of the surface oscillation.

Figure 2.3: The transmitter circuit design.

The transmitter was designed to oscillate at a resonant frequency of about 40


KHz. The 555 timer generates a 40 KHz sinusoidal ultrasonic wave.
6

2.5 555 Timer

The 555 monolithic timing circuits is highly stable controller capable of


producing accurate time delays, or oscillation .In the delay time of operation, the
time is precisely controlled by one external resistor and capacitor .For a stable
operation as an oscillator, the free running frequency and the duty cycle are both
accurately controlled with two external resistors and one capacitor.

Figure 2.4 :The 555 timer block diagram.


7

The Table 2.1 shows the datasheet of the 555 timer, the parameter rating and
the units characterized by each component.

Table 2.1 : Datasheet of the 555 timer


Symbol Parameter Rating Unit

VCC Supply Voltage +16 V

Maximum allowable
Pd 600 mW
power dissipation

Operating ambient
TA 0 to 70 ºC
temperature range

VTH(Vcc = 5v) Threshold voltage 3.33 V

VTRIG(Vcc = 5v) Trigger Voltage 1.67 V

VRESET Reset Voltage 0.3 to 1.0 V


8

2.6 Ultrasonic Receiver

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.

Figure 2.5 : The receiver circuit design.


9

2.7 AT89S51 Microcontroller

The microcontroller is used to generate 40 kHz sound pulse. It reads when


the echo arrives, it finds the time taken in microseconds for to and from travel of
sound waves. Using velocity of 330 m/s, it does the calculations and shows on the
LCD Module and display the distance in centimetres. It used In-System
programming (ISP) to be programmed and this programmer will be elaborate more
in chapter 5.

Figure 2.6 : The microcontroller top view.


10

2.7.1 Instruction Set

51 in AT89S51 means that this microcontroller have 51 instruction set.


Instruction set is a subroutine that have been used in order to complete any process
using microcontroller. But not all the 51 instruction set have been used in certain
projects. There are a few instruction set which is popular and always been used to
generate algorithms,moving or to do another functions.

ACALL - Absolute Call

ACALL unconditionally calls a subroutine at the indicated code address.


ACALL pushes the address of the instruction that follows ACALL onto the stack,
least-significant-byte first, most-significant-byte second. The Program Counter is
then updated so that program execution continues at the indicated 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 ACALL instruction, and replacing
bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate
the page. Bits 3-7 of the most-significant-byte of the Program Counter remain
unchaged.

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 - Absolute Jump

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 - Compare and Jump If Not Equal

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 - Clear Register

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.

CPL - Complement Register

CPL complements operand, leaving the result in operand. If operand is a


single bit then the state of the bit will be reversed. If operand is the Accumulator
then all the bits in the Accumulator will be reversed. This can be thought of as
"Accumulator Logical Exclusive OR 255" or as "255-Accumulator." If
the operand refers to a bit of an output Port, the value that will be complemented is
based on the last value written to that bit, not the last value read from it.

DIV – Divide Accumulator by B

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.

DJNZ - Decrement and Jump if Not Zero

DJNZ decrements the value of register by 1. If the initial value of register is


0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new value
of register is not 0 the program will branch to the address indicated by relative addr.
If the new value of register is 0 program flow continues with the instruction
following the DJNZ instruction.
12

INC - Increment Register

INC increments the value of register by 1. If the initial value of register is


255 (0xFF Hex), incrementing the value will cause it to reset to 0. Note: The Carry
Flag is NOT set when the value "rolls over" from 255 to 0.

JBC - Jump if Bit Set and Clear Bit

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.

Figure 2.7 :Atmega 8951 Microcontroller Used In This Project.

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

Figure 2.8 : The block diagram of AT89S51 microcontroller


CHAPTER 3

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

3.2 Scope of Study

Designing complete model of ATmega Ultrasonic Range Finder nearly


impossible for this project because time constraint and limited resources. Scope of
this project narrowed into few items as follow:
 Transmission of ultrasonic waves.

 ATmega programming for arithmetic operation.

 Measurement of a distance from any obstacles.

With this smaller scope of study the realization of the project objective
become achievable.

3.3 Review on Previous Research

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 :

 Sharp GP2D12 Distance Measurement Sensor has a maximum range


of 80cm.
 GP2D120 Distance Measurement Sensor has a maximum range of
30cm only.
17

3.4 Selection of Methodology

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.

3.5 Research Technique

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

4.2 Flowchart Of The Project

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.

Figure 4.1 : Flowchart Of Whole Project


20

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.

Week 1 Week 2 – Week 5 – Week 8 –


Week 4 week 7 week 11


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

Week 12 Week 13- – Week 15


Week 14


Test the project.

√ √
Check all the errors
found and fix all the
problems.


Prepare for
presentations and
demonstration.

Table 4.1 : Timeline for working process


CHAPTER 5

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.

5.2 Circuit Description

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.

Microcontroller AT89S51is at the heart of the circuit. Port-1 pins P1.7


through P1.2, and port-3 pin P3.7 are connected to input pins 1 through 7 of current
buffer, respectively. These pins are pulled up with a 10-kilo-ohm resistor network.
They drive all the segments of the LCD module display with the help of
inverter.Microcontroller AT89S51 provides the segment data and display-enable
signal simultaneously in time-division multiplexed mode for displaying a particular
number on the LCD module.

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.

The comparator is inbuilt in microcontroller AT89S51. The echo signal will


make port-3 pin 3.6 low when it goes above the level of voltage set on pin 13. This
status is sensed by the microcontroller as programmed. When port-3 pin P3.6 goes
high, we know that the echo signal has arrived, the timer is read and the 16-bit
number is divided by twice the velocity of sound and then converted into decimal
format.
24

5.3 The Program

This program is written in C code. It is compiled using the program MicroC


in order to generate the Hex file. In-System programming (ISP) is used as a
programmer to write the coding before being programmed into microcontroller.

5.3.1 In-System Programming (ISP)

ISP is a technique to load hex file in microcontroller without removing


microcontroller from its target. This programmer can be used either for in-system
programming or as a stand-alone spi programmer for Atmel ISP programmable
devices.
25

5.3.2 Hardware Of ISP

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.

Figure 5.1 :Cicuit Diagram Of ISP Programmer Interface


26

5.3.2 Software Of ISP

This software have the main features as follow :


 Read and write the intel hex file

 Read signature, lock and fuse bits

 Clear and fill memory buffer

 Reload current hex file

 Auto detection of hardware

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.

Figure 5.2 : Main screen of the ISP programmer


27

5.4 Flowchart

The flowchart below show for obtaining the time taken before the distance
will be calculate.
28

Figure 5.3 : Flowchart of the project obtaining the distance


29

5.5 C Language

C language or in simple word we call as coding is written in ISP. Then, we


need to connect the ISPprogrammer with computer or laptop by using USB cable.
After that, we programmed the coding that we have written earlier inside the
microcontroller. The assembly language is shown at Appendix A.

5.6 Circuit Design

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

Figure 5.4 :The printed circuit board diagram of the circuit


31

Figure 5.5 :Schematic diagram of the circuit


32

Figure 5.6 : Complete circuit

Here is list of all components used in this project. There are resistors,
capacitors, IC and sockets, diode, transistors, switches and heat sink.

 100Ω resistor, 1.8 kΩ resistor, 3 kΩ resistor, 10 kΩ resistor, 12 kΩ


resistor, 470 kΩ resistor (1 unit)

 390Ω resistor, 120 kΩ resistor (2 units)

 1kΩ resistor (3 units)

 0.02 µF capacitor, 10 µF capacitor (1 unit)

 0.001 µF capacitor, 0.01 µF capacitor, 100 µF capacitor (2 units)

 LM7805 (+5V IC Voltage Regulator)


33

 AT8951 (Microcontroller)

 NE555 (Timer)

 LM393 (comparator amplifier)

 8 pin IC socket (2 units), 16 pin IC socket ( 1 unit), 40 pin IC socket


(1 unit)

 1 Ampere diode, LED, PNP transistor, NPN transistor, 12 MHz


crystal resonator, 40 kHz ultrasonic transmitter and receiver, buzzer,
LCD Module, switches and 8 way DIP switch.
CHAPTER 6

SYSTEM IMPLEMENTATION

6.1 Factors Affecting The Performance Of Ultrasonic Sensors

Position/distance measurement using ultrasonic sensors is based on the


principle of measuring the time of flight of the ultrasonic waves in a particular
medium. There are number of factors which affect the accuracy of measurement and
therefore should be taken into consideration while designing the ultrasonic sensing
system. The following are some of the factors.
35

6.1.1 Radiation Pattern

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 Ω)

D = spot diameter in centimeters.


R = target range in centimeters.
Ω = beam angle in degrees.
At minimum range, R = 50 cm and Ω = 30º.
D = 2 * 50 * tan (15º) = 26.795 cm.
At maximum range, R = 400 cm and Ω = 30º.
D = 2 * 400 * tan (15º) = 214.359 cm.

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.

Figure 6.1: Geometric approximation of the ultrasonic beam width.


37

Figure 6.2: Beam pattern with respect to amplitude.

6.2 Environmental Factors

The attenuation of sound power depends on the speed of sound, which


depends on many environmental factors like temperature, medium, pressure,
humidity, acoustic interference, radio frequency interference.

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

Table 6.1:The speed of sound at different temperature.

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

6.2.2 Pressure And Humidity

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

Medium Speed, m/s at 10°C

Air 331.5

Ammonia 414.8

Argon 301.9

Carbon Dioxide 257.8 (low frequency)

Carbon Disulfide 184.7

Carbon Monoxide 337.1

Chlorine 205.4

Ethylene 313.9

Helium 969.8

Hydrogen 1269.4

Illuminating Gas 490.4

Methane 431.9

Neon 434.9

Nitric Oxide 324.9

Nitrogen 334.06

Nitrous Oxide 261.8

Oxygen 317.2

Table6.2 :The ultrasonic wave speed through different mediums


41

6.3 Noise

The output of the sensor involves noise, which is primarily introduced


because of the uncertainty of the echo which might comes back from the false
object/target. Also the attenuation of the sonic burst depends on the position of the
object/target in the lobe region.

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

TESTING AND RESULTS

7.1 System Testing

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 = [ (Estimate - Actual) / Actual ] X 100%

% 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 = [ (1875- 1910) / 1875] x 100 %

% error = 1.87 %
44

Real measurements Device measurements Error in cm


in cm
in cm

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

Table 7.1:Distance measurement with its error.


45

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.

A test to measure a distance which is more than 4 m also have been


conducted, but this AT89S51 Ultrasonic Range Finder gives high percentage of error
and sometimes the LCD Module will turn off due to over limit calculation inside the
circuit.
CHAPTER 8

CONCLUSION

8.1 Concluding Remark

During the process of designing and implementing the AT89S51 Ultrasonic


Range Finder, we can see that there were some criteriasthat very important..
Understanding the concept of the project and discipline were the most important
part, besides dividing the project into several parts related to each other, managing
the time of completing the project. Each specific part and work need to be done
according to the planin Chapter 4 and in the end all the work was combined into a
whole working project.

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

The importance of the project is calculating accurate distance from any


obstacle that we want to measure. The device can be used in many different fields
and categories like distance calculation in construction field, robots, car sensor to
avoid obstacles and many other applications. The building process of the device
was based on using as much as possible from the courses taken in the university, like
Micro Processor, Basic Electrical Engineering, Multimedia and systems and
Electronics Devices and also practical work in the laboratories.
48

REFERENCES

1. An Ultrasonic Range Finder Designed for an Autonomous Vehicle


Navigation System - by JiqiuSai
2. Robotic Exploration and Landmark Determination: Hardware-
Efficient Algorithms and FPGA Implementations – by
K. Sridharan, Panakala Rajesh Kumar
3. http://www.zembedded.com/interfacing-ultrasonic-rangefinder-with-
avr-mcus-avr-
4. http://www.parallax.com/tabid/768/productid/92/default.aspx
5. http://www.futurlec.com/AT89LP4052_Controller.shtml
49

APPENDIX A

C LANGUAGE FOR ATMEGA ULTRASONIC RANGE FINDER

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define lcd_port PORTD

#define LCD_EN 0x80

#define LCD_RS 0x20

unsignedint count, dist, temp, t; //count the number of


40kHz pulses, 1 pulse=2
count
--------------------------------------------------------------
void command (char cmd)
{
DDRD = 0XFF;
lcd_port = ((cmd>> 4) &amp; 0x0F)|LCD_EN;
lcd_Port = ((cmd>> 4) &amp; 0x0F;
_delay_ms(1);
lcd_port = (cmd&amp; 0x0F)|LCD_EN;
lcd_port = (cmd&amp; 0x0F);

_delay_ms(1);
}
50

--------------------------------------------------------------
voiddatawr (char dat)
{
lcd_port = (((dat>> 4) &amp; 0x0F)|LCD_EN|LCD_RS);
lcd_port = (((dat>> 4) &amp; 0x0F)|LCD_RS);
_delay_ms(1);
lcd_port = ((dat&amp; 0x0F)|LCD_EN|LCD_RS);
lcd_port = ((dat&amp; 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

TCCR2 |= (1 << CS20); //start timer at Fcpu/1


for(;;)
{
53

if ((PINB&amp; 0x02) &amp;&amp; (count>=4))


//if pulse is received
after sending 2 pulses
{
t = 4;
temp= TCNT1;
dist=
(int)((double)((temp*0.0000125*34000))/2);
//calculate the
distance in cm and
speed of sound is
340 m/s
temp=dist;
while (t!=0) //print the distance
in four digits from
right to the left
on lcd
{
datawr((temp%10) + 0x30);
temp = temp/10;
t--;
}
count = 0;
}
if(TCNT1 > 20000) //if signal does not
received, reset the
count and send pulse
again about 1.2ms
{
TCNT1 = 0;
54

count = 0;
}
}
}

You might also like