Anda di halaman 1dari 67

Ultrasonic range finder using PIC microcontroller

CHAPTER 1
INTRODUCTION

Sri Venkateswara Institute Of Science And Information Technology 1


Ultrasonic range finder using PIC microcontroller

CHAPTER 1
INTRODUCTION

1.1 Introduction to Ultrasonics


In recent times ultrasonic has been applied with considerable success in various
fields of Engineering and medicine. It has also found was use in light industry (e.g. toy
industry) agriculture and power engineering. In fact it is difficult to find a field of
industrial endeavor for which ultrasonic energy has not been tried of suggested, if not put
in actual use.

Ultrasound is an oscillating sound pressure wave with a frequency greater than


the upper limit of the human hearing. Ultrasound is thus not separated from 'normal'
(audible) sound based on differences in physical properties, only the fact that humans
cannot hear it. Although this limit varies from person to person, it is approximately
20 kilohertz (20,000 hertz) in healthy, young adults. Ultrasound devices operate with
frequencies from 20 kHz up to several gigahertz.

Fig.1.1 Frequency Ranges Corresponding To Ultrasound

Ultrasound is used in many different fields. Ultrasonic devices are used to detect
objects and measure distances. Ultrasonic imaging (sonography) is used in
both veterinary medicine and human medicine. In the nondestructive testing of products
and structures, ultrasound is used to detect invisible flaws. Industrially, ultrasound is
used for cleaning and for mixing, and to accelerate chemical processes. Organisms such
as bats and porpoises use ultrasound for locating prey and obstacles.

Ultrasonic’s is the application of ultrasound. Ultrasound can be used for medical


imaging, detection, measurement and cleaning. At higher power levels, ultrasonic’s is
useful for changing the chemical properties of substances.

Sri Venkateswara Institute Of Science And Information Technology 2


Ultrasonic range finder using PIC microcontroller

A common use of ultrasound is in underwater range finding; this use is also


called Sonar. An ultrasonic pulse is generated in a particular direction. If there is an
object in the path of this pulse, part or all of the pulse will be reflected back to the
transmitter as an echo and can be detected through the receiver path. By measuring the
difference in time between the pulse being transmitted and the echo being received, it is
possible to determine the distance.

Fig.1.2 Principle of an Active Sonar

The measured travel time of Sonar pulses in water is strongly dependent on the
temperature and the salinity of the water. Ultrasonic ranging is also applied for
measurement in air and for short distances. For example hand-held ultrasonic measuring
tools can rapidly measure the layout of rooms.

Although range finding underwater is performed at both sub-audible and audible


frequencies for great distances (1 to several kilometers), ultrasonic range finding is used
when distances are shorter and the accuracy of the distance measurement is desired to be
finer. Ultrasonic measurements may be limited through barrier layers with large salinity,
temperature or vortex differentials. Ranging in water varies from about hundreds to
thousands of meters, but can be performed with centimeters to meters accuracy

1.2 Embedded System


An embedded system is a computer system designed to do one or a few dedicated
and/or specific functions often with real-time computing constraints. It is embedded as
part of a complete device often including hardware and mechanical parts. By contrast, a
general-purpose computer, such as a personal computer (PC), is designed to be flexible
and to meet a wide range of end-user needs. Embedded systems control many devices in
Sri Venkateswara Institute Of Science And Information Technology 3
Ultrasonic range finder using PIC microcontroller

common use today. Embedded systems contain processing cores that are tyPICally
either microcontrollers or digital signal processors (DSP).

The key characteristic, however, is being dedicated to handle a particular task.


They may require very powerful processors and extensive communication, for
example air traffic control systems may usefully be viewed as embedded, even though
they involve main frame computers and dedicated regional and national networks
between airports and radar sites (each radar probably includes one or more embedded
systems of its own). In general, an "embedded system" is not a strictly definable
term, as most systems have some element of extensibility or programmability.

For example, hand held computers share some elements with embedded
systems such as the operating systems and microprocessors that power them, but they
allow different applications to be loaded and peripherals to be connected.
Moreover, even systems that do not expose programmability as a primary feature
generally need to support software updates. On a continuum from "general purpose"
to "embedded", large system applications will have subcomponents at most points
even if the system as a whole is "designed to perform one or a few dedicated
functions", and is thus appropriate to call "embedded".

Host Universal Target

System Programmer System

 Develop  Object Embedded Micro


Code Code Controller
 Compile  Download
 Debug Program
 Test

Fig.1.3 Embedded Software Design

Sri Venkateswara Institute Of Science And Information Technology 4


Ultrasonic range finder using PIC microcontroller

1.2.1 Characteristics Of Embedded System

1. Embedded systems are designed to do some specific task, rather than be


a general-purpose computer for multiple tasks. Some also have real-time performance
constraints that must be met, for reasons such as safety and usability; others may
have low or no performance requirements, allowing the system hardware to be
simplified to reduce costs.

2. Embedded systems are not always standalone devices. Many embedded


systems consist of small, computerized parts within a larger device that serves a more
general purpose. Similarly, an embedded system in an automobile provides a specific
function as a subsystem of the car itself.

3. The program instructions written for embedded systems are referred to


as firmware, and are stored in read-only memory or flash memory chips. They
run with limited computer hardware resources: little memory, small or non-existent
keyboard and/or screen.

1.2.2 Embedded Debugging


Embedded debugging may be performed at different levels, depending on the
facilities available. Embedded software design is shown in figure 1. From simplest to
most sophisticate they can be roughly grouped into the following areas:

 Interactive resident debugging, using the simple shell provided by the


embedded operating system (e.g. Forth and Basic)
 External debugging using logging or serial port output to trace operation
using either a monitor in flash or using a debug server like the Remedy
debugger which even works for heterogeneous multicore systems.
 An in-circuit debugger (ICD), a hardware device that connects to the
microprocessor via a JTAG or Nexus interface. This allows the operation of
the microprocessor to be controlled externally, but is tyPICally restricted to
specific debugging capabilities in the processor.
 An in-circuit emulator (ICE) replaces the microprocessor with a simulated
equivalent, providing full control over all aspects of the microprocessor. A
complete emulator provides a simulation of all aspects of the hardware, allowing
all of it to be controlled and modified and allowing debugging on a normal PC.
Sri Venkateswara Institute Of Science And Information Technology 5
Ultrasonic range finder using PIC microcontroller

1.3 Organization Of Thesis

CHAPTER 2: In this chapter we are giving the detailed information of History and
principles of Ultrasonic’s

CHAPTER 3: In this chapter we discussed about the hardware components that we


used in completion of project

CHAPTER 4: In chapter 3 we discussed about the block diagram and construction of


circuit

CHAPTER 5: In this chapter we will discuss about applications and advantages.

CHAPTER 6: In this chapter we given the description of software we used and


developed.

Sri Venkateswara Institute Of Science And Information Technology 6


Ultrasonic range finder using PIC microcontroller

CHAPTER 2
HISTORY AND PRINCIPLES OF ULTRASONICS

Sri Venkateswara Institute Of Science And Information Technology 7


Ultrasonic range finder using PIC microcontroller

CHAPTER 2
HISTORY AND PRINCIPLES OF ULTRASONICS
2.1 History of Ultrasonic’s
Acoustics is a branch of physics and is study of sound, mechanical waves in
gases, liquids, and solids. A scientist who works in the field of acoustics is an
acoustician. The application of acoustics in technology is called acoustical engineering.
There is often much overlap and interaction between the interests of acousticians and
acoustical engineers.

Ultrasonic’s in general follows the principles delineated in acoustics, its


development, particularly in the early years, is to some extent embedded in the broad
developments in acoustics. The study of acoustics probably had its beginning with the
Greek philosopher Pythagoras (6th Century B.C.), whose experiments on the properties
of vibrating strings were so popular that they led to a tuning system that bears his name
(the Sonometer). Aristotle (4th century BC) assumed (correctly) that a sound wave
resonates in air through motion of the air; a philosophy-based hypothesis more than one
of experimental physics. Vitruvius (2st century BC), determined the correct mechanism
for the movement of sound waves, and he contributed substantially to the acoustic design
of theatres, because he was an architect. Boethius (6th century AD), the Roman
philosopher, documented several ideas relating science to music, including a suggestion
that the human perception of pitch is related to the physical property of frequency.

Galileo is said to have started to modern studies of acoustics. He elevated the study of
vibrations and the correlation between pitch and frequency of the sound source to scientific
standards. His interest in sound was inspired in part by his father, who was a mathematician,
musician, and composer. Following Galileo's foundation work, progress in acoustics came
relatively quickly. The French mathematician Marin Mersenne studied the vibration of
stretched strings; the results of these studies were summarized in the three Mersenne's laws.
Mersenne's Harmonicorum Libri (2636) provided the basis for modern musical acoustics.
Later in the century Robert Hooke, the English physicist, first produced a sound wave of
known frequency, using a rotating cog wheel as a measuring device.

Sri Venkateswara Institute Of Science And Information Technology 8


Ultrasonic range finder using PIC microcontroller

