Professional Documents
Culture Documents
A PROJECT REPORT
Submitted by
NISHIT CHITTORA
of
BACHELOR OF ENGINEERING
in
MAY 2011
GEETANJALI INSTITUTE OF TECHNICAL STUDIES,
DABOK, UDAIPUR, RAJASTHAN, INDIA
(Affiliated to Rajasthan Technical University, Kota, Rajasthan)
CERTIFICATE
is the bonafide work of “NISHIT CHITTORA” who carried out the project
SIGNATURE SIGNATURE
The report details the implementation of distance measurement system using the
kHz, it is insensitive to ultrasonic waves, and hence the ultrasound waves can be
They are widely used as range meters and proximity detectors in industries also
it can be used in parking assistance system. The distance can be measured using
pulse echo and phase measurement method. Here the pulse echo methods used.
the signal is detected. The time delay of the transmitted and the received signal
ABSTRACT iii
LIST OF FIGURES vi
1. INTRODUCTION 1
1.1 OBJECTIVE
RANGE FINDER
2 CIRCUIT DESCRIPTION 8
3 SOFTWARE 14
4.1 APPLICATION 24
APPENDICES 25
APPENDIX-A 25
APPENDIX-B 27
APPENDIX-C 28
APPENDIX-D 31
APPENDIX-E 36
REFERENCES 49
LIST OF FIGURES
1.1 OBJECTIVE
The object of this work is to replace the old traditional range detector, used in
several applications. In present work the object position is measured
electronically by using seven segment displays by replacing the heavy and
bulky circuits with the compact circuits using intelligent Microcontroller. The
bulky pressing switch is replaced by the small and one touch tactile switch. It
saves electric consumption, saves the no. of man power, through seven segment
display and one microcontroller as well as ultrasonic receiver & transmitter
sensors.
1.2 ULTRASONIC RANGE FINDER
There are several ways to measure distance without contact. One way is to use
ultrasonic waves at 40 kHz for distance measurement. Ultrasonic transducers
measure the amount of time taken for a pulse of sound to travel to a particular
surface and return as the reflected echo. This circuit calculates the distance
based on the speed of sound at 25°C ambient temperature and shows it on a 7-
segment display. Using it, you can measure distance up to 2.5 meters. For this
particular application, the required components are AT89C2051
microcontroller, two 40kHz ultrasonic transducers (one each for transmitter
and receiver), current buffer ULN2003, operational amplifier iM324I inverter
Ca4M4VI four T-segment displays I five transistors and some discreet
components. The ultrasonic transmitter- receiver pair is shown in Ultrasonic
generators use piezoelectric materials such as zinc or lead zirconium tartrates or
quartz crystal. The material thickness decides the resonant frequency when
mounted and excited by electrodes attached on either side of it. The medical
scanners used for abdomen or heart ultrasound are designed at 2.R Mez. fn this
circuit, a 40kHz transducer is used for measurement in the air medium. The
velocity of sound in the air is around 330 m/s at 0°C and varies with
temperature.
In this project, you excite the ultrasonic transmitter unit with a 40kHz pulse
burst and expect an echo from the object whose distance you want to
measure. Fig. 2 shows the transmitted burst, which lasts for a period of
approximately 0.5 ms. It travels to the object in the air and the echo
signal is picked up by another ultrasonic transducer unit (receiver), also a 40
kHz pre-tuned unit. The received signal, which is very weak is amplified several
times in the receiver circuit and appears somewhat as shown in Fig. 2 when
seen on a CRO. Weak echoes also occur due to the signals being directly
received through the side lobes. These are ignored as the real echo received
alone would give the correct distance. That is why we should have a level
control. Of course, the signal gets weaker if the target is farther than 2.5 and
will need a higher pulse excitation voltage or a better transducer. Here the
microcontroller is used to generate 40 kHz sound pulses. It reads when the echo
arrives; it finds the time taken in microseconds for to-and-fro travel of sound
waves. Using velocity of 333 m/s, it does the calculations and shows on the four
7-segment displays the distance in centimeters and millimeters (three digits for
centimeters and one for millimeters).
1.3 BLOCK DIAGRAM OF ULTRASONIC RANGE FINDER
The Ping sensor detects objects by emitting a short ultrasonic burst and then
"listening" for the echo. Under control of a host microcontroller (trigger pulse),
the sensor emits a short 40 kHz (ultrasonic) burst. This burst travels through the
air at about 1130 feet per second, hits an object and then bounces back to the
sensor. The PING sensor provides an output pulse to the host that will terminate
when the echo is detected, hence the width of this pulse corresponds to the
distance to the target.
Sound waves with frequency range from 20 Hz to 20 KHz are responsive to the
human ear. Vibrations above this frequency are termed as ultrasonic. Ultrasonic
signals are affected by the properties of the medium. Thus while passing
through a particular medium these signals get attenuated. The attenuation of
ultrasonic signal is taken as the means for the measurement of distance of the
target and for different other applications Ultrasonic distance sensors are used to
detect the presence of flaw by measuring the distance. They do so by evaluating
the echo of a transmitted pulse with concern to its travel time. Time dependent
control of sensitivity is used to compensate the distance dependency of the echo
amplitude, while different reflection properties are compensated by an
automatic gain control, which holds the average echo amplitude constant. Echo
amplitude therefore has very little influence on the accuracy of the distance
measurement provided the signal to noise ratio is not very low. By considering
whether the echo has been received within a time window, i.e. a time interval,
which can be preset by the user, the distance range is given in which the sensor
responds to the presence of an object. Using this technique, interference can be
suppressed and relevant objects are monitored more reliably.
Ultrasonic sonar sensors actively transmit acoustic waves and receive them
later. This is done by ultrasonic transducers, which transform an electrical
signal into an ultrasonic wave and vice versa. The ultrasound signal carries the
information about the variables to be measured. The task for the ultrasonic
sensors is not merely to detect ultrasound, as intelligent sensors they have to
extract the information carried by the ultrasonic signals efficiently and with
high accuracy. To achieve this performance, the signals are processed,
demodulated and evaluated by dedicated hardware. Algorithms based on models
for the ultrasonic signal propagation and the interaction between the physical or
chemical variables of interest are employed (munich,1994).
Furthermore, techniques of a sensor specific signal evaluation are being applied.
Ultrasonic sensors can be embedded into a control system that accesses
additional sensors, combines information of the different sensors, handles the
bus protocols and initiates actions.
2.
3. CIRCUIT DESCRIPTION
Figure 4 shows the circuit of the microcontroller based distance meter. The
40kHz pulse bursts from the microcontroller are amplified by transistor T5.
Inverting buffer CD4049 drives the ultrasonic sensor used as the transmitter.
Three inverters (N1, N2 and N3) are connected in parallel to increase the
transmitted power. This inverted output is fed to another set of three inverters
(N4, N5 and N6). Outputs of both sets of parallel inverters are applied as a push
pull drive to the ultrasonic transmitter.
The positive going pulse is applied to one of the terminals of the ultrasonic
sensor and the same pulse after 180-degree phase shift is applied to another
terminal. Thus the transmitter power is increased for increasing the range. If you
want to increase the range up to 5 meters, use a ferrite-core step-up pulse
transformer, which steps-up the transmitter output to 60V (peak-to- peak). The
echo signal received by the receiver sensor after reflection is very weak. It is
amplified by quad operational amplifier LM324. The first stage (A1) is a buffer
with unity gain. The received signal is directly fed to the non-inverting input
(pin 3) of A1 and coupled to the second stage by a 3.3nF (small-value)
capacitor. If you use the ubiquitous 0.01μF capacitor for coupling, there will be
2-mega-ohm resistor for feedback. The third stage is a precision rectifier
amplifier with a gain of 10. The rectifier functions, unlike a simple diode, even
for signal voltage of less than 0.6V. The output is filtered to accept 40 kHz
frequencies and fed to pin 12 of microcontroller AT89C2051, which is an
analogue comparator. Pin 13 is the other pin of the
Figure 4: Circuit Diagram of Ultrasonic Range Finder
Comparator used for level adjustment using preset VR1. The ultrasonic
transducer outputs a beam of sound waves, which has more energy on the main
lobe and less energy (60 dB below the main lobe) on the side lobes as shown in
Fig. 4. Even this low side-lobe signal is directly picked up by the receiver unit.
So you have to space the transmitter and receiver units about 5 cm apart. The
two units are fixed by cello tape on to a cardboard, with the analogue circuit at
one end. Microcontroller AT89C2051 is at the heart of the circuit. Port-1 pins
P1.7 through P1.2, and port-3 pin P3.7 are connected to input pins through 1 to
7of IC2 (IC ULN2003), respectively. These pins are pulled up with a 10-kilo-
ohm resistor network RNW1. They drive all the segments of the 7-segment
display with the help of inverting buffer IC2. Port-3 pins P3.0 through P3.3 of
the microcontroller are connected to the base of transistors T1 through T4 to
provide the supply to displays DIS1 through DIS4, respectively. Pin P3.0 of
microcontroller IC1 goes low to drive transistor T1 into saturation, which
provides supply to the common- anode pin (either pin 3 or 8) of display DIS1.
Similarly, transistors T2 through T4 provide anode currents to the other three 7-
segment displays. Microcontroller IC1 provides the segment data and display-
enable signal simultaneously in time-division multiplexed mode for displaying a
particular number on the 7-segment display unit. Segment data and display-
enable pulse for the display are refreshed every 5 ms. Thus the display appears
to be continuous, even though the individual LEDs used in it light up one by
one. Using switch S1 you can manually reset the microcontroller, while the
power on reset signal for the microcontroller is derived from the combination of
capacitor C4 and resistor R8. A 12MHz crystal is used to generate the basic
clock frequency for the microcontroller. Resistor R16 connected to pin 5 of
DIS2 enables the decimal point. The comparator is inbuilt in microcontroller
AT89C2051. The echo signal will make port-3 pin 3.6 low when it goes above
the level of voltage set on pin 13. This status is sensed by the microcontroller as
programmed. When port-3 pin P3.6 goes high, we know that the echo signal has
arrived; the timer is read and the 16-bit number is divided by twice the velocity
of sound and then converted into decimal format as a 4-digit number.
3. SOFTWARE
The software is written in Assembly language and assembled using 8051 cross-
assembler. It is well commented and easy to understand. The pulse train for 0.5
ms is started by making pin 8 high and low alternately for 12.5 microseconds so
that the pulse frequency is 40 kHz. After 25 such pulses have passed, a waiting
time is given to avoid direct echoes for about 20 μs. Then the signal is awaited,
while the timer runs counting time in microseconds. When the echo arrives,
port-3 pin P3.6 goes high, the timer reads and the 16-bit number is divided by
twice the velocity and converted into decimal format as a 4-digit number. If the
echo does not arrive even after 48 milliseconds, the waiting loop is broken and
the pulse train sequence is started once again. If the echo comes within this
time, it is displayed for half a second before proceeding to another
measurement. Thus, the display appears continuous and flicker-free.
/*timer low reg. is also so; total cycle time is 64.6ms ,350m/s gives
0.35mx65=22.5m b; up and down 10 meters say! .35 m/ms,.35 mm/us, 1mm
per 3 micros ; up and down .35/2 mm/us = 1/6 mm/us ; velocity of sound in
air is 350 m/s ; after 100 times, we have to stop transmitting for a time of
about .1 s ; so we stop for this amount of time and expect an echo.*/
/*check_echo:*/
jnb p3.6, //check timeout
MOV 40h,TL0 ; //read timer count
MOV 41h,TH0
mov r0,40h
mov r1,41h
mov r3,#0
mov r2,#6
call UDIV16 ; //divide by 6
mov 40h,r0
mov 41h,r1
mov 50h,#25
disp: call disp1 ; //show the value on LED
djnz 50h,disp ; //so many times for a visible time limit
jmp beg
checktimeout: mov a,th0
cjne a,#0c0h,check_echo ; //upto 4 metres
jmp beg;
/*;16 Bit Hex to BCD Conversion for 8051 Microcontroller ; This routine is
for 16 bit Hex to BCD conversion; ;Accepts a 16 bit binary number in
R1,R2 and returns 5 digit BCD in ; R7,R6,R5,R4,R3(up to 64K )
Hex2BCD: ;r1=high byte ;r7 most significant digit*R2 = LSByte*/
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H, //HIGH_BYTE ; CHECK FOR HIGH
BYTE
SJMP ENDD
HIGH_BYTE: MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT: ADD A,R6
CONTINUE: MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: ret
DISP1:
REFRESH: ;
mov r1,41h
mov r2,40h
CALL HEX2BCD
MOV 18H,r3 ; // least significant digit
MOV 19H,r4 ; //next significant digit
MOV 1AH,r5
mov r2,#10
djnz r2,$ ; //wait 20 us
check_echo:
jnb p3.6, //check timeout
MOV 40h,TL0 ; //read timer count
MOV 41h,TH0
mov r0,40h
mov r1,41h
mov r3,#0
mov r2,#6
call UDIV16 ; //divide by 6
mov 40h,r0
mov 41h,r1
mov 50h,#25
disp: call disp1 ; // show the value on LED
djnz 50h,disp ; //so many times for a visible time limit
jmp beg
checktimeout: mov a,th0
cjne a,#0c0h,check_echo ; //upto 4 metres
jmp beg
;subroutine UDIV16
SEMICONDUCTORS:
S.No. NOTATTION COMPONENT
1. IC1 AT89C2051 microcontroller
2. IC2 ULN2003 current buffer
3. IC3 CD4049 hex inverting buffer
4. IC4 LM324 quad operational amplifier
5. IC5 7815, 15V regulator
6. IC6 7915, -15V regulator
7. IC7 7805, 5V regulator
8. T1,T4 BC557 pnp transistor
9. T5 2N2222 npn transistor
10. D1, D2 1N4148 switching diode
11. D3-D6 1N4007 rectifier diode
12. DIS1-DIS4- LTS 542 common-anode, 7-segment display
Table 2: Resistors
CAPACITORS
S.No. Notation Rating
1. C1, C2 3.3nF ceramic disk
2. C7, C10-C12 0.1μF ceramic disk
3. C3 2.2nF ceramic disk
4. C4 10μF, 16V electrolytic
5. C5, C6 22pF ceramic disk
6. C8, C9 1000μF, 50V electrolytic
Table 3: Capacitors
MISCELLANEOUS
Table 4: Miscellaneous
APPENDIX-B
PCB LAYOUT DESIGN
Figure 7: PCB layout (Top)
Whether or not a material obeys Ohm's law, its resistance can be described in
terms of its bulk resistivity. The resistivity, and thus the resistance, is
temperature dependent. Over sizable ranges of temperature, this temperature
dependence can be predicted from a temperature coefficient of resistance. \
The inverse of resistivity is called conductivity. There are contexts where the
use of conductivity is more convenient.
RESISTOR COMBINATIONS
The combination rules for any number of resistors in series or parallel can be
derived with the use of Ohm's Law, the voltage law, and the current law.
RESISTIVITY CALCULATION
CAPACITOR
Capacitance
The capacitor's capacitance (C) is a measure of the amount of charge (Q) stored
on each plate for a given potential difference or voltage (V) which appears
The capacitance is proportional to the surface area of the conducting plate and
inversely proportional to the distance between the plates. It is also proportional
to the permittivity of the dielectric (that is, non-conducting) substance that
separates the plates.
Stored energy
In electric circuits
Electrons cannot directly pass across the dielectric from one plate of the
capacitor to the other. When there is a current through a capacitor, electrons
accumulate on one plate and electrons are removed from the other plate. This
process is commonly called 'charging' the capacitor even though the capacitor is
at all times electrically neutral. In fact, the current through the capacitor results
in the separation rather than the accumulation of electric charge. This separation
of charge causes an electric field to develop between the plates of the capacitor
giving rise to voltage across the plates. This voltage V is directly proportional to
the amount of charge separated Q. But Q is just the time integral of the current I
through the capacitor. This is expressed mathematically as:
where
For circuits with a constant (DC) voltage source, the voltage across the
capacitor cannot exceed the voltage of the source. Thus, an equilibrium is
reached where the voltage across the capacitor is constant and the current
through the capacitor is zero. For this reason, it is commonly said that
capacitors block DC current.
The current through capacitors in series stays the same, but the voltage across
each capacitor can be different. The sum of the potential differences (voltage) is
equal to the total voltage. To find their total capacitance:
Capacitor/inductor duality
Capacitor symbols
APPENDIX-E
DESCRIPTION
PIN CONFIGURATION
Pin Description
VCC
Supply voltage.
GND
Ground.
PORT 1
Port 1 is an 8-bit bidirectional I/O port. Port pins P1.2 to P1.7 provide internal
pullups. P1.0 and P1.1 require external pullups. P1.0 and P1.1 also serve as the
positive input (AIN0) and the negative input (AIN1), respectively, of the on-
chip precision analog comparator. The Port 1 output buffers can sink 20 mA and
can drive LED displays directly. When 1s are written to Port 1 pins, they can be
used as inputs. When pins P1.2 to P1.7 are used as inputs and are externally
pulled low, they will source current (IIL) because of the internal pullups. Port 1
also receives code data during Flash programming and program verification.
PORT 3
Port 3 pins P3.0 to P3.5, P3.7 are seven bidirectional I/O pins with internal
pullups. P3.6 is hard-wired as an input to the output of the on-chip comparator
and is not accessible as a general purpose I/O pin. The Port 3 output buffers can
sink 20 mA. When 1s are written to Port 3 pins they are pulled high by the
internal pullups and can be used as inputs. As inputs, Port 3 pins that are
externally being pulled low will source current (IIL) because of the pullups.
Port 3 also serves the functions of various special features of the AT89C2051 as
listed below:
Port 3 also receives some control signals for Flash programming and
programming verification.
RST
Reset input. All I/O pins are reset to 1s as soon as RST goes Hig h. Holding the
RST pin high for two machine cycles while the oscillator is running resets the
device. Each machine cycle takes 12 oscillator or clock cycles.
XTAL1
Input to the inverting oscillator amplifier and input to the internal clock
operating circuit.
XTAL2
Output from the inverting oscillator amplifier.
OSCILLATOR CHARACTERISTICS
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier which can be configured for use as an on-chip oscillator, as shown in
Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the
device from an external clock source, XTAL2 should be left unconnected while
XTAL1 is driven as shown in Figure 2. There are no requirements on the duty
cycle of the external clock signal, since the input to the internal clocking
circuitry is through a divide by- two flip-flops, but minimum and maximum
voltage high and low time specifications must be observed. Notes: C1, C2 = 30
pF, 10 pF for Crystals= 40 pF, 10 pF for Ceramic Resonators
(a) (b)
Figure13: (a) Oscillator Connections,
(b) External Clock Drive Configuration
On the chip are two lock bits which can be left unprogrammed (U) or can be
programmed (P) to obtain the additional features listed in the table:
PROGRAMMING ALGORITHM:
1. Power-up sequence: Apply power between VCC and GND pins Set RST and
XTAL1 to GND With all other pins floating, wait for greater than 10
milliseconds
3. Apply the appropriate combination of ’H’ or ’L’ logic levels to pins P3.3,
P3.4, P3.5, P3.7 to select one of the programming operations shown in the
PEROM Programming Modes table. To Program and Verify the Array:
7. To verify the programmed data, lower RST from 12V to logic ’H’ level and
set pins P3.3 to P3.7 to the appropriate levels. Output data can be read at the
port P1 pins.
8. To program a byte at the next address location, pulse XTAL1 pin once to
advance the internal address counter. Apply new data to the port P1 pins.
9. Repeat steps 5 through 8, changing data and advancing the address counter
for the entire 2 Kbytes array or until the end of the object file is reached.
10. Power-off sequence: set XTAL1 to ’L’ set RST to ’L’ Float all other I/O
pins Turn Vcc power off
DATA POLLING: The AT89C2051 features Data Polling to indicate the end
of a write cycle. During a write cycle, an attempted read of the last byte written
will result in the complement of the written data on P1.7. Once the write cycle
has been completed, true data is valid on all outputs, and the next cycle may
begin. Data Polling may begin any time after a write cycle has been initiated.
PROGRAM VERIFY: If lock bits LB1 and LB2 have not been programmed
code data can be read back via the data lines for verification:
1. Reset the internal address counter to 000H by bringing RST from ’L’ to ’H’.
2. Apply the appropriate control signals for Read Code data and read the output
data at the port P1 pins.
3. Pulse pin XTAL1 once to advance the internal address counter.
4. Read the next code data byte at the port P1 pins.
5. Repeat steps 3 and 4 until the entire array is read.
The lock bits cannot be verified directly. Verification of the lock bits is
achieved by observing that their features are enabled.
CHIP ERASE: The entire PEROM array (2 Kbytes) and the two Lock Bits are
erased electrically by using the proper combination of control signals and by
holding P3.2 low for 10 ms. The code array is written with all "1"s in the Chip
Erase operatio and must be executed before any non-blank memory byte can be
re-programmed.
READING THE SIGNATURE BYTES: The signature bytes are read by the
same procedure as a normal verification of locations 000H, 001H, and 002H,
except that P3.5 and P3.7 must be pulled to a logic low. The values returned are
as follows.(000H) = 1EH indicates manufactured by Atmel (001H) = 21H
indicates 89C2051
PROGRAMMING INTERFACE : Every code byte in the Flash array can be
written and the entire array can be erased by using the appropriate combination
of control signals. The write operation cycle is self-timed and once initiated,
will automatically time itself to completion.All major programming vendors
offer worldwide support for the Atmel microcontroller series.
FLASH PROGRAMMING MODES
(a) (b)
DC CHARACTERSTICS
Table 9: DC Characterstics
EXTERNAL CLOCK DRIVE WAVEFORM