Upload
dinhtruc
View
227
Download
5
Embed Size (px)
Citation preview
TRIBHUVAN UNIVERSITY
Institute of Engineering Advanced College of Engineering and Management
Kupondole, Lalitpur
A Final Year Project Report on
“WIRELESS ULTRASOUND FLOOD MONITORING SYSTEM”
[CODE NO.: EG777EX]
BY
Amit Kumar Tamang Exam Roll No: 23005 Kushal Khanal Exam Roll No: 23023 Santosh Kumar Baral Exam Roll No: 23036
Lalitpur, Nepal February, 2008
TRIBHUVAN UNIVERSITY
Institute of Engineering
Advanced College of Engineering and Management Kupondole,Lalitpur
A Final Year Project Report on
“WIRELESS ULTRASOUND FLOOD MONITORING SYSTEM”
[CODE NO.: EG777EX]
BY
Amit Kumar Tamang ([email protected]) Exam Roll No: 23005 Kushal Khanal ([email protected]) Exam Roll No: 23023 Santosh Kumar Baral ([email protected]) Exam Roll No: 23036
A FINAL YEAR PROJECT WORK SUBMITTED TO THE DEPARTMENT OF COMPUTER AND ELECTRONICS ENGINEERING FOR THE PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE DEGREE OF THE BACHELOR’S IN ELECTRONICS AND COMMUNICATION ENGINEERING
Lalitpur,Nepal February, 2008
TRIBHUVAN UNIVERSITY
Institute of Engineering
Advanced College of Engineering and Management Kupondole,Lalitpur
Department of Computer and Electronics Engineering
“WIRELESS ULTRASOUND FLOOD
MONITORING SYSTEM” Being a project submitted in partial fulfillment of the requirements for the degree of Bachelor’s Degree in Electronics and Communication Engineering. In the
Department of Computer and Electronics Engineering Advanced College of Engineering and Management
Tribhuvan University
BY
Amit Kumar Tamang ([email protected]) Exam Roll No: 23005 Kushal Khanal ([email protected]) Exam Roll No: 23023 Santosh Kumar Baral ([email protected]) Exam Roll No: 23036
Lalitpur,Nepal February, 2008
CERTIFICATE
We have pleasure in forwarding the project of Amit Kr.Tamang, Kushal Khanal,
Santosh Kr. Baral entitled “Wireless Flood Monitoring System Using Ultrasound”
for the completion of Bachelor of Engineering in Electronics and Communication of
this institute.
Amit Kr. Tamang, Kushal Khanal, Santosh Kr. Baral have completed the project work
for the full prescribed period under the curriculum, and the project embodied the result
of their investigations conducted during the period they worked as a full time student of
this department.
(Er. Rosish Shakya) (Er.Surya Pd. Aryal)
Supervisor External Examiner
(Er. Nita Koirala) (Er. Dhaneshwar Sah)
Internal Examiner H.O.D of Computer and Electronics
TABLE OF CONTENTS
Title Page Number
Acknowledgements i Abstract ii List of abbreviations iii List of figures iv-v
1. Introduction 1-2
Background 1 Problem Statement 2 Objectives 2
2. Literature Review 3-16
Previous works 3 Related Theory 5
2.2.1 Sound 5 2.2.2 Factors affecting the propagation of sound wave 6 2.2.3 Properties of sound 8 2.2.4 Application of the reflection of sound 9 2.2.5 Ultrasound 9 2.2.6 Doppler’s effect 12 2.2.7 Application of Doppler’s shift 12 2.2.8 Ultrasonic transducer 16 2.2.9 Application of ultrasound 16
3. Methodology 17-72
3.1 System Architecture 17 3.1.1 Transmission 18 3.1.2 Reception 18 3.1.3 Detection 19 3.1.4 Signal holding 19 3.1.5 Pulse Shaping 19 3.1.6 Level Calculation 19 3.1.7 Flow Calculation 19 3.1.8 Display 19 3.1.9 Wireless Module 20
3.2 Description of components 20 3.2.1 Ultrasonic transducers 20
3.2.2 8051 Microcontroller 20 3.2.3 Voltage Regulators 26 3.2.4 Diodes 27 3.2.5 Line driver or Voltage translator 28 3.2.6 DC socket 28 3.2.7 LM833 29
3.2.8 LM358 31 3.2.9 CD4011 31 3.2.10 CD4069 32 3.2.11 74HC04 33
3.2.12 555 Timer 34 3.2.13 LCD 34 3.2.14 RF Modules 34
3.3 Circuit Explanation 36 3.3.1 Power Supply Circuit 36 3.3.2 Transmission Section 36 3.3.3 Reception Section 37 3.3.4 Signal Detection 39 3.3.5 Circuit Diagram 44
3.4 Program in System 46 3.4.1 Flowchart 46 3.4.2 Resolution calculations 53
3.5 Serial Communication 56 3.5.1 Serial data communication in MCU 57 3.5.2 RS232 Protocol 58
3.6 Software & Equipments 59 3.6.1 Proteus 6 Professional 59 3.6.2 MCU programming in C 62 3.6.3 SDCC Compiler 64 3.6.4 Visual Basic 6.0 66 3.6.5 Oscilloscope 68 3.6.6 Digital Multimeter 69
3.7 Problem faced 70
4. Result and Conclusions 73 4.1 Results 73 4.2 Limitation 73 4.2 Conclusion 73 4.3 Future Enhancements 73
References 74 Appendix A: Liquid Crystal Display 75 Appendix B: Keypad interfacing with MCU 79 Appendix C: Cost Analysis 82
i
ACKNOWLEDGEMENTS
First of all we would like to express our sincere thanks to the Department of Computer
and Electronics Engineering, ACEM, for providing us the environment to complete
this final year project successfully.
We would like to record our appreciation to our H.O.D. Er. Dhaneshwor Shah, for his
valuable encouragement throughout the project. His efforts created an environment and
infrastructure to our project.
We express our gratitude to our project Supervisor Er. Rosish Shakya who seriously
helped us from the beginning to the end of our project. He managed us his precious time,
suggestions and continuous effort to support us. We are obliged to Er .Anish Adhikari
and Er. Amit KC for their genuine attempts that they showed to us.
We are extremely obliged to record our heartfelt thanks to our friend Mr. Rajesh
shrestha for his priceless help and guidance in visual basic programming.
We express our appreciation to Mr. Ujwol Napit for his valuable suggestion and Mr.
Dhan Bahadur Magar for his priceless effort during our demonstration.
We would like to express our heartfelt thanks to Project Association of Computer and
Electronics, PACE for valuable support during the project.
We extend our sincere thanks to I.O.E which has given us the opportunity to do this
project which will help us enhance our career.
We would like thank Mr. Ganesh Gautam for cooperating us in various ways. Last but
not the least, we would like to appreciate all of our classmates for their encouragement
and help, they fuelled in us throughout.
Amit Kumar Tamang
Kushal Khanal
Santosh Kumar Baral
ii
ABSTRACT
Our project entitled “Wireless Ultrasound Flood Monitoring System” is designed to
reduce the information gap between the government and the people in case of natural
catastrophes like flood, glacial outburst. We don’t have the Information System till now
that informs people about the possible dangers of those disasters. Each and every year
many people lose their home, property and life. In one hand the government itself has no
information and secondly it has problem in evacuating the people from such site.
Examples are the terror of eruption of glacial lake Chho-Rolpa, Pashupati Bagmati Dam
eruption and various Terai region floods due to the dams built in border side of Indian
territory. Thus we came up with this project. In our project, the level and flow of water is
continuously monitored. Our device can be placed at these sites. Ultrasonic transducer
which generates 40 KHz frequency wave is chosen, that is non hazardous, non audible,
non irritating and it is easily reflected from any medium except air. The level and flow of
water are calculated by the microcontroller controlled site and sent wirelessly to the
remote monitoring station by RF modules. There is also the provision of GUI made by
Visual Basic that helps the operator at site to read out the current values after proper
authentication. There is the facility of Visual display, automatic mode and manual mode
and the information database. The Front End VB GUI is bounded to back end MsAccess
Database via SQL. The statistics for latest ten values for both level and flow can be
visually perceived in plots. Flow uses Doppler’s Shift and level calculation is based on
echo reflection property of waves. The increasing flow hints at the probability of flood
and the increasing level ensures the flood is certain. So the emergency alarming is
performed to the public and the alternative control action such as automatic gate opening
can be performed manually from the monitoring station. Our project is simple, reliable
and economically feasible according to the cost benefit analysis. Thus with
implementation of our project destruction by catastrophes can be drastically reduced .It is
dedicated to the welfare of the public and the government. We have been able to meet our
requirement.
iv
LIST OF FIGURES Figure Number
Title Page Number
2.1 Effect of wind on sound 7 2.2 Illustration of Echo Reflection 9 2.3 A transducer with a circular radiating surface whose diameter is
large in comparison to a wavelength produces a narrow, conical beam pattern with multiple secondary lobes.
11
2.4 Illustration of Doppler’s shift 12 2.5 Application of the Doppler’s shift in Echolocation of a Moving
Object 13
2.6 Ultrasonic transducer 16 3.1 System Block Diagram 17 3.2 Back view of the SQ40T/SQ40R 20 3.3 AT89C51 IC pin description 23 3.4 Minimum connection of 8051 MCU system 26 3.5 Pin description of voltage regulator 7805 & 7809 26 3.6 Figure showing input sine wave and its half wave rectification
using diodes. 27
3.7 Negative voltage protection in the circuitry using diode 27 3.8 Line driver MAX232 28 3.9 Null modem 29 3.10 Dual 8 pin Opamp 30 3.11 Non inverting configuration of an amplifier 31 3.12 Quad NAND gate IC 32 3.13 Logical symbol and truth table of NAND gate 32 3.14 Six NOT gates IC 33 3.15 Logical symbol and truth table of NOT gate 33 3.16 555 timer configuration to generate square wave. 34 3.17 RF modules 35 3.18 Voltage regulators 36 3.19 Astable mode of 555 timer 37 3.20 Circuit to excite ultrasonic transmitter 38 3.21 Opamp as comparator (a) Circuit diagram (b) Timing diagram 40 3.22 SR FF (a) Circuit Diagram (b) Timing diagram 41-42 3.23 Pulse shaping circuit 42
3.24 (a) Schematic of circuit at site 44 3.24 (b) Schematic of circuit at monitoring station 45
3.25 Flowchart for level 47 3.26 Flowchart for flow 47 3.27 Overall Flowchart of the system 49-53 3.28 Waveform of serial data unit 57 3.29 Snap shot of simulation circuit to test the code in Porteus ISIS
professional 61
v
3.30 Designed PCB layout 62 3.31 Snap shot of outlook of EZ-Downloader 65 3.32 Compiling ultrasound.c using SDCC 66 3.33 Snap shot of interfacing form designed using Visual Basic
(a) Manual mode (b) Auto mode 67
3.34 Plots of measured values of level and flow 68 A.1 Structure of 2X16 LCD 76 C.1 Circuit diagram of Keypad 90 C.2 Flowchart for keypad programming 91
Wireless Ultrasound Flood Monitoring System
1
Introduction
1.1 Background Technology is the result of effective technique applied for solving particular problems
with available resources. The technology has made human life easier, safer and more
productive. The life of mankind has become impossible without the technology. Latest
technologies are emerging day by day and one can’t remain aloof without using
technology.
In fact the technology has revolutionized the world. The development of electronics
industries accelerated from 1980s only after the invention of ICs. The invention of ICs
has extensively reduced the size, weight, cost and increased the quality, reliability of
every electronics product. From a simple amplifier radio to satellite communication,
space exploration, electronics products are widely used.
The production of such electronics goods is not simple as we use it. It involves the detail
study of nature, waves, flow of energy, study of available materials, various experiences
and expertise of the past and their modification as per the requirement. It takes a lot of
time, effort and perhaps lifelong dedication of many individuals.
Our final year project is one of the implementation of electronics to make wireless
ultrasound flood monitoring and alarming system. Our project is a microcontroller based
prototype for level and flow measurement of flowing water. The system is mainly
designed to be used at the remote site and for the monitoring purpose. The ultrasonic
transducers are used to measure the liquid level and its flow at suspected place. And
AT89C51/52 is used as MCU. The system consists of RF wireless modules for the data
transmission from the remote site to the remote monitoring station which will indicate
the water level, water flow and useful for flood monitoring. The detail description about
ultrasound and ultrasonic technology, description about the ATMEL AT89C51, software
and hardware description are presented in the sections followings.
Wireless Ultrasound Flood Monitoring System
2
1.2 Problem Statement In Nepal, there is not a single system, which can be used for monitoring and alarming in
case of floods and eruption of glacial lakes. That has resulted in loss of lives and
property especially in Terai and Himalayan region. There is also problem for government
in timely informing and evacuating people form the affected sites, which has multiplied
the casualties.
There have been many cases of visit of environmental inspectors form different nations
to inspect the condition of glacier’s lake and they seem to be very interested rather that
us. For instance the visit of Japanese environmentalist to Solukhumbu’s Imja glacial
lake, PM of Norway observing various glacial lakes in Nepal.
In consideration with above severe problem, we have come up with our design. Our
design can remotely monitor the level and flow of water in suspected site and alarm the
people as per the information given from the site. And we are certain that this system can
serve as a prototype to figure out, the dependencies on the foreigners on such problems.
1.3 Objectives: The main issue of our project is to design a Remote Flood Monitoring and Alarming
System. So, our objectives are:
a. To measure the level of Water
b. To measure the flow of Water
c. To convey the information Wirelessly to the monitoring station
d. To activate the emergency alarming as per the information
Wireless Ultrasound Flood Monitoring System
3
Literature Review
2.1 Previous works Nothing in this world is hundred percent static as lord Buddha said “Everything in this
universe is in the state of flux”. Nothing is ultimate and satisfactory. The nature of
human is to dream and imagine, thus modify available tools and technique, which lead
human to this era.
Technology has revolutionized the life standard of human. We are in the information
age of the 21st century. The role of engineers in this age is certainly of vital importance.
It is of their genuine attempt and aptitude that everyday one more comfortable
technology is in our hand. The change is physiological, psychological, and technological
and persists in each and every aspect of life and environment within which man lives.
Our project entitled “Wireless ultrasound flood monitoring and alarming system” is
not truly original in itself from the very scratch. At different times in the past, many
attempts were continually made by our seniors some of which concepts we have
incorporated from theirs. We came across the reports “Distance measurement using
Ultrasound “that simply illustrated how ultrasound echo- reflection can be used in the
distance measurement. This illustration was limited up to 0.3m in distance and the
resolution was poor. They had used PIC not able to measure the distance of moving
object as well.
The other project that we came across was “Ultrasonic Imaging System” undertaken in
similar concept as the radar pulses they were passed inside the body which reflected
waves in various patterns that gives the various information of different organs of the
body. These waves were slow than x ray naturally. The electronic circuitry of this project
was so poor that it could not deserve the quality of imaging. They had used various
modes such as A-Mode, B-Mode, Doppler’s Mode and M-Mode.
Wireless Ultrasound Flood Monitoring System
4
Next we came across a project work entitled” Wireless PC to PC communication
Using IR Modulation” which was limited to the text files only. They had used data
transfer in asynchronous mode to transfer text files from one PC to another. They had
used IR modulation and demodulation techniques and the data transfer rate was limited
up to maximum rate of 2400bps. The text file was transferred on polling basis rather
than the in interrupt basis.
“Device Control Using IR” was also a project in which 555 timer was used in
modulating the ASCII value pulses and decoding those pulses to perform specified
action depending upon the characters sent at the same rate of 2400 bps.
“Wireless Remote Water Level Monitoring System Using Ultrasound” was a project
by our seniors. This used the Echo -Reflection property of ultrasound. The level of water
was detected by calculating the time elapsed between transmitted and received pulse and
multiplying that time by the standard velocity at that temperature. There was not special
provision of selecting the velocity of sound as per the environmental temperature. The
resolution calculated was so poor that the look up table method was implemented in
microcontroller programming. The wireless transmission was not achieved satisfactorily.
There was no interface to handle the device in site and therefore no question of user
authentication at site. On the other hand the flow theory was explained but not carried
out due to lack of time. There was not the provision of continuous measurement of the
parameters and previous value observation as well.
Thus we became ready to overcome all the challenges that project faced and came up
with more features, more accurate values, and longer range of operation. The level
monitoring is directly calculated rather than based on look up table to predict only the
range. Flow is completely the concept of our own based on Doppler’s Effect that we
carried out. Further we shaped the pulse on our own way. Half duplex communication
between the remote site and a center based PC monitoring system in easy user guided
VB interface. There is the feature of Automatic and Manual mode of operation and the
provision for previous statistical data plotted. This will generate the error signaling in
Wireless Ultrasound Flood Monitoring System
5
condition of the measured parameters being out of range. As an enhancement of the
project further, the velocity of different layers of fluid in streamlined motion and the
profile could also be shown along with mass flow per second. But due to limitation of
time we performed preliminary tests but could not achieve the complete success.
2.2 Related Theory 2.2.1 Sound
Sound is a mechanical longitudinal wave that is produced by any vibrating body.
Sound energy is transferred from one place to another in the form of compression and
rarefactions. Compressions are those regions where the density of the propagating
medium increases and rarefactions are those regions where the density of the medium
decreases. Being a mechanical wave it needs material medium for the propagation of
wave. The particles of the medium vibrate simple harmonically about their mean position
along the direction of propagation of wave.
The velocity of sound depends upon the Bulk Modulus and Density. The bulk modulus
also called compressibility of liquids is defined and the ratio of increase in pressure to
a change in volume. Also for adiabatic expansion of air considered, then velocity of
sound is inversely proportional to the density (δ) and directly proportional to the square
root of the temperature which further depends upon humidity. As the humidity of air
increases the amount of water vapor increases in the air which reduces the density of
air that in turn increases the velocity of sound. This can be well proved by the
following equation
MRT
MPVPEv ====γ
δγ
δ …(2.1)
For air,
E = 1.5 x 105 Nm-2
δ = 1.27 kgm-3
v = 345 ms-1
Wireless Ultrasound Flood Monitoring System
6
For water,
E = 2.05 x 109 Nm-2
δ = 1.27 kgm-3
v = 345 ms-1
2.2.2 Factors affecting the propagation of sound wave
Density of Medium:
The velocity of sound is dependent upon the density of the medium along with the
Elasticity property of the medium. At a given pressure, the velocity of sound is inversely
proportional to the square root of the density. That means greater the density of the
medium smaller will be the velocity of sound in the gaseous medium where there is
constant pressure. For example the velocity of sound in Hydrogen gas is greater in
Oxygen at constant pressure because of the fact that the density of hydrogen is less than
that of the oxygen.
In case the elasticity of the medium is much high as compared to the increase in
density velocity of the sound will be greater than that of the gaseous medium. For this
reason the velocity of the sound is greater in liquids than in gases and still greater in the
solids than the liquids. For example, the sound of train heard from the rails is faster than
the sound from the air as the velocity of sound is greater in iron (solids) than the
gases(air).
Moisture or Humidity:
The presence of moisture in the air reduces the density of air because the density of
vapor(0.92Kgm-3) is less than the dry air (1.293 Kgm-3) . Since the velocity of sound in
gases is inversely proportional to the square root of the density of the medium, the
velocity of sound is greater in a moist day than in a dry day.
Temperature:
The velocity of sound is directly proportional to the square root of the absolute
temperature of the gaseous medium. That means the velocity of the sound in hot air is
Wireless Ultrasound Flood Monitoring System
7
greater than on a cold day. In fact the velocity of sound increases by 0.61 ms-1 for every
degree rise in temperature.
Velocity of Wind:
Figure 2.1: Effect of wind on sound
The velocity of sound is affected by the wind velocity. Let δ be the angle between the
velocity of sound V(sound) and the wind direction U(Wind). Then The effective velocity
of sound is given by
V= U(wind) Cos δ + V(sound) ...(2.2)
From the above relation it is clear that the velocity of the sound increases when δ is acute
otherwise the velocity of sound decreases. As special cases, the velocity of sound and air
will be added together when both are in same direction(δ=0), will be subtracted when in
opposite direction(δ=1800). Also it is interesting to note that the wind will not affect the
velocity of the sound when it blows perpendicular(δ=900) to the propagation of the
sound.
Pressure:
The velocity of sound in gaseous medium has no effect in the velocity of the sound. It is
because the gases are compressible. That means as the pressure increases, the density of
the gases increases and the overall ratio of the pressure and density remains constant .So
the velocity of sound in gases is independent of the pressure.
Wireless Ultrasound Flood Monitoring System
8
Intensity of sound is defined as the amount of sound per unit area per unit time when
the unit area is being held perpendicular to the direction of propagation of the wave.
The loudness of sound is the ratio of intensity of sound and the threshold of hearing
10(-12) Wm-2 for a test frequency of 1000Hz expressed in decibels. Sound undergoes
different properties such as reflection, refraction, diffraction, Interference, attenuation,
scattering etc.
The intensity goes on decreasing exponentially with the distance (x) and depending
upon a property called attenuation constant (u) as given by
I = I0 e(-u*x) …(2.3)
2.2.3 Properties of sound
Reflection of Sound:
When we consider the reflection of sound waves, the nature and direction of motion of
the particles of reflected wave depends upon whether the reflecting surface is a denser or
a rarer medium.
Reflection from denser medium:
Sound consisting of longitudinal waves and hence compressions and rarefactions, when
strikes the surface of denser medium, a wave of compression is reflected as a wave of
compression and the rarefaction is reflected as the rarefaction i.e. no change in the type
takes place. That means that a phase shift of 1800 takes place from reflection from the
denser medium.
Reflection from rarer medium:
When sound wave strike the surface of rarer medium, a wave of compression is reflected
as the wave of rarefaction and the wave of rarefaction is reflected as the wave of the
compression i.e. the change in type takes place. However, the direction of motion of
particles after reflection remains the same as that of incident waves i.e. there takes place
no change in sign. In other words , no change in phase takes place in the reflected wave.
Wireless Ultrasound Flood Monitoring System
9
2.2.4 Application of the reflection of Sound:
Echo:
When sound is produced in front of a obstacle, sound is reflected back and repetition of
sound is heard back (if within the audio range 20HZ to 20KHz). This repetition of sound
from distant object is called echo.
Let,
∆t=Time taken to hear echo from distant obstacle.
v= Velocity of sound at that temperature.
D=Distance between the source and the obstacle
Then , ⎟⎠⎞
⎜⎝⎛ ∆×=
2tVD ...(2.4)
Figure 2.2: Illustration of Echo Reflection
2.2.5 Ultrasound
Ultrasound is sound of frequency beyond the audible range of Human 20 Hz to 20 KHz.
Ultrasound can not be perceived by the human ear but can be heard by the bats and
whales in detecting the objects nearby and act accordingly. The sound below 20 Hz
sound is called infrasound.
Ultrasound in the range of 2 MHz to 20 MHz is used in Medical ultrasound. And for
internal local use of about 50 MHz. Higher frequencies have shorter wavelength and
Wireless Ultrasound Flood Monitoring System
10
their reflectance increases to provide better information about the objects that come
their way.
The generation and measurement of ultrasonic waves is accomplished mainly by
piezoelectric (or magnetostrictive) or by optical means. Piezoelectric sensors are based
on piezoelectric effects – an effect that produces electric field due to polarization of the
dielectric material due to applied mechanical deformation or pressure and vice versa.
In optical methods we use diffraction property of light the ultrasonic waves are
rendered visible.
Ultrasound is reflected at interfaces between tissues with differing acoustic
impedances. The acoustic impedance is measured as the product of velocity of sound
and the physical density of the medium.
Sounds in the range of 20 KHz to 100 KHz are commonly used for communication and
navigation by bats, dolphins. Much higher frequencies are used for medical purposes.
Ultrasonic waves are produced and received by the ultrasonic transducers. A variety of
medical diagnostic applications that work on echo-reflection and Doppler’s shift are
used such as in echocardiogram. Ultrasound imaging is one of the emerging
technologies that have very high resolution.
Ultrasound Properties:
Some of the fundamentals that influence the operation of ultrasonic sensors are
explained here. The maximum detection range of an ultrasonic sensor is typically longer
for lower frequencies, while the resolution and accuracy are typically better at higher
frequencies. The strength of the target echo, however, is greatly affected by the geometry
and reflectivity of the target, thereby affecting the range and resolution of the distance
measuring system.
One of the biggest sources of error in an ultrasonic position measurement is the
variability of sound speed in the transmission path between the sensor and the target,
Wireless Ultrasound Flood Monitoring System
11
largely caused by uncertainty in the average temperature along the path. Maximum
measurement accuracy is therefore obtained when temperature compensation is used
within the sensor. The temperature uncertainty affects absolute accuracy substantially
more than it does the relative accuracy of an incremental measurement.
It is not unusual for the amplitude of echo levels to change by large amounts from pulse
to pulse due to variations in sound speed in the medium, caused by factors such as air
turbulence or target movement. Also, long-term changes in humidity can have a
significant effect on the strength of an echo from a target.
It is usually desirable to use a sensor with the narrowest possible radiation pattern that
can detect the required targets. The beam width and the directivity depends upon the
ration of D/λ. Greater the ration greater the directivity and less will be the beamwidth.
For a greater frequency, the narrower the radiation pattern of the sensor, the longer the
maximum range of the sensor and the less susceptibility to unwanted targets at the sides
of the sensor. However, a very narrow radiation pattern from a sensor will require more
accurate orientation of the sensor's axis with regard to the acoustic beam's
perpendicularity to a flat target. In any event, the user must understand the effective
beam angle of the sensor when determining which targets will be detected and which
will be ignored. This effective beam angle changes with the distance of the target and the
strength of the reflection from the target.
Figure 2.3: A transducer with a circular radiating surface whose diameter is large in
comparison to a wavelength produces a narrow, conical beam pattern with
multiple secondary lobes.
Wireless Ultrasound Flood Monitoring System
12
2.2.6 Doppler’s Effect
The apparent change in frequency due to the relative motion of the sound source and
the observer is called Doppler’s Effect. This effect was observe d by Christian Doppler
in 1942 and proved in 1945 in Holland and so called Doppler’s Effect. Doppler’s effect
in light and sound can be used to find the velocity of the moving object.
Doppler’s effect in light is used by RADAR (Radio Navigation And Ranging). It
determines the velocity of flying planes practically applied in airports and many military
and spy planes.
Figure 2.4: Illustration of Doppler’s shift
According to this effect when the source of sound approaches the stationary observer
then the apparent frequency increases and when it recedes away the apparent frequency
decreases and the target object velocity can be obtained using above equation.
Also Red shift phenomenon in light is observed under this effect that shows the evidence
of increasing universe.
2.2.7 Application of Doppler’s Shift
This section describes the application of the Doppler’s shift in Echolocation of a Moving
Object in detail. And the theory described below supports our system to implement the
Doppler’s Shift practically.
Wireless Ultrasound Flood Monitoring System
13
Figure 2.5: Application of the Doppler’s shift in Echolocation of a
Moving Object
In the figure 2.5 we have,
f = Actual frequency of Ultrasound transmitted by the Transmitter i.e. source
f’ = Frequency of the moving object (Which becomes the secondary transmitter i.e.
Secondary Source of Sound)
f” = Apparent Frequency of Ultrasound to the receiver.
c = Velocity of the sound wave at that particular temperature, humidity and for that
particular medium.(Say air).
0v = Velocity of the moving Object.
d = Distance between the Transmitter and the Receiver
D = Distance between the Receiver and object
As object moves at a constant speed, the object intercepts the ultrasound and scatters it
back. The frequency received by the moving object is given by the following formula.
fv
cosv c ' f
s
0 ×⎟⎟⎠
⎞⎜⎜⎝
⎛ +=
α …(2.5)
As it scatters ultrasound, the object becomes a secondary, moving ultrasound source. The
velocity of this source towards receiver is βcosv 0
Wireless Ultrasound Flood Monitoring System
14
The receiver frequency f” is given by
fcosvc
cosv-c
c f'cosv-c
c 'f' 0
0 0×⎟⎠
⎞⎜⎝
⎛ +×⎟⎟⎠
⎞⎜⎜⎝
⎛=×⎟⎟
⎠
⎞⎜⎜⎝
⎛=
cα
ββ …(2.6)
Hence,
fcosv-ccosvc
'f' 0
0 ×⎟⎟⎠
⎞⎜⎜⎝
⎛ +=
βα
…(2.7)
Assume, βα = Now solving equation 2.5 for v0, we get,
βsecf'f'f - 'f' v0 ××⎟⎠⎞
⎜⎝⎛
+= c …(2.8)
From the experimental arrangement, we can show that
( )D2
D4dsec
22 +=β …(2.9)
Then the velocity of the moving object is given by
( )D2
D4df'f'f - 'f' v
22
0+
××⎟⎠⎞
⎜⎝⎛
+= c …(2.10)
In terms of time relation the above equation will be
( )D2
D4dTrxTtxTrx-Ttx v
22
0+
××⎟⎠⎞
⎜⎝⎛
+= c …(2.11)
The shift is too small to be measured over a single pulse, we have to take ’”N” number of
pulses to observe accumulative shift.
( )D2
D4dTrxNTtxNTrxN-Ttx Nv
22
0+
××⎟⎠⎞
⎜⎝⎛
×+×××
= c …(2.12)
Wireless Ultrasound Flood Monitoring System
15
When we have d<<D, Then Sec(ß) ≈1
c×⎟⎠⎞
⎜⎝⎛
×+×××
=TrxNTtxNTrxN-Ttx Nv0 …(2.13)
If the experimental arrangement is symmetric (α ~ β) and if we assume: v0cosα << c,
then Doppler shift can be written as:
fcos v2
f- 'f' f 0 ×⎟⎠⎞
⎜⎝⎛≅=∆
cα
…(2.14)
Experimentally, we can measure the beat frequency between the transmitted (f) and
received (f”) sounds, amplified as Doppler waveform, from which we obtain the Doppler
shift.
Knowing the ultrasound frequency f and speed c, we can measure the Doppler shift ∆f
and the angle α and thus we can calculate the speed of the moving object 0v :
( )⎟⎠⎞
⎜⎝⎛=
αcos f 2'-ff'cv0 …(2.15)
Assume °= 60α , we get
( )⎟⎠⎞
⎜⎝⎛=
f '-ff'cv0 …(2.16)
⎟⎠⎞
⎜⎝⎛ −×= 1
f'f'v0 c …(2.17)
⎟⎠⎞
⎜⎝⎛ −×= 1
TrxTtxv0 c …(2.18)
Wireless Ultrasound Flood Monitoring System
16
2.2.8 Ultrasonic Transducers
Ultrasonic transducers are based on Piezoelectric Effect or on the Magnetostrictive
effect. This can be utilized to produce ultrasonic transducer of up to some giga-hertz
operations as per the specific requirements. The transducers used in our project are
SQ40T and SQ40R for our purpose because other high frequency transducers were not
available in our market.
Figure 2.6: Ultrasonic transducer
2.2.9 Application of ultrasound
Ultrasound was primarily used in SONAR systems where various oceanic floors and bed
distance were measured. It is used in imaging systems including eco-cardiology where
the picture and working condition of the heart is shown in video. It is used in treatment
of kidney stone where special shock waves are sent to the prone areas and stones broken
down into smaller pieces that could be readily carried out by the urinary system
thereafter. It is still used in determining the blood flow within the vessels and different
flow of liquids in pipes in the industries.
Ultrasound is used in many detection and control applications as well. Those
applications include loop control, Roll Diameter, Tension Control, Winding and
Unwinding Control in Cloth weaving industries. Similarly, it is used in Liquid Level
Control, Thru Beam Detection for High Speed Counting, Full Detection, Thread or
Wire Break Detection, Vehicle Detection for Car Wash and Automotive Assembly,
Irregular Parts Detection for Hoppers and Feeder Bowls, Counting or Profiling Using
Ultrasonic System, Thickness Gauging, Web Break Detection, Quality Control
Inspection and so on.
Wireless Ultrasound Flood Monitoring System
17
CHAPTER THREE
Methodology
3.1 System architecture The main principle of measuring liquid level is to measure the time between the time of
transmitting and receiving of the reflected pulse from the liquid level surfaces. The total
time lapsed is double time period (i.e. the time required from transmitter to the liquid
level and reflected from liquid level to the receiver). So total time is divided by two, in
order to find out the duration of pulse on reaching liquid level. The calculation is
governed by the following relation.
2TvD ×= …(3.1)
Where,
D is distance between the receiver and liquid level (in meter)
v =Velocity of Ultrasonic Wave in Air (in meter per second)
T=Time Taken by the Ultrasonic Sound from Transmitter to Receiver (in second)
Figure 3.1: System Block Diagram
Wireless Ultrasound Flood Monitoring System
18
3.1.1 Transmission:
For the excitation of the ultrasonic transducer SQ40T, we need 40KHz pulse. The
generation of excitation pulse is done in following stages:
Generation of 40 KHz square wave
NE555 timer (astable mode) is used for the generation of the pulses with 50% duty cycle.
It generates 40 KHz square wave when enabled by the MCU. The purpose of using
NE555 is to generate the 40KHz frequency rather than the square wave.
Conversion of square wave to transducer exciting pulses
For this purpose the transistors and inverters are used. The square wave so generated has
logic level of 0V to 5V. In order to convert this logic to inverter compatible logic (0V –
9) we have used two transistors (BC547). Then the inverters are used to convert these
signals to increase the transmission power. The logic behind using these inverters is to
generate two different pulses 180 degree out of phase with each other, so that they can be
fed to the positive and the negative terminals of the transducer SQ40T.The transducer
SQ40T generates the 40KHz ultrasound by piezoelectric effect.
3.1.2 Reception
The receiver transducer SQ40R resonates at 40 KHz to receive only the transmitted
signal. The two major operations done after receiving signal after the receiver transducer
SQ40R are:
a. Amplification
b. Rectification
a. Amplification
Since the signal received at the transducer SQ40R is of low strength and even imposed
with noise, we need to amplify the signal. Thus, we have used LNA LM833N, which
rejects noise and amplifies the required signal.
The amplification is done in two stages with maximum gain of 60dB so that the signal
can be used for further processing.
Wireless Ultrasound Flood Monitoring System
19
b. Rectification
The amplified signal is then rectified by diodes 1N4002. We have carried out half wave
rectification to generate DC level of received signal.
3.1.3 Detection
Now the generated DC voltage obtained form rectification process is fed to comparator
LM358. This comparator is used to compare the DC level of received signal against
preset threshold value to generate high logic if signal is received otherwise low logic.
3.1.4 Signal Holding
In order to hold the logic level generated from detector or comparator SR flip flop is
used, so that MCU can acknowledge the received signal. The output of the latch is set to
low logic with the help of MCU initially to predefine the state of latch.
3.1.5 Pulse Shaping
To measure the flow the sine wave, the output of LNA is fed to pulse shaping circuitry
that uses single inverter of 74HC04. The output is square wave of logic level 0V to 5V
compatible with MCU.
3.1.6 Level calculation
MCU is used to observe the time elapsed between the transmitted and received signal.
This time is used to calculate the level of reflecting water surface.
3.1.7 Flow calculation
The pulse shaped signal from 74HC04 is fed into the MCU for measuring the frequency
of received signal. Then the frequency shift between the transmitted and received wave is
calculated and applied with Doppler’s effect to measure the velocity of water.
3.1.8 Display
The calculated level and flow of water is displayed on the 16 x 2 LCD which is low
power passive display device. (see Appendix A for LCD)
Wireless Ultrasound Flood Monitoring System
20
3.1.9 Wireless module
Finally, the information from site is delivered to the monitoring station using
commercially available RF modules and vice versa.
3.2 Description of components 3.2.1 Ultrasonic transducer
For the purpose of generating the ultrasound, we have used SQ40T as transmitter
transducer of ultrasound and SQ40R as a receiver transducer of ultrasound. Theses
transducer operates at their best at 40 KHz of AC signal. The transmitter is excited the
best, and at 18 V P-P of AC signal. Similarly, the SQ40R I more sensitive to frequency
of 40 KHz and can produce signal up to few hundreds milivolts after sensing ultrasonic
signal.
Figure 3.2 Back view of the SQ40T/SQ40R
3.2.2 8051 Microcontroller Microcontrollers are designed in a single chip, which typically includes a
microprocessor, certain byte of R/W memory, from 1K to 2K bytes of ROM, and several
signal lines to connect I/O lines. They are used in such functions as controlling
appliances and traffic lights. We have used ATMEL 89C51 microcontroller in our
project. Some features are summarized below:
• 8-Bit CPU Optimized for Control Applications
• Extensive Boolean Processing Capabilities (Single-Bit Logic)
• On-Chip Flash Program Memory
• On-Chip Data RAM
Wireless Ultrasound Flood Monitoring System
21
• Bidirectional and Individually Addressable I/O Lines
• Multiple 16-Bit Timer/Counters
• Full Duplex UART
• Multiple Source/Vector/Priority Interrupt Structure
• On-Chip Clock Oscillator
• On-chip EEPROM (AT89S series)
• SPI Serial Bus Interface (AT89S Series)
• Watchdog Timer (AT89S Series)
More detailed description of it is presented as below:
The microcontroller is the device that can perform various operations and computations
on the data. It consists of the arithmetic and the logic unit, I/O unit, control unit and other
various components.
The 8051 is the most popular microcontroller used today. Many derivative
microcontrollers have been developed which are based on and compatible with the
8051.To program an 8051 requires an important skill for one who plans to develop
product that will take advantage of microcontrollers. One of the 8051 based
microcontrollers is the most popular and widely used chip named as AT89C51.
The 8051 is an 8-bit machine. Its memory is organized in bytes and practically all its
instructions deal with byte quantities. It uses an accumulator as the primary register for
instruction results. Other operands can be accessed using one of the four different
addressing modes available:
• Register implicit
• Direct
• Indirect or immediate
Operands reside in one of the five memory spaces of the 8051. The five memory spaces
of the 8051 are:
• Program memory
• External Data Memory
Wireless Ultrasound Flood Monitoring System
22
• Internal data Memory
• Special Function Registers
• Bit Memory
The AT89C51 microcontroller includes 4k Bytes of In-System reprogrammable Flash
memory. Also 128*8-bit Internal RAM with 32 programmable I/O Lines. It consists of
two 16-bit Timer/Counters and six Interrupt Sources. The AT89C51 is a low power, high
performance CMOS 8-bit micro-computer with 4K bytes of flash programmable and
erasable read only memory. The on-chip Flash allows the program memory to be
reprogrammed in-system or by conventional nonvolatile memory programmer. By
combining a versatile 8-bit CPU with flash on a monolithic chip, the Atmel AT89C51 is
a powerful microcontroller, which provides a highly flexible and cost effective solution
to many embedded control applications.
The AT89C51 provides the following standard features timer/counter, five vector two-
level interrupt architecture, full duplex serial port, on-chip oscillator and clock circuitry.
In addition, the AT89C51 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 RAM contents but freezes the
oscillator disabling all other chip functions until the next hardware reset.
Features of AT89C51:
• 4K bytes of In-system reprogrammable Flash Memory.
• Endurance: 1,000 Write/Erase cycles
• Fully static operation: 0 Hz to 24 MHz.
• Three level program memory lock.
• 32 programmable I/O lines
• 128 x 8-Bit Timer/counters.
Wireless Ultrasound Flood Monitoring System
23
• Six Interrupt Sources.
• Programmable Serial Channel.
• Low power Idle and Power Down Modes.
Pin Description:
Vcc
Supply voltage
Gnd
Ground
Port 0
Port 0 is an 8-bit open-drain bi-directional I/O port. So, it requires external pull up
resisters when used as simple I/O port. It is also designed as AD0-AD7 i.e. it can be
used for both address and data bus. When ALE = 0, it acts as data bus D0 –D7, but when
ALE = 1, it acts as address bus A0-A7. In our system, we have used Port 0 as the data
bus for the LCD.
Figure 3.3: AT89C51 IC pin description
Wireless Ultrasound Flood Monitoring System
24
Port 1 / Port 2
Port 1 / Port 2 both are an 8-bit bi-directional I/O port with internal pull-ups. Port 1 / Port
2 both acts as simple I/O when 8051 used with no external memory connection. But,
with the system with external memory connection, Port 2 acts as higher order address
bus along with the Port 0 to provide the 16-bits address for the external memory.
Port 1 is dedicated for the keypad while in case of Port 2, pin 2.1 used to enable the 555
timer, pin 2.2 used to enable/disable the latch in the circuit,pin2.7,2.6 & 2.5 used for the
control signaling of the LCD.
Port 3
Port 3 is also an 8-bit bi-directional I/O port with internal pull-ups. The port 3 output
buffers can sink/source four TTL inputs. When 1s are written to port 3 pins they are
pulled high by internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are
externally being pulled low will source current because of the internal pull ups. Port 3
also serves the function of various special features of the AT89C51 as listed below; Port
3 also receives some control signals for Flash programming and verification.
Port 3 also serves the functions of various special features of the AT89C51 as listed
below:
Port pin Alternate functions
P 3.0 RXD ( serial input port)
P 3.1 TXD ( serial transmit port)
P 3.2 INT0 ( external interrupt 0)
P 3.3 INT1 (external interrupt 1)
P 3.4 T0 ( timer 0 external input)
P 3.5 T1 ( timer 1 external input)
P 3.6 WR (external data memory write strobe)
P 3.7 RD ( external data memory read strobe)
Table 3.1: Port 3 Alternate function table
Wireless Ultrasound Flood Monitoring System
25
ALE/PROG
ALE (address latch enable) is an output pin and is active high, while connecting to an
external memory.
RST
RESET pin (i.e. pin 9) is an input pin and active high (normally low).
Where the high pulse must last for minimum of the two machine cycles before it goes to
low.Upon application of the high pulse, the MCU will be reset such that all the values of
its register will reset and program counter will be set to 0s.Infact, it is also referred to as
reset interrupt among the six interrupts available in 8051 MCU.
PSEN
“Program store Enable” is read strobe to external program memory. When the AT89C51
is executing code from external program memory, PSEN is activated twice each machine
cycle, except that two PSEN activations are skipped during each access to external data
memory.
EA/VPP
External Access Enable. EA must be strapped to GND in order to enable the device to
fetch code from external program memory locations starting at 0000H up to FFFFH.
This pin also receives the 12-volt programming enable voltage during Flash
programming for two parts that require 12-volt VPP.
XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL2
Output from the inverting oscillator amplifier.
Wireless Ultrasound Flood Monitoring System
26
3.2.3 Voltage Regulators
In our system we’ve used 7805&7809 as a voltage Regulators. It is a 3-Terminal
Regulator with Output Current Up to 100mA. It doesn’t require External Components It
has provision for Internal Thermal Overload Protection and Internal Short-Circuit
Limiting.
Figure 3.4: Minimum connection of 8051 MCU system
Figure 3.5: Pin description of voltage regulator 7805 & 7809
Wireless Ultrasound Flood Monitoring System
27
This 78xx series of fixed-voltage monolithic integrated-circuit voltage regulators is
designed for a wide range of applications. These applications include on-card regulation
for elimination of Noise and distribution problems associated with single-point
regulation.
The 7805 is most common and well-known of the 78xx series regulators, as its small
component count and medium-power regulated 5V make it useful for powering TTL.
3.2.4 Diodes
We have used silicon diodes 1N4001 in order to carry half wave rectification of the input
sine wave, to obtain its DC amplitude.
Figure 3.6: Figure showing input sine wave and its half wave
rectification using diodes.
Moreover, the diodes are also used as protection against negative voltage at the power
supply of circuit in reverse bias mode.
Figure 3.7: Negative voltage protection in the circuitry using diode
Wireless Ultrasound Flood Monitoring System
28
3.2.5 Line driver or Voltage translator
As a Line driver IC we have used the MAX232 IC in our system. It operates with Single
5-V Power Supply. The MAX232 device is a dual driver/receiver that includes a
capacitive voltage generator to supply EIA-232 voltage levels from a single 5-V supply.
Each receiver converts EIA-232 inputs to 5-V TTL/CMOS levels. These receivers have a
typical threshold of 1.3 V and a typical hysteresis of 0.5 V, GND and can accept ±30-V
inputs. Each driver converts TTL/CMOS input levels into EIA-232 levels. The MAX232
is characterized for operation from 0°C to 70°C. The MAX232I is characterized for
operation from –40°C to 85°C.
Since both 8051 MCU and computer are DTE, the communication between them can be
done with RS232 standard using MAX232 and null modem or virtual modem
configuration. Each DTE acts as virtual modem to other DTE.
3.2.6 DC socket
A DC connector is a electrical connector for supplying direct current (DC) power. DC
connectors are poorly standardized, compared to domestic AC power plugs and sockets.
DC plug is a common name used for one common type of cylindrical two-conductor
plug
Figure 3.8: Line driver MAX232
Wireless Ultrasound Flood Monitoring System
29
Figure 3.9: Null modem
available in a range of sizes and used to power small pieces of electronic equipment.
Several competing standards exist for DC plugs, and in some cases incompatible plugs
will fit together, or can be made to fit, possibly damaging equipment if the voltage is
wrong, the polarity is wrong, current ratings are exceeded, power supply filtering or
stability is inadequate for the equipment being powered.
The intended use of these plugs is on the cable connected to a power supply. The
matching jack or socket is then mounted in the equipment to be powered
3.2.7 LM833
The LM833 is a dual general purpose operational amplifier designed with particular
emphasis on performance in audio systems.
This dual amplifier IC utilizes new circuit and processing techniques to deliver low
noise, high speed and wide bandwidth without increasing external components or
decreasing
stability. The LM833 is internally compensated for all closed loop gains.
The LM833 is pin-for-pin compatible with industry standard dual operational amplifiers.
It has:
• High gain bandwidth: 15MHz (typical); 10MHz (min)
Wireless Ultrasound Flood Monitoring System
30
• Wide power bandwidth: 120KHz
Figure 3.10: Dual 8 pin Opamp
The gain bandwidth product (GBW or GB) for an amplifier is the product of the open
loop gain (constant for a given amplifier) and its 3 dB bandwidth. This quantity is
commonly specified for operational amplifiers, and allows circuit designers to determine
the maximum gain that can be extracted from the device for a given frequency (or
bandwidth) and vice versa.
Understanding the meaning of gain bandwidth product (GBWP)
If the GBWP of an op-amp is 1 MHz, it means that the gain of the device falls to unity at
1 MHz. Hence, when the device is wired for unity gain, it will work up to 1 MHz
(GBWP = gain x bandwidth, therefore if BW = 1 MHz, gain = 1) without excessively
distorting the signal. So by simple mathematics, for 40 KHz, the gain will be 25. Further,
if the maximum frequency of operation is 1 Hz, then the maximum gain that can be
extracted from the device is 6101×
We have used both opamps of LM833 for amplifying weak signal from transducer.
An opamp has the 1
2
RRGain −= in above configuration. So with the help of feed back
resistor we can vary gain easily.
Wireless Ultrasound Flood Monitoring System
31
Figure 3.11: Non inverting configuration of an amplifier
3.2.8 LM358
The LM358 consists of two independent, high gain; internally frequency compensated
operational amplifiers which were designed specifically to operate from a single power
supply over a wide range of voltages.
Application areas include transducer amplifiers, dc gain blocks and all the conventional
op amp circuits which now can be more easily implemented in single power supply
systems
The schematic and pin configuration of LM358 is same as that of LM833 as shown in
figure 3.10 above.
3.2.9 CD4011
The CD4011BC quad gates are monolithic complementary MOS (CMOS) IC
constructed with N- and P-channel enhancement mode transistors.
The devices also have buffered outputs which improve transfer characteristics by
providing very high gain. All inputs are protected against static discharge with diodes to
VDD and VSS.
We have used three NAND gates to realize SR-FF.
Wireless Ultrasound Flood Monitoring System
32
Figure 3.12: Quad NAND gate IC
Each of the gates performs the same function as shown in figure 3.13.
Figure 3.13: Logical symbol and truth table of NAND gate
3.2.10 CD4069
The CD4069 is a six NOT gate having IC, used for inverting logic in a electronic circuit
between 0V and 9V.
In our circuitry we have used the inverting property of NOT gate to generate excitation
pulse for transducer.
Wireless Ultrasound Flood Monitoring System
33
Figure 3.14: Six NOT gates IC
3.2.11 74HC04
The 74HC04 is also a six NOT gate having IC used for inverting logic between 0V and
5V. In our circuitry we have used it to produce active low logic when signal is detected,
as interrupt of MCU is active low and the gates are also used for pulse shaping. The
schematic of 74HC04 is same as that of CD4069 as in figure 3.14. The working on each
NOT gate can be summarized as follows:
Figure 3.15: Logical symbol and truth table of NOT gate
Wireless Ultrasound Flood Monitoring System
34
3.2.12 555 timer
It is a 8 pin special IC designed for the purpose of generating square wave by connecting
the proper connecting elements. With the help of variable resistors, we can generate
square wave at different frequency.
It is used to generate the signal of 40 KHz which is the frequency of ultrasound to be
excited as implement in our system.
Figure 3.16: 555 timer configuration to generate square wave.
3.2.13 LCD
The LCD, liquid crystal display, is used for the Displaying of the information at the site’s
circuit. It displays the level, flow values and plays the role for interfacing with the user at
site. For detail information about LCD(see Appendix A).
3.2.14 RF modules
RFM12B has been used as transceiver to communicate with monitoring station and the
site. It works on the signal ranges from 433/868/915 MHz. The SPI interface is used to
Wireless Ultrasound Flood Monitoring System
35
communicate with the microcontroller for the various parameter settings like baud rate,
clock rate, modes, carrier frequency etc. The RF modules are shown in the figure 3.17
below.
Figure 3.17: RF modules
Note: For further detail about the components described in section 3.2 refer to the CD
attached herewith, which contains the datasheets of the used components. Further, refer
the Books and site as mentioned in the References.
Wireless Ultrasound Flood Monitoring System
36
3.3 Circuit Explanation 3.3.1 Power supply circuit:
We have used 7805 and 7809 IC for power supply in our system, as some IC operate in
9V while some at 5V.
Also decoupling capacitor are used in the IC’s input and output to filter out ripples in
source.
Figure 3.18: Voltage regulators
3.3.2 Transmission section
a. 555 timer
Here, according to pin 4 of 555 is enabled /disabled by MCU, the 555 timer in astable
mode configuration generates square wave of 40 KHz.
The value of components for generating 40 KHz wave is:
R1=10K
R2 = 13K
C = 102 p
C )RR (R
1.44 frequency 321
×++
= …(3.2)
Wireless Ultrasound Flood Monitoring System
37
b. Transistors and inverters
Signal from 555 timer is fed to two points:
i) Through the NAND gate, then to the transistor
ii) Directly to the base of next transistor.
The transistors are in inverting mode, thus they amplify the current. At the same time
since the transistors is working in (0-9)V logic thus there is power of signal. Now, the
outputs from the collector of the two transistors are fed to the CMOS inverters (which
are capable for high frequency switching).
Figure 3.19: Astable mode of 555 timer
Then, the two square wave signal 180º out of phase with each other, are fed to the
positive and negative terminal of transducer. The capacitor C is used to block any DC
noise in the excitation signal.
3.3.3 Reception section
The received signal by SQ40R is of very low strength. Statistically on receiving
ultrasound, the signal measured is of frequency 40 KHz with (60-130) mV peak to peak
amplitude. Now, this received signal is further processed as:
Wireless Ultrasound Flood Monitoring System
38
a. Coupling the signal
The resistor R is used to GND any DC level in the received signal; C is used to couple
the high frequency ultrasound signal.
b. Amplifying the signal
For amplification, we have used the LNA LM833N.This is a two-opamp IC operating at
9V. Here, we carry amplification in two stages in inverting mode of opamp. The gain in
the signal can be varied 10 times to 1000 times i.e. 20dB to 60dB.The first stage gain can
be varied from 1dB to 60dB, whereas the second stage gain is fixed to 20dB.
Figure 3.20: Circuit to excite ultrasonic transmitter
Here, amplification is not done in reference to 0V. As the IC operates in (0-9)V logic so
if we amplify at 0V the signal will go below 0V ,hence experience the clipping .So, we
have carried out amplification at reference of 4.5V, so that even signal of 9V peak to
peak , there won’t be clipping if we adjust gain properly. Since the opamp has negative
Wireless Ultrasound Flood Monitoring System
39
feedback, the voltages at the positive and negative terminals are equal. This is called
virtual GND .So, with this configuration of bipolar signal can be amplified even if the
opamp operates in single mode power supply.
This technique is very useful when we need full wave signal, while we are using opamp
in single mode power supply. So, after amplification we get the signal of frequency 40
KHz with (5-8) V peak to peak amplitude.
c. Signal rectification
Now, the sinusoidal signal after amplification is half wave rectified using the diodes
1N4001, to obtain the DC value of the amplified signal. The output of the signal
rectification is DC signal of (4-8) V. Although, the half wave rectification could be
carried out using single diode but the diode that is grounded is used to provide complete
path for negative cycle of input wave.
3.3.4 Signal detection
Noise is inevitable in any system, so our system is also prone to noise due to the
interference from various sources like RF, microwave emitting sources etc. But, we have
been able to discriminate noise against signal through proper filtering techniques.
Experimentally, we have observed that that noise DC level doesn’t rise above 2.5V in
our environment.
The signal detector is LM358 as comparator.LM358 has two opamps. We have used one
opamp in comparator mode where:
i) Changing voltage is applied to positive terminal
ii) Reference voltage is applied to the negative terminal
The opamp in comparator mode has no feedback, so theoretically gain is infinite. Now, if
the input at the non-inverting terminal becomes a more positive than the negative
terminal(with reference voltage), the output should have been in kilo-volts . But this is
limited by the biasing voltage of opamp. In our case the IC works in (0-9) V logic thus
output can only saturate to 9V.
Wireless Ultrasound Flood Monitoring System
40
The reference voltage is calculated as follows:
( )⎟⎟⎠
⎞⎜⎜⎝
⎛+
×=ba
ccbrf RR
VR V …(3.3)
(a)
(b)
Figure 3.21: Opamp as comparator
(a) Circuit diagram
(b) Timing diagram
We have used Rb as variable resistor, so as to change the reference voltage as per need
by experimenting.
The DC level obtained from rectification stage is fed to the non–inverting terminal of
comparator and compared against reference level of 3V.So, the output of the comparator
Wireless Ultrasound Flood Monitoring System
41
is logic 1(9V) for signal and logic (0V) for noise in the environment. The resistor Ro at
the output is used to change the (0-9)V logic to (0-5)V logic as our next stage IC
operates on (0-5)V logic.
a. Signal holding
We have used SR-FF for holding the received signal as shown in figure 3.22. The logic
level 1 generated by the signal detecting circuit appears for very short time, so MCU
may not be able to acknowledge it Thus, in order to hold that signal for MCU , we have
used latch circuitry.
In order to pre-define the output of the latch we hold the input at ‘Z’ low, so that output
of the latch is low independent of input at ‘W’. Signal at ‘Z’ is changed to high state only
after ultrasound is transmitted by system, which makes the output of latch dependent
only on the input ‘W’. This helps to avoid false triggering.
We have used three NAND gates of CD4011 IC in order to realize the latch.
The output of the latch is finally fed to the MCU after inverting it, as the interrupt of
MCU is active low. We have also used pull down resistor after the inverter before
feeding the signal to MCU; so as to properly set the logic levels (i.e. avoid floating
logic).
b. Pulse shaping
In order to find the flow of water, we need to find the frequency of the reflected signal
for which we need a MCU compatible pulse. So, in order to convert the amplified sine
wave from LM833 to MCU compatible square wave having logic levels (0-5)V, we used
following circuitry.
(a)
Wireless Ultrasound Flood Monitoring System
42
(b)
Figure 3.22: SR FF
(a) Circuit Diagram
(b) Timing diagram
Figure 3.23: Pulse shaping circuit
Wireless Ultrasound Flood Monitoring System
43
This circuit is similar to Schmitt trigger operation. This is comparator application which
switches the output negative when the input passes upward through a positive reference
voltage and output positive when the input passes downward through a positive reference
voltage.
The Schmitt trigger is also the comparator application which switches the output
negative when the input passes upward through a positive reference voltage. It then uses
negative feedback to prevent switching back to the other state until the input passes
through a lower threshold voltage, thus stabilizing the switching against rapid triggering
by noise as it passes the trigger point.
But we didn’t use the Schmitt trigger because it was more convenient to generate square
wave using hex buffer 74HC04.
Wireless Ultrasound Flood Monitoring System
44
Wireless Ultrasound Flood Monitoring System
45
(b)
Figure 3.24: (a) Schematic of circuit at site
(b) Schematic of circuit at monitoring station.
3.4 Program in system
Wireless Ultrasound Flood Monitoring System
46
3.4.1 Flow Chart
The flowcharts described below are not the entire flowchart of the system. Rather, the
level and flow finding flowcharts have been described separately. So that, it gives the
central idea of the program to find level and flow of the flowing water.
Flow chart for level
The flowchart shown in figure 3.25 describes the method to find the level of the moving
water. To find level, first the ultrasonic wave is transmitted from the ultrasonic
transmitter transducer. At that mean time a timer is started. This timer belongs to the
internal timer of the MCU. Then, we wait for the reflected wave from water surface to be
received by the ultrasonic receiver transducer. As the receiver receives the reflected
wave the timer that started earlier is stopped. Now, the timer register of the timer will
have the time (∆T) that elapsed for the transmitted wave to be received after the
reflection from the water surface.
Now with the help of this time, the level of the water is found using formula described in
flowchart figure 3.22. For detail about calculating the level of water see section 3.4.2
resolution calculation of level.
Flowchart for flow
The flowchart shown in figure 3.26 describes the method of finding the flow of the
moving water. To find the flow, first the ultrasound wave is transmitted. As the reflected
wave start receiving the frequency of the received wave is calculated and the frequency
shift there after. Now, the value of frequency shift is employed in the formula shown in
flowchart figure 3.26 to find out the velocity of moving water. For detail about
calculating the flow of water see section 3.4.2 resolution calculation of flow
Wireless Ultrasound Flood Monitoring System
47
Figure 3.25: Flowchart for Figure 3.26: Flowchart for level calculation flow calculation
Wireless Ultrasound Flood Monitoring System
48
Overall Flowchart
The flowchart shown in figure 3.27 describes the entire flow of system. Before
proceeding to the flowchart some of the terms used in the flowcharts are described
below.
Lvl_flw_flag is flag to indicate level or flow of water to be measured.
Wave_40k is the control signal to excite or stop the generation of 40KHz of wave
Latch is the enable / disable signal for the latch (SR flip flop) in the circuit.
Lvl_count keeps the record of measured level of the water
Lvl_flag is the flag to indicate the final value of level
Pulse_counter is the counter to count the number of square pulses have been received.
Flow keeps the record of measured flow of the water
Wireless Ultrasound Flood Monitoring System
49
START
Greeting MessageDisplay
Waiting for stationCommandi.e. SerRx()
Display “invalid
command”
Is It handover To station
i.e H?
Call Subroutine Site_control
Is It to find Level
“L”?
IsIt to find Flow
“F”?
Call Subroutine Find_level
Call SubroutineFind_flow
YES YES YES
NO NO NO
IsLevel exceeds
Threshold Value?
Is Flow exceeds
ThresholdValue?
BUZZER ON
BUZZER OFF
YES
YES
NO
Wireless Ultrasound Flood Monitoring System
50
Sub routineSite_control
User Authentication
Wait for site commandi.e Key()
Is It handover
ToStation?i.e “H”
Is It to find level?
“L”
Is It to find
flow?“F”
DisplayInvalid
command
Call subroutineFind_level
Call SubroutineFind_flowReturn
YES
NO
YES
NO
YES
NO
IsLevel exceeds
Threshold Value?
Is Flow exceeds
ThresholdValue?
BUZZER ON
BUZZER OFF
YES
NONO
YES
Wireless Ultrasound Flood Monitoring System
51
SubroutineLEVEL
Set timer0 in Mode2With
TH0 = E3 (resolution)
Enable interrupts timer0 & External
interrupt 1
Reset level valuesLvl_count = 0Lvl_flag = 0
Start transmitting wave as Wave_40k = 1
&Latch = 1
Start timer0
IsLvl_flag = 1?
Is External interrupt1
Occurred?
Is Timer0 interrupt
Occurred?
Disable interrupts
AsEA = 0
Also transmit it to the monitoring
station
return
Display lvl_count as required level
On LCD
Call ISRINT1
Call ISR T0
NO
YES
YES
NO
YES
NO
ISRINT1
Stop Timer0
Dpt_flag = 1
Wave_40k = 0Latch = 0
return
ISRT0
Increase Lvl_count by
1
Return
Wireless Ultrasound Flood Monitoring System
52
SubroutineFLOW
Pulse_Counter = 0Enable External
interrupt 0
Set timer0 in Mode1 with
TH0 = 0,TL0 =0
Wave_40k = 1
Is External interrupt
0Occurred?
Call ISRINT0
If pulse_counter
= 1
Start timer0 as TR0 = 1
A
A
Is External
Interrupt 0Occurred?
Call ISR INT0
IfPulse_Counter
=1001
Stop Timer0
Flow = TH0 x 256 +TL0
Flow = | flow – 25000 |
Flow = Flow x 1.3 (i.e resolution)
B
YES
NO
YES
NO
YES
NO
NO
Wireless Ultrasound Flood Monitoring System
53
Figure 3.27: Overall Flowchart of the system
3.4.2 Resolution calculations
The resolution of any device implies the ability of that device to measure the smallest
possible value any quantity. This section of the resolutions describes the resolution
calculation of level and flow in detail. Moreover, it also gives a brief idea about how the
level finding formula 3.1 and flow finding formula of equation 2.16 have been exploited
in the MCU programming.
Resolution calculation of level
From the formula of velocity, we have
tD v =
Where,
v = velocity of sound in m/s
D = distance traveled
t = time taken to travel distance D
vD t , =or
Wireless Ultrasound Flood Monitoring System
54
For, 1 cm of resolution for level
D = 1 cm
v = 340 m/s (assume)
Such that, t = 0.01/340
= 29.41 µs
Hence, it shows that to travel 1 cm of distance by ultrasound it takes 29.41 µs.
Now, the query comes into play, how to implement above fact by microcontroller
AT89C51 with 11.0592 MHz of crystal frequency?
We know that,
AT89C51 with 11.0592 MHz of crystal has machine cycle of period 1.085 µs,
So, The Number of machine cycle (MC) required to represent 1 cm is given as
Number of MC = ss
µµ
085.141.29
≈ 27
So, if we increase any variable depth (say) by one at each elapsed of 27 MC from the
time we send the burst of pulses until it is received; we finally come up with the required
value of distance stored in variable level.
Then, what is the minimum distance that can be measured with AT89C51 with crystal
11.0592 MHz?
We have,
Distance = velocity of sound * time elapsed
So,
Minimum Distance = Velocity of sound * possible minimum time- elapse that can be
detected by MCU
= 340 m/s * 1.085 µs
= 3.689 * 10-4 m
= 0.36 mm
Wireless Ultrasound Flood Monitoring System
55
Hence, the minimum distance that can be measured by AT89C51 with 11.0592 MHz of
crystal is 0.36mm.
Resolution Calculation for flow
From the equation 2.17 we have,
⎟⎟⎠
⎞⎜⎜⎝
⎛−×= 1
TT
v vrx
txs0
Where,
0v = velocity of a moving object
sv = velocity of sound
txT = time to send 1000 burst of pulses of 40 KHz
= 1000 x 25µs
= 25000µs
rxT = time to receive 1000 burst of reflected wave (which is shifted by Doppler Effect
around 40KHz)
Now minimum velocity that can be measured or resolution for flow:
⎟⎠⎞
⎜⎝⎛ −×= 1
2499925000 340 v0
= 0.013600544 m/s
= 1.3 cm/s
Moreover, the resolution can be increased by increasing the number of pulses as
illustrated in example below:
For example, if the 2500 burst pulses of 40 KHz is considered. Then
txT = 2500 x 25µs
= 62500 µs
Such that,
⎟⎠⎞
⎜⎝⎛ −×= 1
6249962500 340 v0
= 5.44 x 10 -3ms-1 = 5.44 mm/s
This indicates the flow having the resolution of 5.44mm/s.
Wireless Ultrasound Flood Monitoring System
56
3.5 Serial Communication
The data I/O of the PC depend upon the Microprocessor Architecture. It can employ
Memory Mapped I/O or I/O Mapped I/ O. In I/O Mapped I/O, the devices are identified
with the separate I/O address. The maximum numbers of devices in this approach that
can be well addressed depends upon the number of data bits in the Microprocessor
Architecture Design. For example 8 bit architecture in 8085 can address up to 256
devices using this approach. The data transfer for this approach is faster than the
Memory Mapped I/O because there is no need to go to memory address to fetch operands
time and again. However, the number of devices that can be addressed is limited and
small range than the Memory mapped I/O. The instructions such as IN and OUT are
used.
In Memory Mapped I/O, the devices are treated like the memory locations. The
addressability of I/O devices is much high and is determined by the number of Bits in the
Address Bus. The memory instructions such as LDA, STA, LDAX, STAX, are used for
data I/O in such approach.
Data transfer can occur in either of the two ways: Serial and Parallel data transfer in
synchronous and asynchronous mode. .Asynchronous mode is often used in data
communication between PC and the peripherals because of higher speed of the processor
than the peripheral devices in general. The asynchronous data transfer takes place bitwise
or character wise. The start bit, stop bit, parity bit are used for baud rates that is fixed to
be same at the both transmitting side and receiving side. UART such as Motorola’s
MC6850 is used for asynchronous data communication.
In synchronous mode there is provision of synchronization between the transmitter and
the receiver. The receiver can respond to the varying clock rate of the transmitter and the
data transfer takes place block wise rather than character wise. The start bit, stop bit and
parity bits are also used. The USRT chips are used for synchronous mode of data
communication.
Wireless Ultrasound Flood Monitoring System
57
In Parallel data transfer a number of lines are used to transfer a word at a time. This
technique is faster than the serial data communication technique however it is suitable
for short distance communication only. The printers and such peripherals use
parallel data transfer.
In serial data transfer a single line is used to transfer a bit at a time. This technique is
slower than parallel data transfer however highly economical. It is used for long distance
communication such as in internet. Most of the time serial data communication is of
interest. The signal high is indicated by MARK and the signal low level is called
SPACE. There are different protocols to govern the serial data transfer such as RS 232 C
(Now called as EIA-232), RS 423A and RS 422A that was developed in 1960s.]
Figure 3.28: waveform of serial data unit
3.5.1 Serial data communication in MCU
In Microcontroller there is one inbuilt chip called USART (Universal Synchronous
Asynchronous Receiver and Transmitter) that facilitates both the synchronous and
asynchronous data communication. The TXD (pin 11) and RXD (pin 10) of
AT89C51/AT 89C52 microcontroller are used for the serial communication purpose. In
this project we have implemented serial communication in polling mode rather than in
interrupt mode since we don’t need high speed of operation and we didn't have to mind
for the CPU Utilization Factor.
The PC side VB interface is used for fixing the data rate (asynchronous) half duplex
communication. There is the provision of setting the values of auto mode and manual
Wireless Ultrasound Flood Monitoring System
58
mode tracking. The data is wirelessly transmitted by the RF Transmitter at the site and
Received at the monitoring system by the RF receiver and finally to the PC via serial
Port.
3.5.2 RS232 Protocol
The protocol governing the serial communication in our case is RS232C.Some Features
of RS 232C Standard are listed below:
• EIA Standard 232 developed in early 1960s
• RS 232C in late 1960s.
• .Named as EIA-232C later however most commonly called RS 232C.
• Describes the function of 25 signal and handshake pin for serial data transfer.
• Describes the voltage levels, impedance levels, rise and fall times, maximum bit
rate and maximum capacitances for these signal lines.
• Connector should have 25 pins, the DTE should be Male and the DCE should be
female. However IBM reduced these 25 pins to 9 pins that are often required for
asynchronous communication. Those connectors are DB25 and DB9 connectors
respectively.
• Voltage levels: +3V to +15V->logic "0" For logic Low
-3V to -15V->logic "1" For logic High
-3V to +3V->Transition region (often avoided).
• Commonly used standard is: +12V for logic "0"
-12V for logic "1"
• The signal direction is specified with respect to the DCE (Data communication
Equipment).
• Both Chasis ground (pin 1) and Signal ground (pin 7) are available. To prevent
large AC induced ground currents in the signal ground
these two should be connected together only at the power supply in the terminal or
computer.
• TXD (pin 2), RXD (pin 3) make handshake signals for primary forward
communication channel.
• Most frequently used pins signals and the description is given below:
Wireless Ultrasound Flood Monitoring System
59
25 pin 9 pin Signal Direction Description
1 - - - Protective Ground
2 3 TD DTE→DCE Transmitted data
3 2 RD DCE→DTE Received Data
4 7 RTS DTE→DCE Request to send
5 8 CTS DCE→DTE Clear to Send
6 6 DSR DCE→DTE Data set Ready
7 5 DCD DCE→DTE Data Carrier Detect
8 1 DTR DTE→DCE Data terminal Ready
20 4 RI DCE→DTE Ring Indicator
22 9 DSRD DCE↔DTE Data Signal Rate Detector
Table 3.2: Pin description of DB-9 connector and its relation with the
DB- 25 connector with respect to pins
With these signal connection we can establish simplex, half-duplex and full-duplex
asynchronous communication. The connection between both DTEs can be emulated by
the careful examination of these signals such as Null Modem. we have used Half-duplex
communication in our project. Since 232C Standard is very old and not compatible with
the PC we have used MAX 232ACP IC (Line Driver/Translator) for the TTL
compatibility.
3.6 Software & Equipments
This section is intended to give some basic introduction and useful information about the
software and tools that we employed in to develop our system.
3.6.1 Proteus 6 Professional
Many CAD users dismiss schematic capture as a necessary evil in the process of creating
PCB layout but Proteus 6 Professional has always disputed this point of view. With PCB
Wireless Ultrasound Flood Monitoring System
60
layout now offering automation of both component placement and track routing, getting
the design into the computer can often be the most time consuming element of the
exercise. And if you use circuit simulation to develop your ideas, you are going to spend
even more time working on the schematic.
ISIS has been created with this in mind. It has evolved over twelve years research and
development and has been proven by thousands of users worldwide. The strength of its
architecture has allowed us to integrate first conventional graph based simulation and
now - with PROTEUS VSM - interactive circuit simulation into the design environment.
For the first time ever it is possible to draw a complete circuit for a micro-controller
based system and then test it interactively, all from within the same piece of software.
Meanwhile, ISIS retains a host of features aimed at the PCB designer, so that the same
design can be exported for production with ARES or other PCB layout software.
The Proteus Professional v 6.9, Lab Center Electronics 1990-2005, has been used for the
simulation and PCB layout designed purpose in our system. And this software proved to
be the most comprehensive tool for testing many microcontroller based circuitry with
MCU coding, of course and it has also helped to give professional look to our circuit.
Proteus used in Simulation
We have used the Proteus ISIS professional to carry out the simulation of our design and
checking the corrective ness of the coding done in C language. The library of the ISIS
was rich in the commercially available ICs, which proved to be fruitful for us to check
the output of circuit at various conditions and to check the feasibility of any new
components to be added in the systems.
During the simulation of our system, ISIS had been very useful to test the code from the
very beginning. As the Proteus ISIS professional don’t have simulation facility for the
ultrasonic transducers we had to test the entire code of the system by providing the
induced interrupts by the use of buttons for level interrupt and Digital clock generator for
the flow interrupt as shown in the figure 3.29 below.
Wireless Ultrasound Flood Monitoring System
61
Figure 3.29: Snap shot of simulation circuit to test the code in Porteus ISIS
professional
Proteus used in PCB design:
We have used the Proteus ARES professional for the PCB design. The design of PCB
was employed manually rather than using the self routing tool ELECTRA available in
ARES.
Wireless Ultrasound Flood Monitoring System
62
Figure 3.30: Designed PCB layout
3.6.2 MCU Programming in C
The programming of MCU is done in Assembly language, C language etc. Among then
we have chosen C language programming instead of Assembly language programming
due to the various reasons as explained followings:
Wireless Ultrasound Flood Monitoring System
63
When compliers complies the code written in C language to produce Hex files, that
loaded into the ROM of MCU. The size of HEX file is larger with respect to the HEX
file produced by the program written in assembly language.
As MCU has limited on chip ROM. For example AT89C51 MCU has only 4KB of
ROM. Moreover, memory can only be extended up to 64KB as address bus used is of 16
bits.
Hence, the size of HEX file produced by the complier is the major issue while writing
the code in MCU.
Assembly language Vs C language
In spite of the problem explained above while doing the MCU programming in C
language, we chose C language because the assembly language is tedious and time
consuming while the C language is much easier and less time consuming to write
program. Furthermore, program in C sis easier to modify, update and more importantly
to debug. C language also allows us to use codes available in function libraries.
C data types for MCU
This sections attempts to review some of the widely used C data types in MCU. The
section explain how the proper use of C data types is carried out, such that the
programmer would be able to produce small size of HEX file as much as possible.
Unsigned char: The unsigned char is an 8 bit data types that takes the value in the range
of 0-255 (00-FFH). It is most widely used data types for MCU. By default, C compilers
assume as signed char if we don’t put keyword unsigned in front of char. it is also used
for the ASCII character as genuinely used in C language.
Signed char: It is also an 8 bit data type using D7 among (D7-D0) of 1 byte data to
represent the ‘+’ or ‘-‘ sign of the magnitude, such that there are only 7 bits for the
magnitude of signed numbers giving range of (-128 to 127). This data types is used
where the sign of the magnitude becomes vital.
Wireless Ultrasound Flood Monitoring System
64
Unsigned int: When the values of variables exceed 256 then the unsigned int comes into
play. This is 16 bits data type giving the range of 0 – 65535 (0000 – FFFFH), it occupies
2 bytes of RAM space of MCU. Hence, misuse of this data type will result in
unnecessary increase in size of HEX file.
Signed int: It uses D15 bit of (D15 – D0) data to represent sign as described in case of
signed char, giving the magnitude range of (-32,768 to +32767)
Finally, it can be concluded that when the variables are declared during programming the
MCU in C language,
• The programmer should drag his/her attention to the size of the data types & its
intended use.
• There should not be unnecessary declaration of variables, i.e. no redundant
declaration or optimum use of the declared variable.
If one takes care of the above mentioned point then s/he will be able to mitigate the size
of HEX files effectively.
3.6.3 SDCC compiler
SDCC (Small Device C Compiler) is free open source, retarget table; optimizing ANSI-
C compiler by Sandeep Dutta designed for 8 bit Microprocessors. The current version
targets Intel MCS51 based Microprocessors (8031, 8032, 8051, 8052, etc.), Dallas
DS80C390 variants, Freescale (formerly Motorola) HC08 and Zilog Z80 based MCUs. It
can be retargeted for other microprocessors, support for Microchip PIC, Atmel AVR is
under development. SDCC has extensive language extensions suitable for utilizing
various microcontrollers and underlying hardware effectively. The Supported data-types
are: bool, char, short, int ,long, float
Compiling in SDCC
For single source file 8051 projects the process is very simple. Compile your programs
with the following command "sdcc sourcefile.c". This will compile, assemble and link
your source file. Output files are as follows:
Wireless Ultrasound Flood Monitoring System
65
sourcefile.asm ,sourcefile.lst , sourcefile.rst , sourcefile.sym, sourcefile.rel or
sourcefile.o, sourcefile.map, sourcefile.mem, sourcefile.ihx , sourcefile.adb,
sourcefile.cdb, sourcefile. - (no extension) .
Post processing the Intel Hex file
In most cases this won’t be needed but the Intel Hex file which is generated by SDCC
might include lines of varying length and the addresses within the file are not guaranteed
to be strictly ascending. If your tool chain or a boot loader does not like this you can use
the tool packihx which is part of the SDCC distribution:
packihx sourcefile.ihx >sourcefile.hex
Now the Sourcefile.hex is loaded in the ROM of MCU using the software EZ-
Downloader v4.1 as shown in figure 3.31
Figure 3.31: snap shot of outlook of EZ-Downloader
for example:
let us consider we have written a code in notepad and saved it as ultrasound.c.
then first we enter into the command prompt and further enter into the correct path where
the ultrasound.c is saved in.
next we type “sdcc ultrasound.c”
then”packihx ultrasound.ihx>ultrasound.hex”
now ultrasound.hex is available to be loaded into the ROM of MCU. This process is
illustrated in figure 3.32 below.
Note: while declaring the array of unsigned char, put “code” before variable name as:
unsigned char code var_name[ ]. This will compile the var_name[ ] in separate code
memory, such that internal memory (127 bytes) scarcity will not occur.
Wireless Ultrasound Flood Monitoring System
66
Figure 3.32: Compiling ultrasound.c using SDCC
3.6.4 Visual basic 6.0 The PC Motoring Station in our project interfaces the user via VB 6.0 interface. Visual
Basic provides a complete graphical user friendly interface with its integrated
development environment. This development environment has many tools, applications
and even the wizard for the development for frequent applications.
The Visual Basic Environment provides users facilities to build many applications. This
allows users with even little programming knowledge and experience to build strong and
useful applications. Many Object Linking and Embedding OLE; Active Controls can be
added for versatility in the program. Programs such as Excel Spreadsheet can be
embedded to develop programs that can be used in Front End Applications to a Back
End (database )system , serving as the user interface which collects user input and
displays the processed output in more appealing and interesting way. The SQL is used to
bind the front end and the back end in our application.
Much of the outline code is generated by VB such as drawing line, Box, Color Setting,
Formatting the objects and therefore the programmer has no overhead of extra coding
other than the main event triggered coding. The main objects of VB are Form, The
Buttons, Text areas, Menus, Dropdown list, Controls etc. The graphical interface and
Tools, Running Compiling and Debugging are easily accomplished.
Wireless Ultrasound Flood Monitoring System
67
Serial Communication is mainly used in our PC Monitoring station. This allows the
incoming information from the remote site location to the Monitoring Station and vice
versa. The form takes the input of auto-mode time setting value and has the display for
the retrieved data from the site for the flow and level of the liquid. Some alarming
provision is also added. Further, our program has the database of the Real Time Data
retrieved from the site and also has capability to plot the latest 10 values via the Bar
Diagram which helps to interpret and statistic analysis. Further, Site Control signals are
also generated.
(a)
(b)
Figure 3.33: Snap shot of interfacing Form designed using
Visual Basic (a) Manual Mode (b) Auto Mode
Wireless Ultrasound Flood Monitoring System
68
Figure 3.34 : Plots of measured values of level and flow
3.6.5 0scilloscope
An oscilloscope (sometimes abbreviated CRO, for cathode-ray oscilloscope, or
commonly just scope or O-scope) is a type of electronic test equipment that allows signal
voltages to be viewed, usually as a two-dimensional graph of one or more electrical
potential differences (vertical axis) plotted as a function of time or of some other voltage
(horizontal axis).
One of the most frequent uses of scopes is troubleshooting malfunctioning electronic
equipment. One of the advantages of a scope is that it can graphically show signals:
where a voltmeter may show a totally unexpected voltage, a scope may reveal that the
circuit is oscillating. In other cases the precise shape of a pulse is important.
In a piece of electronic equipment, for example, the connections between stages (e.g.
electronic mixers, electronic oscillators, amplifiers) may be 'probed' for the expected
Wireless Ultrasound Flood Monitoring System
69
signal, using the scope as a simple signal tracer. If the expected signal is absent or
incorrect, some preceding stage of the electronics is not operating correctly. Since most
failures occur because of a single faulty component, each measurement can prove that
half of the stages of a complex piece of equipment either work, or probably did not cause
the fault.
Once the faulty stage is found, further probing can usually tell a skilled technician
exactly which component has failed. Once the component is replaced, the unit can be
restored to service, or at least the next fault can be isolated.
Another use is for software engineers who must program electronics. Often a scope is the
only way to see if the software is running the electronics properly.
Another use is to check newly designed circuitry. Very often a newly designed circuit
will misbehave because of design errors, bad voltage levels, electrical noise etc. Digital
electronics usually operate from a clock, so a dual-trace scope which shows both the
clock signal and a test signal dependent upon the clock is useful. "Storage scopes" are
helpful for "capturing" rare electronic events that cause defective operation.
3.6.6 Digital multimeter
Digital multimeter usually employ an electronic circuit that acts as an integrator, linearly
ramping output voltage when input voltage is constant (this can be easily realized with
an opamp). The dual-slope integrator method applies a known reference voltage to the
integrator for a fixed time to ramp the integrator's output voltage up, then the unknown
voltage is applied to ramp it back down, and the time to ramp output voltage down to
zero is recorded (realized in an ADC implementation). The unknown voltage being
measured is the product of the voltage reference and the ramp-up time divided by the
ramp-down time. The voltage reference must remain constant during the ramp-up time,
which may be difficult due to supply voltage and temperature variations.
Wireless Ultrasound Flood Monitoring System
70
3.7 Problem faced During the period of the project, we have come across the lots of genuine problem that
are encountered in any project. So, those problems have not been addressed here. Rather
the major problems of our project have been described here.
Problem in Hardware
As hard to theoritize any concept, much harder is to realize the system with electronic
component. The commercially available ICs and other components don’t operate with
expected reliability.
The simplicity in the circuitry seems that it is a single day work to complete the project.
But after starting, one will experience what obstacles might one face in the course of
making a system synchronizing hardware and software. It is simple to realize the
circuitry module wise during the first attempt, if you are lucky. However, one can
succeed in realizing modules with several serious attempts. For instant, talking about
power supply. It is full of spikes which if used directly may damage the ICs used. So, use
of decoupling capacitor is mandatory.
We started our circuitry design in "bread board" which has a lot of errors in itself. In
order to overcome unseen resistances and leakages that can occur in breadboard, we
switched to realize the circuitry with dot-matrix board. But this proved to be a nightmare.
It took days to build the circuitry which caused massive loss of precious time. At the
same time, the dot-matrix board proved to be further noisier. The initial build was neat
and clean. But as the circuit didn't work so we had to replace the live wire without
removing the insulation plastic. Finally after use a lot of jumpers, replacing and
displacing, the circuit started working. But it took three days to complete the circuitry
and even longer (five days!!) to debug it, for proper working.
Finally we decided to switch to PCB design of our system circuitry. And truly speaking
this is the best method in order to realize circuitry. It took less time and effort to build
up. If one undermines the cost of the PCB board design in easy. In the process we used
ARES of Proteus Professional 6 for the design.
Wireless Ultrasound Flood Monitoring System
71
The previous two methods proved to be cumbersome and can be strictly avoided if one
considers time value of money. Even after PCB design, we had a serious error in
detecting signal because the comparator used to detect the noise always produced logic 1.
From previous work on this project, we found that the problem persisted because of the
transducers. The assumption made was that instead of the ultrasonic sound being
reflected from obstacle surface, the beam of ultrasound is directly received by the
receiver transducer directly. But an intensive, dedicated & long analysis we found the
root cause of the problem. The method initially used was dividing the circuit modules
and conquer. But this proved worthless. The circuit was still buggy and we had no
solutions still. Then after consulting with some senior teachers, we were suggested to use
a resistor across the input of comparator and ground. Testing this on circuit didn't prove
to be fruitful. However the advanced simulation ISIS of Proteus Professional 6 proved to
be a boon.
We carried out the simulations and it yielded the same problem as the hardware circuitry.
Then, we used resistor across input of comparator LM358 and ground, and simulated for
various value of resistors. Finally, we got it through.
The previous work on this project had only concept to measure flow and some ideas on
how to carry the task of finding flow. But we used our own concept of changing the
amplified sine wave from LM833 to square wave to find the frequency of received wave.
The concept was made but it took few days to find appropriate circuitry for the process.
Moreover, sometime use of LCD can be troublesome where LCD might be working but
the contrast may not be set properly. In general, we can ground the Pin 3 of LCD for
optimum contrast.
Problem in Software
The major challenges that we encountered in programming is during the calculation of
flow. In fact, the ultrasound that we used having feature of 40 KHz is responsible for the
following problem.
Wireless Ultrasound Flood Monitoring System
72
Because 40 KHz of signal has 25 µs of time period and as already mentioned above
during calculation of flow we are supposed to count up the predetermined number of
reflected and received pulses. To count each consecutive pulses only time around 25µs is
available. So the instruction to count the pulses should not have length longer than 25µs
(at most).
In programming to count the burst of pulses we used external hardware interrupt, so it
was always challenge for us to shorten or limit the interrupt service routine of that
interrupt. Moreover, we used the C language instead of Assembly language, which made
our challenge more challenging. Because, unlike in Assembly language, it is always
tough to calculate the machine cycle spent of any instruction in C language.
So, as a solution, we decided not to increase the length of ISR of flow’s external
hardware interrupt. Such that we wrote only one instruction to increase the pulse counter.
And to enable the flow’s external hardware interrupt, we took the help of level’s external
hardware interrupt.
Now, initially we enabled the level’s interrupt and as the reflected wave is received the
level’s interrupt is generated. And in level’s interrupt’s ISR the flow’s interrupt is
enabled. While, at the mean time interestingly, in level’s ISR it disable itself.
Moreover if we were availed with MCU with machine cycle in the range of nanoseconds,
we could have time flexibility in ISR (more instructions could have been written inside
ISR without expending more time) that could enhance the precision, resolution and
ultimately accuracy in flow measurement.
Wireless Ultrasound Flood Monitoring system
73
Result and Conclusion
4.1 Results
Due to the limitation of ultrasonic transducers used we could successfully measure the
level of the fluid only up to 2.55 m with resolution of 1 cm (However, it can be increased
up to 0.33 mm). Similarly, in case of measuring flow we could measure the range of flow
rather than accurate flow as set with the resolution of 1.3cm/s.(However, it can be
increased up to 5.44 mm/s). However, we are very hopeful that the circuit would perform
more reliably, if the received wave from the Ultrasound Receiver is filtered and digitized
using ADC.
4.2 Limitation
As far as the limitation of our system is concerned, we could not confirm the accuracy of
value of flow being measured by our system, due to the unavailability of flow measuring
device like flow meter. Moreover, the value of flow wasn’t consistent. Similarly, in case
of level it could detect up to 2.5 meter only. So, it has become the prototype only and to
implement the system in real scenario, we need more sophisticated transducers.
4.3 Conclusion
In our system the flow range detection is good enough to meet our requirement. Precise
level measurement and range flow detection is sufficient to inform and alarm the people
to be aware of flood. Moreover, if we get the consistence value of flow, the system has
the broad application in industries where the information about the flow of any fluid is
vital.
4.4 Future Enhancements
The recommendation for the future enhancements in the project can be:
• To obtain the accuracy in flow such that discharge of the liquid could be measured
• To apply various statistical approaches to accommodate turbulent flow
• Posting the data in the internet such that it could be monitored form any part of the
world
Wireless Ultrasound Flood Monitoring system
74
References
1. Muhammad Ali Mazidi, Janice Gillispie Mazidi , Rolin D. McKinlay, The 8051
Microcontroller and Embedded Systems Using Assembly and C, Second Edition.
2. Kim R. Fowler,Electronic Instrument Design, Architecting for Life cycle.
3. Rajesh Gyawali,Rakshya Shrestha, Rosish Shakya, Shristi Adhikari, “Wireless
Remote Water Level Monitoring System using Ultrasound.”
4. Websites:
http://www.national.com
http://www.alldatasheet.com
http://www.edaboard.com
http://www.8052.com
http://www.en.wikipedia.org
http://hyperphysics.phy-astr.gsu.edu
http://www.interq.or.jp
Wireless Ultrasound Flood Monitoring system
75
APPENDIX A LIQUID CRYSTAL DISPLAY (LCD)
The liquid crystal display (LCD) is passive display equipment. This means it doesn’t emit
light; instead, it uses the ambient light in the environment. By manipulating this light, it
displays required text using very little power. This has made LCDs preferred technology
whenever low power consumption and compact size is critical hence; it is suitable for use
in battery-powered electronic devices. It is a thin, flat display device made up of any
number of color or monochrome pixels arrayed in front of a light source or reflector.
Each pixel of an LCD consists of a layer of liquid crystal molecules aligned between two
transparent electrodes, and two polarizing filters, the axes of polarity of which are
perpendicular to each other. With no liquid crystal between the polarizing filters, light
passing through one filter would be blocked by the other. The surfaces of the electrodes
that are in contact with the liquid crystal material are treated so as to align the liquid
crystal molecules in a particular direction.
Before applying an electric field, the orientation of the liquid crystal molecules is
determined by the alignment at the surfaces. In a twisted nematic device (the most
common liquid crystal device), the surface alignment directions at the two electrodes are
perpendicular, and so the molecules arrange themselves in a helical structure, or twist.
Because the liquid crystal material is birefringent (i.e. light of different polarizations
travels at different speeds through the material), light passing through one polarizing
filter is rotated by the liquid crystal helix as it passes through the liquid crystal layer,
allowing it to pass through the second polarized filter. Half of the light is absorbed by the
first polarizing filter, but otherwise the entire assembly is transparent.
When a voltage is applied across the electrodes, a torque acts to align the liquid crystal
molecules parallel to the electric field, distorting the helical structure. This reduces the
rotation of the polarization of the incident light, and the device appears gray. If the
applied voltage is large enough, the liquid crystal molecules are completely untwisted
and the polarization of the incident light is not rotated at all as it passes through the liquid
crystal layer. This light will then be polarized perpendicular to the second filter, and thus
Wireless Ultrasound Flood Monitoring system
76
be completely blocked and the pixel will appear black. By controlling the voltage applied
across the liquid crystal layer in each pixel, light can be allowed to pass through in
varying amounts, correspondingly illuminating the pixel.
LCD provides a useful interface for the user, debugging an application or just giving it a
"professional" look. The most common type of LCD controller provides a relatively
simple interface between a processor and an LCD. Using this interface is often not
attempted by inexperienced designers and programmers because it is difficult to find
good documentation on the interface, initializing the interface can be a problem and the
displays themselves are expensive.
The 2 lines x 16 character LCD modules are available from a wide range of
manufacturers and should all be compatible with the HD44780. The diagram below
shows the pin numbers for these devices. When viewed from the front, the left pin is pin
14 and the right pin is pin 1.
Figure A.1:- Structure of 2X16 LCD
44780 standards:
The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data
bus. The user may select whether the LCD will require a total of 11 data lines (3 control
lines plus 8 lines for the data bus). The three control lines are referred to as EN, RS and
RW.
Wireless Ultrasound Flood Monitoring system
77
EN:
The EN line is called “Enable”. This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should make sure this line is low
and then set the other two control lines and/or put data on the data bus. When other lines
are completely ready, set EN high and wait for the minimum amount of time as specified
in the data sheet and end by bringing it back to low again.
RS:
The RS line is the “Register Select” line. When RS is low, the data is to be treated as a
command or special instruction. When RS is high the data being sent is text data, which
should be displayed on the screen. For example, to display the letter “T” on the screen
you would set RS high.
RW:
The RW line is the “Read/Write” control line. When RW is low, the information on the
data bus is being written on the LCD. When RW is high, the program is effectively
querying or reading the LCD. Only one instruction is a read command. All others are
write commands so RW will almost always be low.
D0 – D7:
The 8-bit data pins, D0 – D7, are used to send information to the LCD or read the
contents of the LCD’s internal registers.
To display letters and numbers, we send ASCII codes for the letters A – Z, a – z and
numbers 0 – 9 to these pins while making RS = 1.There are also instruction command
codes that can be sent to the LCD to clear the display or force the cursor to the home
position or blink the cursor. Table A below lists the instruction command codes.
We also use RS = 0 to check the busy flag bit to see if the LCD is ready to receive
information. The busy flag is D7 and can be read when R/W = 1 and RS = 0, as follows:
if R/W = 1, RS = 0. When D7 = 1(busy flag =1), the LCD is busy taking care of internal
operations and will not accept any new information. When D7 = 0, the LCD is ready to
receive new information. It is always recommended to check the busy flag before writing
any data to the LCD.
Wireless Ultrasound Flood Monitoring system
78
Table A.1 : LCD Command Codes
Code (Hex) Command to LCD Instruction
Register
1 Clear display screen
2 Return Home
4 Decrement Cursor(shift cursor to left)
6 Increment Cursor(shift cursor to right)
5 Shift Display right
7 Shift Display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning of first line
C0 Force cursor to beginning of second line
38 2 lines and 5 X 7 matrix
Wireless Ultrasound Flood Monitoring system
79
APPENDIX B KEYPAD INTERFACING WITH MCU
This section describes the basic circuit of 4 X 4 matrix keypad using push to on switches
and the basic algorithm to interface the keypad with MCU. The circuit of figure C.1
shows the 4x4 matrix keypad connected to a single port. The rows are connected to an
output port (upper nibble of the port) and the columns are connected to input port (lower
nibble of the port). If no key has been pressed, reading the input port will yield 1s for all
columns since they are all connected to high (Vcc). If all the rows are grounded and a key
is pressed, one of the columns will have 0 since the key pressed provides the path to
ground. It is the function of the MCU to scan the keypad continuously to detect and
identify the key pressed. The process described as below:
The process is proceeding with grounding rows and reading the columns. To detect a
pressed key, the MCU grounds all rows by providing 0 to the output latch, that it reads
the columns. If the data read from the columns is D3 – D0 = 1111, no key has been
pressed and the process continues until a key press is detected. However, if one of the
column bits has a zero, this means that a key press has occurred. For example, if D3 – D0
= 1101, this means that a key in the D1 column has been pressed. After a key press is
detected, the MCU will go through the process of identifying the key. Starting with the
top row, the MCU grounds it by providing a low to row D0 only: then it reads the
columns. If the data read is all 1s, no key in that row is activated and the process is
moved to the next row. It grounds the next row, read the columns, and checks for any
zero. This process continues until the row is identified. After identification of the row in
which the key has been pressed, the next task is to find out which column the pressed key
belongs to. This should be easy since the MCU knows at any time which row and column
are being accessed.
The entire process has also been described in flowchart figure C.2
Wireless Ultrasound Flood Monitoring system
80
Figure C.1: Circuit diagram of Keypad
The figure C.1 shows the circuit diagram of keypad of 4X4 array with 16 push to on
switches. Both ends of the switches are connected to the pin of a single port with resistors
connected to the Vcc. The value of the resistor we used is of 4.7 KΩ
Wireless Ultrasound Flood Monitoring system
81
Figure C.2 : Flowchart for keypad programming
Wireless Ultrasound Flood Monitoring system
82
APPENDIX C
COST ANALYSIS
List Of Components Quantity Cost/piece Total Cost in Rupees
LM833N 1 120 120
LM358 1 80 80
AT89C51 1 150 150
CD4011 1 60 60
CD4069 1 60 60
L7809 1 20 20
L7805 1 15 15
74HC04 1 40 40
555 Timer 1 20 20
MAX232 1 80 80
Resistors/Diodes - 70 70
Capacitors - 100 100
Crystal Oscillator 1 35 35
Ultrasonic Transducers 2 850 1700
Transistors 2 20 40
Connecting Wires - 100 100
RF modules 4 1650 6600
LCD 1 640 640
Total Cost 9930
Wireless Ultrasound Flood Monitoring System
44
3.3.5 Circuit Diagram