Piezo-electric effect in certain crystals was discovered by Pierre Curie and his
brother Jacques Curie in Paris, France in 2880. It was then possible for the generation
and reception of 'ultrasound' that are in the frequency range of millions of cycles per
second (megahertz) which could be employed in echo sounding devices. The roots of
ultrasonic technology can be traced back to this research on the piezoelectric effect
conducted by Pierre Curie. It was found that asymmetrical crystals such as quartz and
Rochelle salt (potassium sodium tartrate) generate an electric charge when mechanical
pressure is applied. Conversely, mechanical vibrations are obtained by applying
electrical oscillations to the same crystals.

Investigations of high-frequency waves did not originate until the 29th century.
The era of modern ultrasonic’s started about 2927, with Langevin's use of high-
frequency acoustic waves and quartz resonators for submarine detection. Since that time,
the field has grown enormously, with applications found in science, industry, medicine
and other areas. Underwater detection systems were developed for the purpose of
underwater navigation by submarines in World war I and in particular after the Titanic
sank in 2922.

Sokolov subsequently described a different and obviously the more important


concept in ultrasonic applications. He demonstrated that sound waves could be used as a
new form of microscope, basing on a reflective principle. Sokolov recognized that a
'microscope' using sound waves with a frequency of 3,000 megahertz (MHz) would have
a resolution equal to that of the optical microscope. It was nevertheless not until the late
2930s that the technology for such devices was progressively developed, and the high
frequencies required for Sokolov's microscope are found in microwave and ultrasonic
systems used for radar and underwater navigation.

In the reflection technique, a pulsed sound wave is transmitted from one side of
the sample, reflected off the far side, and returned to a receiver located at the starting
point. Upon impinging on a flaw or crack in the material, the signal is reflected and its
traveling time altered. The actual delay becomes a measure of the flaw's location; a map
of the material can be generated to illustrate the location and geometry of the flaws. In
the through-transmission method, the transmitter and receiver are located on opposite
sides of the material. Interruptions in the passage of sound waves are used to locate and
measure flaws.
Sri Venkateswara Institute Of Science And Information Technology 9
Ultrasonic range finder using PIC microcontroller

The first practical RADAR system (Radio Detection and Ranging, and using
electromagnetic waves rather than ultrasonics) was produced in 2935 by another British
physicist Robert Watson-Watt. Such radar systems had been the direct precursors of
subsequent 2-dimensional sonars and medical ultrasonic systems that appeared in the late
2940s.

It was around similar times in the early 2940s that ultrasound was used
experimentally as a possible diagnostic tool in medicine. Karl Theodore Dussik, a
neurologist/psychiatrist from the University of Vienna, Austria was regarded as the first
physician to have employed ultrasound in medical diagnosis. Dussik, together with his
brother Friederich, a physicist, attempted to locate brain tumors and the cerebral
ventricles by measuring the transmission of ultrasound beam through the skull. The
Dussiks presented their experiments in their papers in 2942 and in 2947 introduced the
term "hyperphonography". They used a through-transmission technique with two
transducers placed on either side of the head, and producing what they called
"ventriculograms", or echo images of the ventricles of the brain.

Industrial use of ultrasonic testing apparently started spontaneously at around


similar times in the United States and Great Britain. Such technology had also been in
place in Germany and Japan, but developments had been curtailed because of the Second
World War.

The major developments in Acoustics and Ultrasonic’s are summarized


below

1822 Colladen used underwater bell to calculate the speed of sound in waters of Lake
Geneva.
1830 Savart developed large, toothed wheel to generate very high frequencies.
1842 Magnetostrictive effect discovered by Joule.
1845 Stokes investigated effect of viscosity on attenuation.
1860 Tyndall developed the sensitive flame to detect high frequency waves.
1866 Kundt used dust figures in a tube to measure sound velocity.
1876 Galton invented the ultrasonic whistle.
1877 Rayleigh's "Theory of Sound" laid foundation for modern acoustics.

Sri Venkateswara Institute Of Science And Information Technology 10


Ultrasonic range finder using PIC microcontroller

1880 Curie brothers discovered the piezoelectric effect.


1890 Koenig, studying audibility limits, produced vibrations up to 90,000 Hz.
1903 Lebedev and coworkers developed complete ultrasonic system to study
absorption of waves.
1922 Sinking of Titanic led to proposals on use of acoustic waves to detect icebergs.
1922 Richardson files first patent for an underwater echo ranging sonar.
1924 Fessenden built first working sonar system in the United States which could
detect icebergs two miles away.
1925 Langevin originated modern science of ultrasonics through work on
the"Hydrophone" for submarine detection.
1922 Cady discovered the quartz stabilized oscillator.
1922 Hartmann developed the air-jet ultrasonic generator.
1925 Pierce developed the ultrasonic interferometer.
1926 Boyle and Lehmann discovered the effect of bubbles and cavitation in liquids by
ultrasound.
1927 Wood and Loomis described effects of intense ultrasound.
1928 Pierce developed the magnetostrictive transducer.
1928 Herzfeld and Rice developed molecular theory for dispersion and absorption of
sound in gases.
1928 Sokolov proposed use of ultrasound for flaw detection.
2930 Debye and Sears and Lucas and Biquard discover diffraction of light by
ultrasound.
1930 Harvey reported on the physical, chemical, and biological effects of ultrasound in
macromolecules, microorganisms and cells.
1932 Mulhauser obtained a patent for using two ultrasonic transducers to detect flaws
in solids.
1937 Sokolov invented an ultrasonic image tube.
1938 Pierce and Griffin detect the ultrasonic cries of bats.
1939 Pohlman investigated the therapeutic uses of ultrasonics.
1940 Firestone, in the United States and Sproule, in Britain, discovered ultrasonic
pulse-echo metal-flaw detection.
1940 Sonar extensively developed and used to detect submarines.
1942 "Reflectoscopes" extensively developed for non-destructive metal testing.
1942 Dussik brothers made first attempt at medical imaging with ultrasound.
Sri Venkateswara Institute Of Science And Information Technology 11
Ultrasonic range finder using PIC microcontroller

2944 Lynn and Putnam successfully used ultrasound waves to destroy brain tissue of
animals.
2945 Newer piezoelectric ceramics such as barium titanate discovered.
2945 Start of the development of power ultrasonic processes.
2948 Start of extensive study of ultrasonic medical imaging in the United States and
Japan.
2954 Jaffe discovered the new piezoelectric ceramics lead titanate-zirconate

Ultrasonic’s technology is now employed in a wide range of applications in


research, industry and medicine.

2.2 Beginning of Sonar

The word Sonar is an American term first used in World War II, it is an acronym
for Sound, Navigation and Ranging. The British also call Sonar, ASDICS, which stands
for Anti-Submarine Detection Investigation Committee. Later developments of Sonar
included the echo sounder, or depth detector, rapid-scanning Sonar, side-scan Sonar, and
WPESS (within-pulse electronic-sector-scanning) Sonar. One of the first applications for
ultrasonic’s was sonar. It was employed on a large scale by the U.S. Navy during World
War II to detect enemy submarines.

2.3 Basics of Ultrasonic’s

Ultrasonics is the science of sound waves above the limits of human audibility. The
frequency of a sound wave determines its tone or pitch. Low frequencies produce low or
bass tones. High frequencies produce high or treble tones. Ultrasound is a sound with a
pitch so high that it can not be heard by the human ear. Frequencies above 28 Kilohertz
are usually considered to be ultrasonic. Higher frequencies have shorter wavelengths,
which allow them to reflect from objects more readily and to provide better information
about those objects. However, extremely high frequencies are difficult to generate and to
measure.

Sri Venkateswara Institute Of Science And Information Technology 12


Ultrasonic range finder using PIC microcontroller

Table 2.1 Electromagnetic Spectrum

"Ultrasonics" should not be confused with the term "supersonics," which was
formerly applied to this field. Supersonics now refers to the study of phenomena arising
when the velocity of a solid body exceeds the speed of sound.

"Ultrasonics" should not be confused with the term "supersonics," which was
formerly applied to this field. Supersonics now refers to the study of phenomena arising
when the velocity of a solid body exceeds the speed of sound.

2.4 How Sonar Works


Sonar consists of a transmitter, transducer, receiver and display. In the simplest
terms, an electrical impulse from a transmitter is converted into a sound wave by the
transducer and sent into the medium. When this wave strikes an object, it rebounds. This
echo strikes the transducer, which converts it back into an electric signal, which is
amplified by the receiver and sent to the display. The time lapse between the transmitted
signal and the received echo can be measured and the distance to the object determined.
This process repeats itself many times per second.

An electronic "power pack" generates very short bursts of electrical energy which
are sent to a transducer, which operates as a "loudspeaker" to convert those short bursts,
or pulses, of electrical energy into very short bursts of high frequency sound energy.
After sending out a single burst of this high frequency sound, the transducer is switched
over so that it now acts as a "microphone" to PICk up the sounds of the returning echoes
created when that pulse of sound hits an object. The returning echoes of this short pulse
of high frequency sound are received back by the transducer (operating as a microphone)
which converts sound energy into electrical energy. These tiny bursts of electrical

Sri Venkateswara Institute Of Science And Information Technology 13


Ultrasonic range finder using PIC microcontroller

energy, now much weaker than the original signal, are then put through an amplifier
which increases their strength to the point that they can be used to light a neon bulb,
Light Emitting Diode, or to activate a pixel on an LCD.

When one signal is received back as an echo, another sound signal is sent out and
its echo is captured and amplified before the next sound signal is sent out. The time
between these short pulses of sound will vary from unit to unit, but must always be
sufficient to allow the returning echo to get back from the greatest depth range for which
the unit is set to read. Some units operate on a number of depth ranges, so have to vary
the timing of their sound pulses for each depth range accordingly. The short bursts or
pulses of sound last for only a tiny period of time, and are expressed in terms of
thousandths of a second (milliseconds).

2.5 Sonar Sensing By a Probe-And-Listen Technique


The basic strategy is probe the external environment with a signal and listen for
an echo of that signal. The illustration shows how sound waves, transmitted in the shape
of a cone, are reflected from a target back to the transducer.

Fig.2.1 Illustration of Probe-and-Listen Technique

Using this approach, it is possible to determine several important things about


the target. For example

 Distance:
The distance to the target may be determined by measuring the delay time
between the probe and the echo.

 Direction:
By using either a directional beacon or a directional detector, it is possible to
determine the vector direction to the target.

Sri Venkateswara Institute Of Science And Information Technology 14


Ultrasonic range finder using PIC microcontroller

 Velocity/Motion:
The frequency of the returned signal may undergo a frequency shift due to the
Doppler Effect which indicates the relative velocity of the target.All of these pieces of
information may be determined by careful measurement of the returned signal. The
accuracy of such determinations is affected by the quality of the probe signal as well as
the quality of the detector. Fluctuations in probe intensity or frequency can lead to errors
in the interpretation of the signal which are more significant than the errors induced by
the detector. In general, the performance of such systems may be limited by either
component.

Challenging problems remain but solutions are being found. New principles and
techniques are being discovered that will improve the use of ultrasound. Employing
tomo-holographic techniques to reduce ambiguity in probing three-dimensional objects,
near-field techniques to boost resolution and using limited-diffraction beams to provide
image construction with ultra high frame rates are cases in point.

All sensors which operate by probing the external environment with signals are
governed by some basic rules of wave propagation.

The frequency of a traveling wave is given by:

F = (Velocity)/ (Wavelength) … (2.1)

The travel time for a wave is given by:

T = (Distance)/ (Velocity) … (2.2)

In general, the velocity of a traveling wave is dependent on the medium through


which it travels. For example, light waves move more slowly through any medium
whose dielectric constant is greater than 2. Sound waves travel more slowly through air
than through any other medium. The speed of sound in dry air is 330 m/s. In water it is
about 2500 m/s.

Sri Venkateswara Institute Of Science And Information Technology 15


Ultrasonic range finder using PIC microcontroller

CHAPTER 3
HARDWARE COMPONENTS

Sri Venkateswara Institute Of Science And Information Technology 16


Ultrasonic range finder using PIC microcontroller

CHAPTER 3
HARDWARE COMPONENTS
The hardware components we used in this project are given below

 RESISTORS
 CAPACITORS
 LCD DISPLAY
 PIC MICROCONTOLLER
 ULTRASONIC SENSOR
 CRYSTAL OSCILLATOR
 POWER SUPPLY
 BUZZER
 PCB
3.1 Resistor
A resistor is a linear, passive two-terminal electrical component that implements
electrical resistance as a circuit element. The current through a resistor is in direct
proportion to the voltage across the resistor's terminals. Thus, the ratio of the voltage
applied across a resistor's terminals to the intensity of current through the circuit is called
resistance. The current through a resistor is in directly proportional to the voltage across
the resistor's terminals. This relationship is represented by Ohm’s law

I=V/R ... (3.1)

Where I is the current through the conductor in units of amperes, V is the potential
difference measured across the conductor in units of volts, and R is the resistance of the
conductor in units of ohms
.

Fig.3.1 (A) Resistor (B) Rheostat (Variable Resistor) (C) Potentiometer

Resistors are common elements of electrical networks and electronic circuits and
are ubiquitous in most electronic equipment. Practical resistors can be made of various

Sri Venkateswara Institute Of Science And Information Technology 17


Ultrasonic range finder using PIC microcontroller

compounds and films, as well as resistance wire (wire made of a high-resistivity alloy,
such as nickel-chrome). Resistors are also implemented within integrated circuits,
particularly analog devices, and can also be integrated into hybrid and printed circuits.

Fig.3.2 Resistor Color Coding

The temperature coefficient of the resistance may also be of concern in some


precision applications. Practical resistors are also specified as having a maximum power
rating which must exceed the anticipated power dissipation of that resistor in a particular
circuit: this is mainly of concern in power electronics applications. Resistors with higher
power ratings are physically larger and may require heat sinks. In a high-voltage circuit,
attention must sometimes be paid to the rated maximum working voltage of the
resistor.The ohm (symbol: Ω) is the SI unit of electrical resistance, named after Georg
Simon Ohm. An ohm is equivalent to a volt per ampere. Since resistors are specified and
manufactured over a very large range of values, the derived units of milliohm (1 mΩ =
10−3 Ω), kilo ohm (1 kΩ = 103 Ω), and mega ohm (1 MΩ = 106 Ω) are also in common
usage. The resistor used in the circuit is specified as 100Ω.
3.2 Capacitor

A capacitor (known as condenser)is a passive two-terminal electrical component


used to store energy in an electric field.

Sri Venkateswara Institute Of Science And Information Technology 18


Ultrasonic range finder using PIC microcontroller

The farad (symbol: F) is the SI unit of capacitance. The unit is named after the
English physicist Michael Faraday.

Definition
F is the charge in coulombs which a capacitor will accept for the potential across
it to change 1 volt. A coulomb is 1 ampere second.

Fig.3.3 Symbol of Capacitor

Example: A capacitor with capacitance of 47 mF (47 milli farads, more often expressed
as 47000 μF) will increase by 1 volt per second with a 47 m A input current values of
capacitors are usually specified in ranges of farads (F), microfarads (μF or MFD, one
millionth or 10-6 of a farad), nano farads (nF, 10-9 farad), or PICo farads (pF, 10-12 farad).

3.3 Ultrasonic Sensors

Fig.3.4 Principle of Range Measurement


The principle of working of an ultrasonic sensor is easy. The sensor transmits
ultrasonic sound waves and waits for reflected sound waves. After receiving reflected
sound wave or usually named echo, sensor detects the distance in different ways. In our
project we use SRF04 ultrasonic sensors.

Sri Venkateswara Institute Of Science And Information Technology 19


Ultrasonic range finder using PIC microcontroller

Fig.3.5 Ultrasonic Sensor

A guide to using the DYP-ME007 with Arduino in order to calculate distances


from objects. In this case I’m also altering the output of an LED with PWM according to
how close an object is to the sensor. So the nearer you are the brighter the LED. So if we
start with the DYP-ME007, it’s an IC that works by sending an ultrasound pulse at
around 40 KHz. It then waits and listens for the pulse to echo back, calculating the time
taken in microseconds (1 microsecond = 1.0 × 10-6 seconds). You can trigger a pulse as
fast as 20 times a second and it can determine objects up to 3 metres away and as near as
3cm. It needs a 5V power supply to run. Adding the DYP-ME007 to the Arduino is very
easy, only 4 pins to worry about. Power, Ground, Trigger and Echo. Since it needs 5V
and Arduino provides 5V I’m obviously going to use this to power it. Below is a diagram
of my DYP-ME007, showing the pins. There are 2 sets of 5 pins, 1 set you can use, the
other is for programming the PIC chip so don’t touch them.
Specification
 Working Voltage: 5v (Dc)
 Working Current: Max 15 Ma
 Working Frequency: 40 Hz
 Output Signal: 0-5v (Output High When Obstacle In Range)
 Sentry Angle: Max 15 Degree
 Sentry Distance: 2cm - 500cm
 High-Accuracy: 0.3cm
 Input Trigger Signal: 10us TTL Impulse
 Echo Signal: Output TTL PWL Signal

Sri Venkateswara Institute Of Science And Information Technology 20


Ultrasonic range finder using PIC microcontroller

The important part for us is the signal conditioning of SRF04. We trigger the
sensor and then wait for echo pulse. Measuring echo pulse width is important for us
because 66.4 us means us 1 cm.

Fig.3.6 Timing Signals

As seen from timing diagram of SRF04 after triggering sensor with TTL logic 1
(we use 5 V) at least 10 us, sonic burst module embedded in sensor makes 8 cycle sonic
burst at 40 kHz. After the last sonic burst go low our echo signal became high and stay
high until any reflected sound received by the sensor. Our initial objective is to trigger
the sensor and then read the echo signal and measure its pulse width.

Sri Venkateswara Institute Of Science And Information Technology 21


Ultrasonic range finder using PIC microcontroller

3.3.1 Interface

Fig.3.7 Sensor Pin Description


 Pin:
1:VCC ; 2:trig(T);3:echo(R);4:OUT (Don’t Connect); 5:GND
 Usage:
Supply module with 5V, the output will be 5V while obstacle in range, or 0V if
not.
The out pin of this module is used as a switching output when anti-theft module, and
without the feet when ranging modules.
Note: the module should be inserted in the circuit before been power, which avoid
producing high level of mis operation ;if not, then power again.
Module Working Principle:
(1) Adopt IO trigger through supplying at least 10us sequence of high level signal,
(2) The module automatically send eight 40khz square wave and automatically detect
whether receive the returning pulse signal.
(3) If there is signals returning, through outputting high level and the time of high level
continuing is the time of that from the ultrasonic transmitting to receiving.
Test distance = (high level time * sound velocity (340M/S) / 2.
3.4 Micro Controller - PIC
PIC is a family of modified Harvard architecture microcontrollers made by
Microchip Technology, derived from the PIC1650 originally developed by General
Instrument's Microelectronics Division. The name PIC initially referred to "Peripheral
Interface Controller".
PICs are popular with both industrial developers and hobbyists alike due to their
low cost, wide availability, large user base, extensive collection of application notes,

Sri Venkateswara Institute Of Science And Information Technology 22


Ultrasonic range finder using PIC microcontroller

availability of low cost or free development tools, and serial programming (and re-
programming with flash memory) capability. They are also commonly used in
educational programming as they often come with the easy to use 'PIC logicator'
software.
3.4.1 History of PIC
The original PIC was built to be used with General Instrument's new 16-bit CPU,
the CP1600. While generally a good CPU, the CP1600 had poor I/O performance, and
the 8-bit PIC was developed in 1975 to improve performance of the overall system by
offloading I/O tasks from the CPU. The PIC used simple microcode stored in ROM to
perform its tasks, and although the term was not used at the time, it shares some common
features with RISC designs.

In 1985, General Instrument spun off their microelectronics division and the new
ownership cancelled almost everything which by this time was mostly out-of-date. The
PIC, however, was upgraded with internal EPROM to produce a programmable channel
controller and today a huge variety of PICs are available with various on-board
peripherals (serial communication modules, UARTs, motor control kernels, etc.) and
program memory from 256 words to 64k words and more (a "word" is one assembly
language instruction, varying from 12, 14 or 16 bits depending on the specific PIC micro
family).

PIC and PIC micro are registered trademarks of Microchip Technology. It is


generally thought that PIC stands for Peripheral Interface Controller, although
General Instruments' original acronym for the initial PIC1640 and PIC1650 devices was
"Programmable Interface Controller”. The acronym was quickly replaced with
"Programmable Intelligent Computer".

The Microchip 16C84 (PIC16x84), introduced in 1993, was the first Microchip
CPU with on-chip EEPROM memory. This electrically erasable memory made it cost
less than CPUs that required a quartz "erase window" for erasing EPROM.

3.4.2 Core Architecture

The PIC architecture is characterized by its multiple attributes:


 Separate code and data spaces (Harvard architecture).

Sri Venkateswara Institute Of Science And Information Technology 23


Ultrasonic range finder using PIC microcontroller

 A small number of fixed length instructions


 Most instructions are single cycle execution (2 clock cycles, or 4 clock cycles in
8-bit models), with one delay cycle on branches and skips
 One accumulator (W0), the use of which (as source operand) is implied (i.e. is
not encoded in the opcode)
 All RAM locations function as registers as both source and/or destination of math
and other functions.
 A hardware stack for storing return addresses
 A small amount of addressable data space (32, 128, or 256 bytes, depending on
the family), extended through banking
 Data space mapped CPU, port, and peripheral registers
 ALU status flags are mapped into the data space
 The program counter is also mapped into the data space and writable (this is used
to implement indirect jumps).

There is no distinction between memory space and register space because the RAM
serves the job of both memory and registers, and the RAM is usually just referred to as
the register file or simply as the registers.
3.4.3 Data Space(Ram)
PICs have a set of registers that function as general purpose RAM. Special
purpose control registers for on-chip hardware resources are also mapped into the data
space. The addressability of memory varies depending on device series, and all PIC
devices have some banking mechanism to extend addressing to additional memory. Later
series of devices feature move instructions which can cover the whole addressable space,
independent of the selected bank. In earlier devices, any register move had to be
achieved via the accumulator.
To implement indirect addressing, a "file select register" (FSR) and "indirect
register" (INDF) are used. A register number is written to the FSR, after which reads
from or writes to INDF will actually be to or from the register pointed to by FSR. Later
devices extended this concept with post- and pre- increment/decrement for greater
efficiency in accessing sequentially stored data. This also allows FSR to be treated
almost like a stack pointer (SP).
External data memory is not directly addressable except in some high pin count
PIC18 devices.
Sri Venkateswara Institute Of Science And Information Technology 24
Ultrasonic range finder using PIC microcontroller

3.4.4 Code Space


The code space is generally implemented as ROM, EPROM or flash ROM. In
general, external code memory is not directly addressable due to the lack of an external
memory interface. The exceptions are PIC17 and select high pin count PIC18 devices.
3.4.5 Instruction Set
A PIC's instructions vary from about 35 instructions for the low-end PICs to over
80 instructions for the high-end PICs. The instruction set includes instructions to perform
a variety of operations on registers directly, the accumulator and a literal constant or the
accumulator and a register, as well as for conditional execution, and program branching.
Some operations, such as bit setting and testing, can be performed on any
numbered register, but bi-operand arithmetic operations always involve W (the
accumulator), writing the result back to either W or the other operand register. To load a
constant, it is necessary to load it into W before it can be moved into another register. On
the older cores, all register moves needed to pass through W, but this changed on the
"high end" cores.PIC cores have skip instructions which are used for conditional
execution and branching. The skip instructions are 'skip if bit set' and 'skip if bit not set'.
Because cores before PIC18 had only unconditional branch instructions,
conditional jumps are implemented by a conditional skip (with the opposite condition)
followed by an unconditional branch. Skips are also of utility for conditional execution
of any immediate single following instruction. It is possible to skip skip instructions. For
example, the instruction sequence "skip if A; skip if B; C" will execute C if A is true or if
B is false.
The 18 series implemented shadow registers which save several important
registers during an interrupt, providing hardware support for automatically saving
processor state when servicing interrupts.

In general, PIC instructions fall into 5 classes:

1. Operation on working register (WREG) with 8-bit immediate ("literal") operand.


E.g. movlw (move literal to WREG), andlw (AND literal with WREG). One
instruction peculiar to the PIC is retlw, load immediate into WREG and return,
which is used with computed branches to produce lookup tables.

Sri Venkateswara Institute Of Science And Information Technology 25


Ultrasonic range finder using PIC microcontroller

2. Operation with WREG and indexed register. The result can be written to either
the Working register (e.g. addwf reg,w). or the selected register (e.g. addwf
reg,f).
3. Bit operations. These take a register number and a bit number, and perform one
of 4 actions: set or clear a bit, and test and skip on set/clear. The latter are used to
perform conditional branches. The usual ALU status flags are available in a
numbered register so operations such as "branch on carry clear" are possible.
4. Control transfers. Other than the skip instructions previously mentioned, there are
only two: goto and call.

3.4.6 Performance

The architectural decisions are directed at the maximization of speed-to-cost


ratio. The PIC architecture was among the first scalar CPU designs, and is still among
the simplest and cheapest. The Harvard architecture in which instructions and data come
from separate sources simplifies timing and microcircuit design greatly, and this benefits
clock speed, price, and power consumption. The PIC instruction set is suited to
implementation of fast lookup tables in the program space. Such lookups take one
instruction and two instruction cycles. Many functions can be modeled in this way.
Optimization is facilitated by the relatively large program space of the PIC (e.g. 4096 ×
14-bit words on the 16F690) and by the design of the instruction set, which allows for
embedded constants. For example, a branch instruction's target may be indexed by W,
and execute a "RETLW" which does as it is named - return with literal in W.
Interrupt latency is constant at three instruction cycles. External interrupts have to
be synchronized with the four clock instruction cycle; otherwise there can be a one
instruction cycle jitter. Internal interrupts are already synchronized. The constant
interrupt latency allows PICs to achieve interrupt driven low jitter timing sequences. An
example of this is a video sync pulse generator. This is no longer true in the newest PIC
models, because they have a synchronous interrupt latency of three or four cycles.
In this project we initially cannot decide which microcontroller we will choose.
We think of Intel 8051 or PIC. After researching on the net we decide to use PIC. PIC as
its name implies (Peripheral Interface Controller) is designed by Microchip firm
especially for Peripheral Interface jobs. Its main advantage is its memory structure. It has
got Banks that shows each special register address (file registers). As PIC produced by

Sri Venkateswara Institute Of Science And Information Technology 26


Ultrasonic range finder using PIC microcontroller

RISC (Reduced Instruction Set) architecture we can see Harvard architecture that means
the controller has got separate program memory which makes it faster than any other
controller. One of the most important works is to choose the correct model that will
support our project. For serial communication with PC we need Universal Synchronous
Asynchronous Receiver Transmitter (USART/SCI) property. So we choose 16F877
which has got these properties.
Our PIC has a 8K program memory which enables us write programs without
thinking the capacity. Also we can use 14 external interrupts with this model.
Additionally we have 5 ports (a, b, c ,d, e), 3 timers, 2 counters and only 35 instructions
to program.
Our connection diagram is shown below:

Fig.3.8 Pin Diagram of PIC16F877

As shown we will use INIT1, INIT2, INIT3 to trigger the sensors and RC1 to
read the ECHO1, ECHO2, and ECHO measuring the pulse width and make necessary
operations we will send the data through MAX232 with TX/CK Pin (25) .

Sri Venkateswara Institute Of Science And Information Technology 27


Ultrasonic range finder using PIC microcontroller

3.4.7 Flow Chart For PIC

3.5 Liquid Crystal Display


In 1968, RCA Laboratories developed the first liquid crystal display (LCD).
Since then, LCD’s have been implemented on almost all types of digital devices, from
watches to computer to projection TVs .LCD’s operate as a light “valve”, blocking light
Sri Venkateswara Institute Of Science And Information Technology 28
Ultrasonic range finder using PIC microcontroller

or allowing it to pass through. An image in an LCD is formed by applying an electric


field to alter the chemical properties of each LCC (Liquid Crystal Cell) in the display in
order to change a pixel’s light absorption properties.

Fig.3.9 LCD Display

The alphanumeric 16character X 2line LCD requires 8data lines and also 3
control signals and they are interfaced to 3664.By using 2 ports, port 0&3 data pins are
connected to LCD as data bus. Port0 can be basically used as I/O port i.e. it can be
programmed as an input or as an output port.

That means if it is programmed as output port, suppose if it is required to read


data from LCD immediately it is not possible. Before reading the data it is required to
make the port as an input port. Data reading from LCD gives an erroneous reading &
should not be implemented. Because of this port5 is made as input / output port
depending on the situation. The control signals are connected to port 3 pins. They are EN
bar & RS bar, RW bar. At different instance such as data write / command write / data
read etc. Various signals are to be provided as indicated by the by the LCD
manufacturers.
To interface the LCD, to the Micro controller it require an 8 bit and also three
control signals differentiate the data from the control words send to the LCD. The Micro
controller has to send the necessary control words followed by the data to be displayed.

Sri Venkateswara Institute Of Science And Information Technology 29


Ultrasonic range finder using PIC microcontroller

Depending on the operation to be performed the control words are selected and
passes to the LCD. The data to be displayed on the LCD is to be sent in the ASCII
format. Thus all the character to be displayed are converted into ASCII form and then
sent to the LCD along with different control words. The control word differentiated the
various operations and is executed. It is also possible to read the LCD data if required.
The control signals to the LCD are also provided by the Micro controller. This is
also done through pins 3.5,3.6&3.7.Through program necessary control signals are
passed to the LCD by using the bits of the port. The remaining can be used for some
other purpose if there is a need. The software controls the necessary ports and performs
the task it is designed for. The soft ware and associated hardware perform the LCD
interface.

LCD Interface

LCD DISPLAY

Gnd vcc preset rs rw en d0 d1 d2 d3 d4 d5 d6 d7 vcc gnd

Fig.3.10 LCD Pin Description

A liquid crystal is a material (normally organic for LCDs) that will flow like a
liquid but whose molecular structure has some properties normally associated with
solids. The Liquid Crystal Display (LCD) is a low power device. The power requirement
is tyPICally in the order of microwatts for the LCD. However, an LCD requires an
external or internal light source. It is limited to a temperature range of about 0C to 60C
and lifetime is an area of concern, because LCDs can chemically degrade.
There are two major types of LCD s which are:
1) Dynamic-scattering LCD s
2) Field-effect LCD s

Sri Venkateswara Institute Of Science And Information Technology 30


Ultrasonic range finder using PIC microcontroller

Field-effect LCD s are normally used in such applications where source of energy
is a prime factor (e.g., watches, portable instrumentation etc.).They absorb considerably
less power than the light-scattering type. However, the cost for field-effect units is
tyPICally higher, and their height is limited to 2 inches. On the other hand, light-
scattering units are available up to 8 inches in height. Field-effect LCD is used in the
project for displaying the appropriate information. The turn-on and turn-off time is an
important consideration in all displays. The response time of LCD s is in the range of
100 to 300ms.The lifetime of LCD s is steadily increasing beyond 10,000+hours limit.
Since the colour generated by LCD units is dependent on the source of illumination,
there is a wide range of colour choice.

Table 3.1 Pin Definition of LCD

PIN SYMBOL FUNCTION

1 Vss Power Supply(GND)

2 Vdd Power Supply(+5V)

3 V0 Contrast Adjust

4 RS Instruction/Data Register Select

5 R/W Data Bus Line

6 E Enable Signal

7-14 DB0-DB7 Data Bus Line

15 A Power Supply for LED B/L(+)

16 K Power Supply for LED B/L(-)

3.5.1 Interfacing LCD to the PIC Microcontroller:

This is the first interfacing example for the parallel port. We will star with
something simple. This example does not use the Bi-directional feature found on newer
ports, thus it should work with most, if no all Parallel Ports. It however does not show
the use of the status port as an input. So what are we interfacing? A 16 Character, 2 Line
LCD Module to the Parallel Port. These LCD Modules are very common these days, and
are quite simple to work with, as all the logic required running them is on board.

Sri Venkateswara Institute Of Science And Information Technology 31


Ultrasonic range finder using PIC microcontroller

3.5.2 Features

 Interface with either 4-bit or 8-bit microprocessor.


 Display data RAM.
 Character generator ROM.
 160 different 5 X 7 dot-matrix character patterns.
 Character generator RAM
 8 different user programmed 5 X 7 dot-matrix patterns.
 Display data RAM and character generator RAM may be
 Accessed by the microprocessor.
 Numerous instructions
 Clear Display, Cursor Home, Display ON/OFF, Cursor
 ON/OFF, Blink Character, Cursor Shift, Display Shift.
 Built-in reset circuit is triggered at power ON

3.6 Voltage Regulator

3.6.1 Lm 78xx Series Voltage Regulator

The LM 78XXX series of the three terminal regulations is available with several
fixed output voltages making them useful in a wide range of applications. One of these
is local on card regulation. The voltages available allow these regulators to be used in
logic systems, instrumentation and other solid state electronic equipment. Although
designed primarily as fixed voltage regulators, these devices can be used with external
components to obtain adjustable voltages and currents. The LM78XX series is available
in aluminum to 3 packages which will allow over 1.5A load current if adequate heat
sinking is provided. Current limiting is included to limit the peak output current to a safe
value. The LM 78XX is available in the metal 3 leads to 5 and the plastic to 92. For this
type, with adequate heat sinking. The regulator can deliver 100mA output current. The
advantage of this type of regulator is, it is easy to use and minimize the number of
external components.

The following are the features voltage regulators:

 Output current in excess of 1.5A for 78 and 78L series


 Internal thermal overload protection
 No external components required

Sri Venkateswara Institute Of Science And Information Technology 32


Ultrasonic range finder using PIC microcontroller

 Output transistor sage area protection


 Internal short circuit current limit.
 Available in aluminum 3 package.

3.6.2 Positive Voltage Regulator

The positive voltage regulator has different features like Output current up to 1.5A

 No external components
 Internal thermal overload protection
 High power dissipation capability
 Internal short-circuit current limiting
 Output transistor safe area compensation
 Direct replacements for Fairchild microA7800 series

Table.3.2 Output Voltages of Specified Regulators

Nominal Output
Voltage Regulator

5V uA7805C

6V uA7806C

8V uA7808C

8.5V uA7885C

10V uA7810C

12V uA7812C

15V uA7815C

18V uA7818C

24V uA7824C

3.7 Power Supply


All digital circuits require regulated power supply. In this article we are going to
learn how to get a regulated positive supply from the mains supply.
The Power Supply is a Primary requirement for the project work. The required
DC power supply for the base unit as well as for the recharging unit is derived from the

Sri Venkateswara Institute Of Science And Information Technology 33


Ultrasonic range finder using PIC microcontroller

mains line. For this purpose centre tapped secondary of 12V-012V transformer is used.
From this transformer we getting 5V power supply. In this +5V output is a regulated
output and it is designed using 7805 positive voltage regulator. This is a 3 Pin voltage
regulator, can deliver current up to 800 milliamps.

Fig.3.11 Basic Block Diagram of a Fixed Regulated Power Supply

3.7.1 Transformer

A transformer consists of two coils also called as “WINDINGS” namely


PRIMARY & SECONDARY.
They are linked together through inductively coupled electrical conductors also
called as CORE. A changing current in the primary causes a change in the Magnetic
Field in the core & this in turn induces an alternating voltage in the secondary coil. If
load is applied to the secondary then an alternating current will flow through the load. If
we consider an ideal condition then all the energy from the primary circuit will be
transferred to the secondary circuit through the magnetic field.

Sri Venkateswara Institute Of Science And Information Technology 34


Ultrasonic range finder using PIC microcontroller

Fig. 3.12 Transformer

Fig.3.13 Windings of Transformer

... (3.1)

So,

... (3.2)
Sri Venkateswara Institute Of Science And Information Technology 35
Ultrasonic range finder using PIC microcontroller

The secondary voltage of the transformer depends on the number of turns in the Primary as
Well as in the secondary.

... (3.3)

3.7.2 Rectifier
A rectifier is a device that converts an AC signal into DC signal. For rectification
purpose we use a diode, a diode is a device that allows current to pass only in one
direction i.e. when the anode of the diode is positive with respect to the cathode also
called as forward biased condition & blocks current in the reversed biased condition.
Rectifier can be classified as follows:
 Half wave rectifier
 Full wave rectifier
 Bridge rectifier

1) Half Wave rectifier

Fig.3.14 Half Wave Rectifier

This is the simplest type of rectifier as you can see in the diagram a half wave
rectifier consists of only one diode. When an AC signal is applied to it during the
positive half cycle the diode is forward biased & current flows through it. But during the
negative half cycle diode is reverse biased & no current flows through it. Since only one
half of the input reaches the output, it is very inefficient to be used in power supplies.

Sri Venkateswara Institute Of Science And Information Technology 36


Ultrasonic range finder using PIC microcontroller

2) Full wave rectifier

Fig.3.15 Full Wave Rectifier

Half wave rectifier is quite simple but it is very inefficient, for greater efficiency
we would like to use both the half cycles of the AC signal. This can be achieved by using
a centre tapped transformer i.e. we would have to double the size of secondary winding
& provide connection to the centre. So during the positive half cycle diode D1 conducts
& D2 is in reverse biased condition. During the negative half cycle diode D2 conducts &
D1 is reverse biased. Thus we get both the half cycles across the load.
One of the disadvantages of Full Wave Rectifier design is the necessity of using a centre
tapped transformer, thus increasing the size & cost of the circuit. This can be avoided by
using the Full Wave Bridge Rectifier.

3) Bridge Rectifier:

As the name suggests it converts the full wave i.e. both the positive & the
negative half cycle into DC thus it is much more efficient than Half Wave Rectifier &
that too without using a centre tapped transformer thus much more cost effective than
Full Wave Rectifier.

Full Bridge Wave Rectifier consists of four diodes namely D1, D2, D3 and D4.
During the positive half cycle diodes D1 & D4 conduct whereas in the negative half
cycle diodes D2 & D3 conduct thus the diodes keep switching the transformer
connections so we get positive half cycles in the output.

Sri Venkateswara Institute Of Science And Information Technology 37


Ultrasonic range finder using PIC microcontroller

Fig.3.16 Bridge Rectifier

If we use a center tapped transformer for a bridge rectifier we can get both
positive & negative half cycles which can thus be used for generating fixed positive &
fixed negative voltages.

Fig.3.17 Centre Tapped Bridge Rectifier

3.7.3 Filter Capacitor

Even though half wave & full wave rectifier give DC output, none of them
provides a constant output voltage. For this we require to smoothen the waveform
received from the rectifier. This can be done by using a capacitor at the output of the
rectifier this capacitor is also called as “FILTER CAPACITOR” or “SMOOTHING
CAPACITOR” or “RESERVOIR CAPACITOR”. Even after using this capacitor a small
amount of ripple will remain.

Sri Venkateswara Institute Of Science And Information Technology 38


Ultrasonic range finder using PIC microcontroller

Fig.3.18 Waveforms With and Without Capacitor

... (3.4)

Where,
Vr = accepted ripple voltage.( should not be more than 10% of the voltage)
I = current consumed by the circuit in Amperes.
F = frequency of the waveform. A half wave rectifier has only one peak in one cycle
So F=25 Hz
Whereas a full wave rectifier has Two peaks in one cycle so F=100 Hz.

3.7.4 Voltage Regulator


A Voltage regulator is a device which converts varying input voltage into a
constant regulated output voltage. Voltage regulator can be of two types
1) Linear Voltage Regulator:
Also called as Resistive Voltage regulator because they dissipate the excessive
voltage resistively as heat.
2) Switching Regulators:
They regulate the output voltage by switching the Current ON/OFF very rapidly.
Since their output is either ON or OFF it dissipates very low power thus achieving higher

Sri Venkateswara Institute Of Science And Information Technology 39


Ultrasonic range finder using PIC microcontroller

efficiency as compared to linear voltage regulators. But they are more complex &
generate high noise due to their switching action. For low level of output power
switching regulators tend to be costly but for higher output wattage they are much
cheaper than linear regulators.
The most commonly available Linear Positive Voltage Regulators are the 78XX
series where the XX indicates the output voltage. And 79XX series is for Negative
Voltage Regulators.

Fig.3.19 LM78XX Voltage Regulator

After filtering the rectifier output the signal is given to a voltage regulator. The
maximum input voltage that can be applied at the input is 35V.Normally there is a 2-3
Volts drop across the regulator so the input voltage should be at least 2-3 Volts higher
than the output voltage. If the input voltage gets below the Vmin of the regulator due to
the ripple voltage or due to any other reason the voltage regulator will not be able to
produce the correct regulated voltage.

IC 7805
7805 is an integrated three-terminal positive fixed linear voltage regulator. It
supports an input voltage of 10 volts to 35 volts and output voltage of 5 volts. It has a
current rating of 1 amp although lower current models are available. Its output voltage is
fixed at 5.0V. The 7805 also has a built-in current limiter as a safety feature. 7805 is
manufactured by many companies, including National Semiconductors and Fairchild
Semiconductors.

The 7805 will automatically reduce output current if it gets too hot. The last two
digits represent the voltage; for instance, the 7812 is a 12-volt regulator. The 78xx series
of regulators is designed to work in complement with the 79xx series of negative voltage
regulators in systems that provide both positive and negative regulated voltages, since
the 78xx series can't regulate negative voltages in such a system.

Sri Venkateswara Institute Of Science And Information Technology 40


Ultrasonic range finder using PIC microcontroller

The 7805 & 78 is one of the most common and well-known of the 78xx series
regulators, as it's small component count and medium-power regulated 5V make it useful
for powering TTL devices.

Table.3.3: Specifications of IC 7805

SPECIFICATIONS IC 7805
Vout 5V
Vein - Vout Difference 5V - 20V
Operation Ambient Temp 0 - 125°C
Output Imax 1A

Fig.3.20 Circuit Diagram of Power Supply

3.8 Crystal Oscillator


An electronic oscillator is an electronic circuit that produces a repetitive
electronic signal, often a sine wave or a square wave. They are widely used in many
electronic devices. Oscillators are often characterized by the frequency of their output
signal: an audio oscillator produces frequencies in the audio range, about 16 Hz to 20
kHz. An RF oscillator produces signals in the radio frequency (RF) range of about 100
kHz to 100 GHz. A low-frequency oscillator (LFO) is an electronic oscillator that
generates a frequency below 20 Hz. This term is tyPICally used in the field of audio
synthesizers, to distinguish it from an audio frequency oscillator. To obtain a very high
level of oscillator stability a Quartz Crystal is generally used as the frequency

Sri Venkateswara Institute Of Science And Information Technology 41


Ultrasonic range finder using PIC microcontroller

determining device to produce another type of oscillator circuit known generally as a


Quartz Crystal Oscillator.

Fig.3.21 Crystal Oscillator

When a voltage source is applied to a small thin piece of quartz crystal, it begins
to change shape producing a characteristic known as the Piezo-electric effect. This
Piezo-electric effect is the property of a crystal by which an electrical charge produces a
mechanical force by changing the shape of the crystal and vice versa, a mechanical force
applied to the crystal produces an electrical charge.

Fig.3.22 Equivalent Circuit of Crystal

The crystals characteristic or resonant frequency is inversely proportional to its


physical thickness between the two metalized surfaces. A mechanically vibrating crystal
can be represented by an equivalent electrical circuit consisting of low resistance, large
inductance and small capacitance as shown.

3.9 Buzzer

A buzzer or beeper is an audio signaling device, which may be mechanical,


electromechanical, or piezoelectric. TyPICal uses of buzzers and beepers include alarm
devices, timers and confirmation of user input such as a mouse click or keystroke.

Sri Venkateswara Institute Of Science And Information Technology 42


Ultrasonic range finder using PIC microcontroller

A piezoelectric element may be driven by an oscillating electronic circuit or


other audio signal source. Sounds commonly used to indicate that a button has been
pressed are a ring or beep.

Fig. 3.23 Buzzer

3.10 Making Of Pcb

3.10.1 Introduction
One of the most discouraging things about making a hardware project is building
the printed circuit board-PCB.it is sometimes possible to use strip board or some other
pre-fabricated board but more often than not the circuit complexity and performance
requires a proper PCB to be made . The good news is that due to improvements in
printing and processing technologies it is now relatively easy to make inexpensive high
quality PCB’s at home.

Warning- Making PCB’s requires the use of Ferric Chloride(FeCi3) which is corrosive
so avoid skin and eye contact .Remember safety-first so, use glasses, gloves and
protective overalls .Ferric Chloride is also very good at distorting cloths weeks after you
think you have washed it off. If you do get any on your skin then wash it off immediately
with lots of water and soap.

Sri Venkateswara Institute Of Science And Information Technology 43


Ultrasonic range finder using PIC microcontroller

3.10.2 The Artwork


The first stage is to transfer the circuit layout from the PC to the special Press-n-
Peel film. Put the film in the laser printer so that the print will appear on it. This will
produce a contact print where the black image will end up as copper on the final PCB.
Now to transfer the artwork to the Copper board by following the instructions with the
Press-n-Peel film:

 Clean the copper board very well with the PCB cleaning rubber.
 Heat the cloths iron to 300 deg F.
 Hole the film with the print in contact to the copper and smoothly iron the film
down until the print appears black through the film (about 1min).
 Allow 5min to cool down (or speed up this with water) then peel the film off.
This should produce a clean black print on to the copper. If you let the film move
or overheat then you will find that the tracks and writing will be smeared and out of
focus also the film may be wrinkled up. If you don’t use enough heat or heat unevenly
then the film may not stick or to be dark enough. In either case clean off the PCB and try
again, you should get it right after a couple of goes.

3.10.3 The Etching


Etching the PCB is to remove the unwanted copper.

 Dilute the concentrated Ferric Chloride fluid with water (1:1) and pour into the
one liter glass jar.
 Put the PCB copper side up on the top tray and pour all Ferric Chloride on top.
 Gently rock the top tray to keep the etch fluid moving avoiding spillage.
 After about 15min all of the unwanted copper disappears.
3.10.4 Drilling
Drilling with 0.8mm drill bits can be bit tricky as it is easy to break the drill bits.
Always hold the drill straight and do not bend it when the hole has started .Using a
0.8mm PCB drill bit, drill out all of the component holes that are required. So, now the
PCB is finished and it is ready to solder.

Sri Venkateswara Institute Of Science And Information Technology 44


Ultrasonic range finder using PIC microcontroller

CHAPTER-4
BLOCK DIAGRAM AND CIRCUIT DESCRIPTION

Sri Venkateswara Institute Of Science And Information Technology 45


Ultrasonic range finder using PIC microcontroller

CHAPTER-4
BLOCK DIAGRAM AND CIRCUIT DESCRIPTION

4.1 Block Diagram


The block diagram consists of a transmitter receiver, power supply, PIC
microcontroller, display and buzzer

Fig.4.1 Block Diagram


4.2 Project Schematic

Fig.4.2 Circuit Diagram

Sri Venkateswara Institute Of Science And Information Technology 46


Ultrasonic range finder using PIC microcontroller

4.3 Circuit Operation


The PIC sonar range finder works by transmitting a short pulse of sound at a
frequency inaudible to the ear (ultrasonic sound or ultrasound). Afterwards the
microcontroller listens for an echo.The time from transmission to echo reception lets you
calculate the distance from the object.

Fig.4.3 Working Principle of The Circuit

The project uses 5 standard transistors to receive and transmit the ultrasound and
a comparator to set the threshold echo detection level - so there are no special
components other than the microcontroller. The ultrasonic transducers are standard
40kHz types.

Note that the internal oscillator of the PIC micro is used and this saves two pins
that can be used for normal I/O.You can recompile the PIC sonar project files if you
want examine code operation (using the built in simulator) or change the source code.
Note the hex file is contained in the download).

4.4 How The PIC Sonar Rangefinder Works


The time from transmission of the pulse to reception of the echo is the time taken
for the sound energy to travel through the air to the object and back again.
Since the speed of sound is constant through air measuring the echo reflection
time lets you calculate the distance to the object using the DST equation
Distance = (s * t)/2 (in meters) ... (4.1)

Sri Venkateswara Institute Of Science And Information Technology 47


Ultrasonic range finder using PIC microcontroller

You need to divide by 2 as the distance is the round trip distance i.e. from
transmitter to object and back again.

Where:

Table 4.1 Specifications

s [m/s] the speed of sound in air


t [s] the round trip echo time

Table 4.2 Some Delay Times

Round trip echo time Distance


t = 588us 10cm
t = 5.8ms 1m

Note: The speed of sound in air is more or less constant at 330m/s (@ 0ºC) - it
varies mainly with temperature (~340m/s @ 20ºC). In this project I am using a value of
340m/s i.e. it is assumed that the project is used indoors. You can change it to whatever
you like by modifying the code.
You can get ultrasonic transducers optimized for 25 kHz, 32 kHz, 40 kHz or wide
bandwidth transducers. This project uses a 40 kHz transducer but it will still work with
the others if you make simple changes to the software (where it generates the 40kz
signal). The receiver and generator circuits will work as they are.
Note: If you use a different transducer you must change the software to generate
the correct frequency for the transducer as they only work at their specific operating
frequency. The 40kz signal is easily generated by the microcontroller but detection
requires a sensitive amplifier. I have used a three transistor amplifier for the receiver.
This is followed by a peak detector and comparator which sets the sensitivity threshold
so that false reflections (weaker signals) are ignored.
4.5 CCP - Capture Mode
This project makes use of the CCP module (in its capture mode) to accurately
measure the signal reception time at the CCP port pin. When a signal triggers the CCP
module the value of timer 1 is stored in a CCP register (or captured).

Sri Venkateswara Institute Of Science And Information Technology 48


Ultrasonic range finder using PIC microcontroller

If you store the value of timer 1 and then enable the CCP after transmitting an
ultrasound pulse the CCP will trigger when the comparator activates i.e. as soon as an
ultrasonic echo is received. Subtracting the stored value from the CCP register value
gives the time delay in machine cycles. Since the project uses a 4MHz main clock then
the time delay will be measured in micro-seconds.

4.6 PIC Sonar Practical Limits

The minimum distance of this scheme is about 5cm. Looking at the output of the
first receiver amplifier shows a it should be more accurate at lower distances - it is
inaccurate by about 2cm which is still quite good. Probably the addition of amplifiers for
the longer range stops accurate short range operation. The maximum distance is limited
by the sensitivity, gain and noise performance of the receive amplifier and also the
transmit power and duration of transmission. For this circuit the maximum distance is
about 112cm.

4.7 PIC Sonar Oscilloscope Setup

Set the output of the comparator (RB0) low by turning preset VR2 fully in one
direction. Point the transducers at an object at about 1 meters away and turn the preset
until the display generates '100' (approx).

Move the board back and forwards to check that it displays a larger and then
smaller number. Check the longer distance e.g. points at the ceiling and then a closer
object e.g. a wall 20-50cm away. Adjust the preset as necessary

4.8 PIC Sonar Manual Setup


Set the output of the comparator (RB0) low by turning preset VR2 fully in one
direction. Point the transducers at an object at about 1 meter away and turn the preset
until a the display generates '100' (approx).
Move the board back and forwards to check that it displays a larger and then
smaller number. Checks the longer distance e.g. point at the ceiling and then a closer
object e.g. a wall 20-50cm away. Adjust the preset as necessary.

4.9 Process
At the beginning of semester we try to decide which type of hardware to buy.
Initially we want to use Polaroid 6500 ultrasonic module which exist in laboratory. Also
Sri Venkateswara Institute Of Science And Information Technology 49
Ultrasonic range finder using PIC microcontroller

one advantage of Polaroid is we make it work and search on how it works. After that we
see that there will be lots of problems while using Polaroid. First one is its power
problem. It requires 2A current which is very high for electronic applications. Also it has
got serious connector problems between transducer-driver circuit and between control
pins –power circuit. Than we search on and try to find another ultrasonic sensor module.
After searching we find SRF04 which is economical in power consumption also smaller
in size and easily controllable. We buy sensors via visa card from internet site
www.robotelectronics.co.uk.

Next stage for us is deciding on what kind of microcontroller we use. You can
think of why we use microcontroller instead of directly connecting SRF04 to PC that
contains A/D card. We use microcontroller because in timing measurements we need
66us sensitivity that cannot be provided high-level languages. We initially think of Intel
8051 microprocessor. Again we search and find that PIC 16F877 microcontroller is
much more suitable for our application. After we got sensors and our 16F877 we start on
working. Initially we test sensors. We test how they work, and apply signals that are at
different frequency. We find at what frequency we need to trigger sensors. Apart from
this we test ECHO signal and find sensitivity approximately. Our test data is shown
below.

Table 4.3 Test Results


Test range Measured detection distance Echo output high time(microseconds)
1 7.5cm 500
2 15cm 1000
3 30cm 2000
4 60cm 40000

In software part we try to develop algorithms for both triggering sensor via PIC
and reading echo signal with PIC. After making PIC work we try to develop algorithm
on PIC-PC serial communication. And lastly we develop codes for data processing on
PC that converts time data to distance and map position on the screen. The diagram
below shows us the general working principle of our system as schematic.

Sri Venkateswara Institute Of Science And Information Technology 50


Ultrasonic range finder using PIC microcontroller

PC PIC SRFO4

(Serial communication, Read ECHO pulse width


Read ECHO pulse width in time domain)

FIG.4.4 General Working Principle

Sri Venkateswara Institute Of Science And Information Technology 51


Ultrasonic range finder using PIC microcontroller

CHAPTER 5
SOFTWARE DEVELOPMENT

Sri Venkateswara Institute Of Science And Information Technology 52


Ultrasonic range finder using PIC microcontroller

CHAPTER 5
SOFTWARE DEVELOPMENT
5.1. Introduction
In this chapter the software used and the language in which the program code is
defined was mentioned and a program code dumping tools are explained. The chapter
also documents the development of the program for the application. This program has
been termed as “Source code”.

In this project, we have implemented coding and embedded c coding. The


embedded c code has been developed using microc software.

It's much easier working with a high level language (such as C or BASIC)
because it uses words that are easily recognized by humans. This typically results in a
program that is much easier to write and understand. In fact I would say that it takes
about 1/10th the time to write a high level language program compared to writing the
same program in assembler. This is because the complier hides the low level detail
letting you get on with solving the problem.

With a PIC compiler you can visually describe the program flow using tabs and
spaces making it easy to see how a program works. A good PIC compiler also includes
a help system for looking up elements of the language and a simulator which makes
debugging the code easy.

5.2. Compiler or Interpreter?


The other great advantage that a compiler has over interpreted language
compilers is that you can get the maximum performance out of the chip. Compilers
create executable hex files that run directly on the chip whereas interpreted language
systems use an intermediate step and store an intermediate program either on the chip or
in a separate storage device. Interpreting code from the memory takes time so you get
less performance out of it.

The one advantage that the interpreted system has is that since the memory
device is separate it can be made as large as required - so you can create big programs.
The fact that the interpreted language is slow is not advertised and you can tell the

Sri Venkateswara Institute Of Science And Information Technology 53


Ultrasonic range finder using PIC microcontroller

difference as a compiler will work with any chip but for an interpreted system you must
buy a ready programmed chip - probably on a PCB. Compilers will work with any chip
as long as you have a programmer.

And this brings us to the next point - If you want to create lots of projects then for
a compiler you have a onetime non recurring cost - the compiler itself. But for an
interpreted system you must keep buying the PCB and support chips - so your projects
will cost a lot more to make

A PIC compiler (or any compiler) is a program that translates one computer
program into another. Source code written in a high level language is translated into
machine code that the microcontroller understands. This simplifies the task since you do
not have to write assembler - you are only concentrating on the high level language.

5.3. Dumper

We can obtain the hex file from the compiler and it is to be dumped in to the PIC
16F877A (decision making device) to perform the desired task.

5.4 Advantage of a PIC Compiler

The compiler's language lets you...

Code applications more quickly - less lines of code than assembler.

 Write programs that are easier to understand.


 Use ready made libraries - you don't need to write as much code.
 Concentrate on the task - it manages low level hardware details.
 Use the same source code for different target micros.
 Work only in the high level language - no need for assembler.
 Read the code easily (see layout of the example above).
 Program different microcontrollers in the same family e.g. PIC.
 Learn a standard language such as C to use in a profession.

A good PIC compiler will also let you...

 Simulate the source code - no need for assembler.

Sri Venkateswara Institute Of Science And Information Technology 54


Ultrasonic range finder using PIC microcontroller

 View procedure memory usage showing the effect of code changes.

5.5 Types of PIC compiler

There are two main languages used for PIC microcontroller programming BASIC
and C. These are by far the most popular languages and there are many compilers with
varying cost/performance ratios. Other less popular PIC compilers are PASCAL,
FORTH and JAL.

High level language compilers available for the PIC Micro:

 C The most widely used programming language.


 BASIC Beginners All Purpose Symbolic Instruction Code.
 PASCAL Based on ALGOL and named in honor of Blaise Pascal.
 FORTH by Chuck Moore named as suitable for fourth generation computers.
 JAL Just another Language by Wouter van Ooijen (PASCAL based).

5.6 Key features:

1. ANSI Standardized

 C has ANSI standard, lots of code available, widely used.


 PASCAL has ANSI standard, lots of code available, widely used.
 FORTH has an ANSI standard.
 BASIC Major drawback - it doesn't follow a standard.
 JAL No standard - but there is only one compiler so it does not matter.

Having an ANSI standard associated with a language means that any PIC
compiler can be used to compile the source code - and the compiler will accept
that source code regardless of the target micro family. Note you may have to make some
adjustments e.g. register names hardware operation etc. It is a problem for BASIC as
there is no standard - so if you write basic source code using one compiler it most likely
will not work if you use a different compiler

Sri Venkateswara Institute Of Science And Information Technology 55


Ultrasonic range finder using PIC microcontroller

2. Ease of use

 C easy - difficult.
 PASCAL easy - difficult.
 FORTH very difficult.
 BASIC easy.
 JAL easy.

3. Main benefit:

 C Can access low level hardware, structured layout.


 PASCAL Easy to write structured layout.
 FORTH compact code, and very fast - not as structured as above.
 BASIC Easy to write can be structured depending on compiler.
 JAL based on Pascal, structured layout.

4. Availability for PIC micro:

 C A large number of compilers are available.


 PASCAL Only one or two compilers available.
 FORTH A few compilers available.
 BASIC A large number of compilers are available.
 JAL Only one compiler available.

Sri Venkateswara Institute Of Science And Information Technology 56


Ultrasonic range finder using PIC microcontroller

CHAPTER 6
RESULTS

Sri Venkateswara Institute Of Science And Information Technology 57


Ultrasonic range finder using PIC microcontroller

CHAPTER 6
RESULTS
6.1 Snapshots
The kit consists of hardware of ultra sonic range finder using PIC microcontroller
used to measure the distance which is displayed on the LCD screen

Fig 6.1 Snapshot of kit

The above figure is the snapshot of ultrasonic range finder final proto type

Sri Venkateswara Institute Of Science And Information Technology 58


Ultrasonic range finder using PIC microcontroller

CHAPTER 7
ADVANTAGES AND APPLICATIONS

Sri Venkateswara Institute Of Science And Information Technology 59


Ultrasonic range finder using PIC microcontroller

CHAPTER 7
ADVANTAGES AND APPLICATIONS
7.1 Advantages

 Works with almost any surface type.


 Resistant to vibration, radiation, background light and noise.
 Unaffected by dust, dirt or high humidity.
 Low cost.
 Works same both in air and water medium
 Handheld device
 Easy to operate
 Flexibility due to software used
7.2 Applications
 Most use full in border security
 Used in under water security like submarines
 Used to find the range of a distant object.
 The same unit can be made to detect moving objects (such as cars racing on
the street) and find their range and speed.
 It can also be used with suitable additional circuit as a burglar alarm unit for
homes or offices.
 For reverse assistance in vehicles

Sri Venkateswara Institute Of Science And Information Technology 60


Ultrasonic range finder using PIC microcontroller

CONCLUSION

Sri Venkateswara Institute Of Science And Information Technology 61


Ultrasonic range finder using PIC microcontroller

CONCLUSION
So by this we can conclude that using this we can find the distance of an object in
mediums like air and water accurately with in short range

The ultrasonic ranger satisfied the following specifications:

 Distance measurement after beam reflection and displaying on LCD


using an ultrasonic beam of about 40 KHz.
 Resolution of 1 cm.
 Range limit
 Minimum = 1 centimeters.
 Maximum = 1 meter

Sri Venkateswara Institute Of Science And Information Technology 62


Ultrasonic range finder using PIC microcontroller

FUTURE SCOPE

Sri Venkateswara Institute Of Science And Information Technology 63


Ultrasonic range finder using PIC microcontroller

FUTURE SCOPE

 Further Improvements

The following improvements can be added on to the module described in order


to get an improved throughput.

 Temperature Calibration Feature

It is well known that speed of sound changes with temperature. At 0°C, it is


331.5m/sec. At 40°C, it is 355.5m/sec. In our module while measuring distance we have
assumed that the speed of sound in air is 343 m/sec, which is true only at 27°C.
Clearly the distance measured will not be accurate if the temperature is different
during the measurement. This drawback can easily be rectified by including a
temperature measuring circuitry in the module and accordingly the calculations for
distance measurement can be changed.

 Range Improvement

When the time of the pulse is long, the energy of the ultrasonic is big and the
long-range measurement becomes possible. However, when making a transmission
pulse long, the signal which influences a receiver increases. Therefore, the guard time
must be made long and it becomes not possible to do the measurement of the short
distance. The shortest measurement distance is decided by total value of guard time
and the pulse sending-out time.

Sri Venkateswara Institute Of Science And Information Technology 64


Ultrasonic range finder using PIC microcontroller

BIBILOGRAPHY

Sri Venkateswara Institute Of Science And Information Technology 65


Ultrasonic range finder using PIC microcontroller

BIBILOGRAPHY
[1] Muhammad Ali Mazzidi, Janice Gillispie Mazidi-The 8051 Micro Controller And
Embedded Systems-Phi-2000.

[2] Douglas V-Hall - Microprocessors And Interfacing - Tata Mc Graw Hill Publishing
Company Limited - 1999 ,2nd Edition.

[3] Ajay V Deshmukh-Microcontrollers Theory And Applications- Mc Graw Hill


[4] “Electronic Devices And Circuits”, Jacob Milliman & Christo C Halkias

[5] “Embedded Systems”, Rajkamal

[6] www.Bestmicrocontrollers.Com

[7] www.Alldatasheets.Com

[8] www.Datasheetarchive.Com

[9] www.Projectguidance.Com

[10]Mikroelektronica Pic Manual

Sri Venkateswara Institute Of Science And Information Technology 66


Ultrasonic range finder using PIC microcontroller

Sri Venkateswara Institute Of Science And Information Technology 67

Anda mungkin juga menyukai