Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

MAHATMA GANDHI MISSIONS

COLLEGE OF ENGINEERING AND


TECHNOLOGY
KAMOTHE, NAVI MUMBAI - 410209.
A REPORT ON ULTRASONIC

RANGE
FINDER USING 8051 CONTROLLER
Project Report Presented By:
SR.NO
NAME
NO
1.
2.
3.
4.

NEERAJ KUMAR
RITU KUMARI
SURAJ MALVE
ANAMIKA MANE

ROLL
32

Submitted in partial fulfillment of term work for the


subject.
ELECTRONIC HARDWARE AND WORKSHOP

CERTIFICATE
This is to certify that the project ULTRASONIC
RANGE FINDER USING 8051 CONTROLLER is a
work carried out by Mr.NEERAJ KUMAR,
Miss.RITU
KUMARI,
Mr.SURAJ
MANE,
Miss.ANAMIKA MANE from the department of
Electronics and Telecommunication [T.E.] and have
successfully completed the project and its report in
partial fulfillment of the term work for the subject
Electronic Hardware Workshop in MGMs College of
Engineering and Technology, Kamothe.
___________________
Signature of the Guide

__________________
Signature of H.O.D.

______________
Examiner

Place: - MGMs College of Engineering and Technology, Kamothe.


Date:-

ABSTRACT

The report details the implementation of distance measurement system using the
ultrasonic waves. As the human ears audible perception range is 20 Hz to 40
kHz, it is insensitive to ultrasonic waves, and hence the ultrasound waves can be
used for applications in industries/vehicles without hindering human activity.
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 measurement unit uses a continuous signal in the transmission frequency
range of ultrasonic transducers. The signal is transmitted by an ultrasonic
transducer, reflected by an obstacle and received by another transducer where
the signal is detected. The time delay of the transmitted and the received signal
corresponds to the distance between the system and the obstacle.

TABLE OF CONTENTS

CHAPTER NO.

1.

TITLE

PAGE NO.

ABSTRACT

iii

LIST OF FIGURES

vi

INTRODUCTION
1.1

OBJECTIVE

1.2

ULTRASONIC RANGE FINDER

1.3

BLOCK DIAGRAM OF ULTRASONIC

2
4

RANGE FINDER
1.4 THEORY OF OPERATION

1.5

1.6
2

ULTRASONIC WAVES
1.5.1 LONGITUDINAL WAVES

1.5.2 TRANSVERSE WAVES

ULTRASONIC DISTANCE SENSORS

CIRCUIT DESCRIPTION

2.1 POWER SUPPLY

11

2.2 CONSTRUCTION AND TESTING

12

SOFTWARE

14

3.1 ASSEMBLY LANGUAGE PROGRAM

14

3.2 OTHER USES

20

CONCLUSION

23

4.1 APPLICATION

24

APPENDICES

25
APPENDIX-A

25

APPENDIX-B

27

APPENDIX-C

28

APPENDIX-D

31

APPENDIX-E
REFERENCES

49

LIST OF FIGURES
1.

BLOCK DIAGRAM OF ULTRASONIC RANGE FINDER

2.

TRANSMITTING AND RECEIVING WAVES

3.

ULTRASONIC TRANSDUCER (TRANSMITTER AND RECEIVER

4.

CIRCUIT DIAGRAM OF ULTRASONIC RANGE FINDER

5.

POWER SUPPLY CIRCUIT DIAGRAM

11

6.

TRANSMITTED AND RECEIVED PULSES

13

7.

PCB LAYOUT (TOP)

25

8.

PCB LAYOUT (BOTTOM)

25

9.

CAPACITOR CHARGE FORMATION

29

10

CAPACITOR CHARGE FORMATION 2

29

11.

IC 89C2051 PINOUT DIAGRAM

35

12.

IC 89C2051 BLOCK DIAGRAM

36

13.

(A) OSCILLATOR CONNECTIONS

38

(B) EXTERNAL CLOCK DRIVE CONFIGURATION

38

(A) PROGRAMMING THE FLASH MEMORY

42

(B)VERIFYING THE FLASH MEMORY

42

14.

15.
16.

FLASH PROGRAMMING AND VERIFICATION WAVEFORMS


EXTERNAL CLOCK DRIVE WAVEFORM

43
45

of-flight method of range

1 INTRODUCTION
2

measurement is subject to

3 The techniques of distance

high

measurement using ultrasonic

of

signal

attenuation when used in an

in air include continuous wave

air medium, thus limiting its

and pulse echo technique. In


the pulse echo method, a burst

levels

distance range.

of pulses is sent through the

4
5 1.1 OBJECTIVE

transmission medium and is

reflected by an object kept at

7 The object of this work is to

specified distance. The time

replace the old traditional

taken

to

range detector, used in several

propagate from transmitter to

applications. In present work

receiver is proportional to the

the

distance of object. For contact

measured

less measurement of distance,

using seven segment displays

the device has to rely on the

by replacing the heavy and

target to reflect the pulse back

bulky

to itself. The target needs to

compact

have a proper orientation that

intelligent

is it needs to be perpendicular

The bulky pressing switch is

to the direction of propagation

replaced by the small and one

of the pulses. The amplitude

touch tactile switch. It saves

of the received signal gets

electric consumption, saves

significantly attenuated and is

the no. of man power, through

a function of nature of the

seven segment display and

medium

one microcontroller as well as

for

and

the

the

pulse

distance

object

position

is

electronically

by

circuits

with

circuits

the
using

Microcontroller.

between the transmitter and

ultrasonic

receiver

target. The pulse echo or time-

transmitter sensors.

&

amplifier

9 1.2 ULTRASONIC RANGE

Ca4M4VI

iM324I
four

inverter
T-segment

displays I five transistors and

FINDER
10

some discreet components.

11 There are several ways to

The

measure

distance

without

ultrasonic

transmitter-

receiver pair is shown in

contact. One way is to use

Ultrasonic

ultrasonic waves at 40 kHz for

piezoelectric materials such as

distance

zinc

measurement.

Ultrasonic

generators

or

lead

use

zirconium

transducers

tartrates or quartz crystal. The

measure the amount of time

material thickness decides the

taken for a pulse of sound to

resonant

frequency

travel to a particular surface

mounted

and

and return as the reflected

electrodes attached on either

echo. This circuit calculates

side

the distance based on the

scanners used for abdomen or

speed of sound at 25C

heart ultrasound are designed

ambient

and

at 2.R Mez. fn this circuit, a

shows it on a 7-segment

40kHz transducer is used for

display. Using it, you can

measurement

measure distance up to 2.5

medium.

meters. For this particular

sound in the air is around 330

application,

m/s at 0C and varies with

temperature

the

required

components are AT89C2051


microcontroller, two 40kHz
ultrasonic transducers
each

for

receiver),
ULN2003,

of

it.

excited
The

in

The

when
by

medical

the

velocity

air
of

temperature.
12 In this project, you excite

(one

the ultrasonic transmitter unit

transmitter and

with a 40kHz pulse burst and

current

buffer

operational

expect

an

echo

from the

object whose distance you

want to measure. Fig. 2 shows

sound pulses. It reads when

the transmitted burst, which

the echo arrives; it finds the

lasts

of

time taken in microseconds

It

for to-and-fro travel of sound

travels to the object in the

waves. Using velocity of 333

air and the echo signal is

m/s, it does the calculations

picked

and shows on the four 7-

for

approximately

up

ultrasonic

period
0.5

by

ms.

another
unit

segment displays the distance

(receiver), also a 40 kHz pre-

in centimeters and millimeters

tuned

(three digits for centimeters

unit.

transducer
The

received

signal, which is very weak is

and one for millimeters).

amplified several times in the

13

receiver circuit and appears

14 1.3 BLOCK DIAGRAM OF

somewhat as shown in Fig. 2

ULTRASONIC

when seen on a CRO. Weak

FINDER

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

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

15
16

RANGE

17

18 Figure 1 : Block Diagram of


Ultrasonic Range Finder
19
20
21 1.4 THEORY OF
OPERATION
22 HC-SR04 timing diagram.

27 Distance in cm = echo pulse


width in uS/58
28 Distance in inch = echo pulse
width in uS/148

29
30 1.5 ULTRASONIC WAVES
31
32 Sound waves with frequency
range from 20 Hz to 20 KHz

23

are responsive to the human


24

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
25

HC-SR04 Timing diagram

26 From the timing diagram, you


can see that the 40KHz pulse
train is transmitted just after the
10uS triggering pulse and the
echo output is obtained after
some more time. The next
triggering pulse can be given only
after the echo is faded away and
this time period is called cycle
period. The cycle period for HCSR04 must not be below 50mS.
According to datasheet, the
distance can be calculated from
the echo pulse width using the
following equations.

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

frequencies are designed for

distance

different distance range and

compensate

the

dependency

of

amplitude,

while

reflection

properties

the

echo

different

different

resolution.

Such

sensors are employed in the

are

automation

of

industrial

compensated by an automatic

processes as well as in traffic

gain control, which holds the

control systems, for example

average

echo

amplitude

to

constant.

Echo

amplitude

parking places are occupied.

therefore

has

whether

car

little

Ultrasonic distance meters are

influence on the accuracy of

used for the measurement of

the

measurement

the filling level in containers

provided the signal to noise

or the height of material on

ratio is not very low. By

conveyor

considering whether the echo

waves are generally used two

has been received within a

types which are given as :-

distance

very

monitor,

belts.

Ultrasonic

time window, i.e. a time

35

interval, which can be preset

36 1.5.1 LONGITUDINAL

by the user, the distance range

WAVES

is given in which the sensor

37 Longitudinal

waves

exist

responds to the presence of an

when the motion

object. Using this technique,

particle and the medium is

interference can be suppressed

parallel to the direction of

and

propagation of the waves.

relevant

objects

are

monitored more reliably.


variety

presence
different

of

ultrasonic

sensors

the

These types of waves are

33

34 A

of

with
operation

referred as L waves. Since


these can travel in solid, liquid
and gases. These waves can
be easily detected.

38

47

39 1.5.2 TRANSVERSE
WAVES
40 In this case particles of the
medium vibrate at right angle

48 HC-SR04 ultrasonic ranging module (Fig1)

to the direction of propagation


of the waves. These are also
called shear waves.
41
42 1.6 HC-SR04 ULTRASONIC
MODULE
43
44 HC-SR04
ranging

is

an

ultrasonic

module designed for

embedded system projects like


this. It has a resolution of 0.3cm
and the ranging distance is from
2cm to 500cm. It operates from a
5V DC supply and the standby
current is less than 2mA. The
module transmits an ultrasonic
signal,

picks

measures

up

the

its

time

echo,
elapsed

between the two events and


outputs a waveform whose high
time

is

modulated

measured
proportional

time
to

by

the

which

is

the

distance.

.The photograph of an HC-SR04


module is shown below.
45

46

49
50 The supporting circuits fabricated
on the module makes it almost
stand alone and what the
programmer need to do is to send
a trigger signal to it for initiating
transmission and receive the echo
signal from it for distance
calculation. The HR-SR04 has
four pins namely Vcc, Trigger,
Echo, GND and they are
explained in detail below.
51 1) VCC : 5V DC supply voltage is
connected to this pin.
52 2) Trigger: The trigger signal for
starting the transmission is given
to this pin. The trigger signal
must be a pulse with 10uS high
time. When the module receives a
valid trigger signal it issues 8
pulses of 40KHz ultrasonic sound
from the transmitter. The echo of
this sound is picked by the
receiver.
53 3)Echo: At this pin, the module
outputs a waveform with high
time proportional to the distance.
54 4) GND: Ground is connected to
this pin.

55 CIRCUIT
DESCRIPTION

58

56
57 A simple ultrasonic range
finder

using

8051

microcontroller is presented in
this article. This ultrasonic
rangefinder

can

measure

distances up to 2.5 meters at


an accuracy of 1 centi meter.
AT89s51 microcontroller and
the

ultrasonic

transducer

module HC-SR04 forms the


basis of this circuit. The
ultrasonic module sends a
signal to the object, then picks
up its echo and outputs a wave
form whose time period is
proportional to the distance.
The microcontroller accepts
this

signal,

necessary
displays

performs

processing
the

and

corresponding

distance on the 3 digit seven


segment display. This circuit
finds a lot of application in
projects

like

parking

sensors,

warning

automotive

systems,

obstacle
terrain

monitoring robots, industrial


distance measurements etc.

59

62

60

The ultrasonic module


is

interfaced

to

the

microcontroller through P3.0


and P3.1 pins. Port0 used for
transmitting the 8 bit display
data to the display and port
pins P1.0, P1.1, P1.2 are used
for transmitting display drive
signals for the corresponding
display units D1, D2, D3.
Push

button

switch

S1,

capacitor C3 and resistor R9


forms a de-bouncing reset
circuitry. Capacitors C1,C2
and crystal X1 are associated
with the clock circuit.
61

63
64 2.1 POWER SUPPLY

65 Figure shows the circuit of the


power supply. The 9V battery
is connected to a capacitor
filtered by capacitors C4 and
then regulated by ICs 7805.
Regulator

7805

provide

regulated supply, respectively.

69 Figure 5: Power Supply


Circuit Diagram
70

71
72 2.2

CONSTRUCTION

AND TESTING
73 An

actual-size,

single-side

Capacitors C5 bypass

the

PCB for the microcontroller-

ripples

the

based distance meter is shown

supply.

in Fig. 6 and its component

Resictor is connected to led to

layout in Fig. 7. Assemble the

protect it form fusing. We will

PCB and put the programmed

get the required 5vto the ckt.

microcontroller

regulated

present
power

in

into

the

socket. After switching on the


power

supply

and

microcontroller automatically
getting

reset

upon

power-on, pin 8 will pulse at


40kHz bursts. This can be
seen using an oscilloscope.
Give this signal to channel 1
of the oscilloscope. Adjust the
time base to 2 ms per division
and set it to trigger mode
instead

of

normal

mode.

Adjust the potentiometer on


66
67
68

the

oscilloscope

labeled

level such that the trace


starts with the burst and

appears steady as shown.

echoes also. When the echo

Connect the transmitter and

signal goes above the level of

receiver ultrasonic units either

reference voltage set on pin

by a twisted pair of wire or by

13, it will make P3.6 low; the

a shielded cable to the board.

arrival of echo is sensed by

Give the received signal to

the program using jnb p3.6

channel 2 of the oscilloscope.

(jump not bit) instruction.

Then, place an A4-size plastic

Software The software is \

sheet in front of the ultrasonic

written in Assembly language

transducers and observe the

and assembled using 8051

echo signal. It will appear as

cross-assembler. It is well

shown. The two transducers

commented

can be fixed to a thick

understand. The pulse train

cardboard with two wires

for 0.5 ms is started by

leading to the circuittwo

making pin 8 high and low

40cm long shielded cables

alternately

will do. The laser pointer is

microseconds so that the pulse

fixed such that it is axial to

frequency is 40 kHz. After 25

the transducers. Channel 2 is

such pulses have passed, a

connected to pin 12, which is

waiting time is given to avoid

the

non-inverting

direct echoes for about 20 s.

AT89C2051s

Then the signal is awaited,

positive

terminal

of

comparator.

The

and

for

easy

to

12.5

negative

while the timer runs counting

inverting terminal (pin 13) is

time in microseconds. When

connected

preset

the echo arrives, port-3 pin

reference. Adjust the preset

P3.6 goes high, the timer

such that the voltage is 0.1V-

reads and the 16-bit number is

0.2V at pin 13. This will

divided by twice the velocity

enable

and converted into decimal

to

detection

of

weak

format as a 4-digit number. If

74

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. Other uses
Simply

by

changing

this

program, the same unit can be


made to detect moving objects
(such as cars racing on the
street) and find their range

75
76

77 Figure 6: Transmitted and


Received Pulses

and speed. It can also be used

78

with

80

suitable

additional

software as a burglar alarm


unit for homes or offices.

79 3. SOFTWARE
81 The software is written in
Assembly

language

and

assembled using 8051 crossassembler.

It

is

commented

and

easy

well
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.
82
83 3.1

ASSEMBLY

LANGUAGE PROGRAM
84 PROGRAM :
85

ORG 00H

MOV DPTR,#SSDisplay //
moves the address of LUT to
DPTR
87 MOV P1,#00000000B // sets P1
as output port
88 MOV P0,#00000000B // sets P0
as output port
89 CLR P3.0 // sets P3.0 as output
for sending trigger
90 SETB P3.1 // sets P3.1 as input
for receiving echo
91 MOV TMOD,#00100000B //
sets timer1 as mode 2 auto
reload timer
92 MAIN: MOV TL1,#210D // loads
the initial value to start counting
from
93
MOV TH1,#210D // loads
the reload value
94
MOV A,#00000000B //
clears accumulator
95
SETB P3.0 // starts the
trigger pulse
96
ACALL DELAY1 // gives
10uS width for the trigger pulse
97
CLR P3.0 // ends the
trigger pulse
98 HERE: JNB P3.1,HERE // loops
here until echo is received
99 BACK: SETB TR1 // starts the
timer1
100 HERE1: JNB TF1,HERE1 //
loops here until timer overflows
(ie;48 count)
101
CLR TR1 // stops the
timer
102
CLR TF1 // clears timer
flag 1
103
INC A // increments A
for every timer1 overflow
104
JB P3.1,BACK // jumps
to BACK if echo is still available
105
MOV R4,A // saves the
value of A to R4
106
ACALL DLOOP // calls
the display loop
107
SJMP MAIN // jumps to
MAIN loop
86

108

109 DELAY1:

MOV R6,#2D // 10uS

delay
110 LOOP1:

DJNZ R6,LOOP1
111
RET

112
113 DLOOP:

MOV R5,#50D // loads


R5 with 100D
114 BACK1: MOV A,R4 // loads the
value in R4 to A
115
MOV B,#100D // loads
B with 100D
116
DIV AB // isolates the
first digit
117
SETB P1.0 // activates
LED display unit D1
118
ACALL DISPLAY //
calls DISPLAY subroutine
119
MOV P0,A // moves
digit drive pattern for 1st digit to
P0
120
ACALL DELAY // 1mS
delay
121
ACALL DELAY
122
MOV A,B // moves the
remainder of 1st division to A
123
MOV B,#10D // loads B
with 10D
124
DIV AB // isolates the
second digit
125
CLR P1.0 // deactivates
LED display unit D1
126
SETB P1.1 // activates
LED display unit D2
127
ACALL DISPLAY
128
MOV P0,A // moves digit
drive pattern for 2nd digit to P0
129
ACALL DELAY
130
ACALL DELAY
131
MOV A,B // moves the
remainder of 2nd division to A
132
CLR P1.1 // deactivates
LED display unit D2
133
SETB P1.2 // activates
LED display unit D3
134
ACALL DISPLAY
135
MOV P0,A // moves the
digit drive pattern for 3rd digit to
P0
136
ACALL DELAY
137
ACALL DELAY

CLR P1.2 // deactivates


LED display unit D3
139
DJNZ R5,BACK1 //
repeats the display loop 100
times
140
RET
138

141
142 DELAY:

MOV R7,#250D //
1mS delay
143 LABEL2: DJNZ R7,LABEL2
144
RET
145
146 DISPLAY:

MOVC
A,@A+DPTR // gets the digit
drive pattern for the content in A
147
RET
148
149 SSDisplay:

DB 0C0H // Hex
code to display DISPLAY 0
150 DB 0F9H // DISPLAY 1
151 DB 0A4H // DISPLAY 2
152 DB 0B0H // DISPLAY 3
153 DB 99H // DISPLAY 4
154 DB 92H // DISPLAY 5
155 DB 82H // DISPLAY 6
156 DB 0F8H // DISPLAY 7
157 DB 80H // DISPLAY 8
158 DB 90H // DISPLAY 9
159
160 END

161
162
163

3.2 OTHER USES

164

Simply by changing

this program, 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
software as a burglar alarm
unit for homes or offices.

171

4.CONCLUSION

165
166

The objective of this

project is to design and

Distance Measurement
device. As described in this
report a system is developed
that can detect objects and
calculate the distance of the
tracked object. With respect to
the requirements for an
ultrasonic range finder the
following can be concluded.

The system is able to detect


objects within the sensing

range.
The system can calculate the
distance of the obstruction
with
167
168

sufficient accuracy.

This device has the

capability to interact with other


peripheral if
169

used as a secondary

device.
170

This can also

communicate with PC through


its serial port.

This offers a

low cost and efficient solution


for non contact type
172

implement an Ultrasonic
Obstruction Detection and

distance

measurements.
173

The Range Finder has

numerous applications. It can


be used for automatic guided
vehicles, positioning of robots
as well as measuring generic
distances, liquid levels in
tanks, and the depth of snow
banks. The device can serve
as

motion

production
ultrasonic
relates

detector

in

lines.

The

detection

range

with

size,

figure,

material and position of the


object.

The

bigger

the

reflector is, the better the


reflectance is, and the stronger
the reflection signal is. The
ultrasonic
measurement

distance
is

an

untouchable detection mode.


Compared with else detection
modes, it does not get much
influenced by ray, temperature
and colour etc, and it has the

great capability to adapt to

would be more on the former

various

circumstances

and

one.

ambient

conditions.

restricted

target

angle

(it

requires a near perpendicular


surface)

and

which

can

large

beam,

create

poor

resolution, seem to be the


Range

Finders

only

limitations. Also there is a


blind

area

limitation

and
in

distance

distance
ultrasonic

measurement.

Despite these drawbacks, we


find the devices main features
to be extremely useful.
174
175
176
177

4.1 APPLICATIONS

181

In industry ultrasonic is

employed for :a Low power applications


where in the ultrasonic energy
explores a body of material
and is thereby modified.
b High power application where
in the ultrasonics energy
modifies the body of material
to which it is applied.
182

Some of the important

low power applications are :183

1) Flow detection,

184

2) Thickness gauging,

185

3) Measurement of

various physical properties of


materials.

Applications of

186

4) Extent of corrosion

ultrasonic can be divided into

187

5) Estimation of grain

two categories.
178

1. Ultrasonics in

industry
179

2. Ultrasonics in

medicine
180

Both are big fields in

themselves. The concentration

sizes in polycrystalline
materials.
188

6) Measurement of

pressure, concentration
temperature, viscosity and
flow rates.
189

7) leak detection

190

8) Variable delay lines

for computer applications and


imaging,
191

9) Liquid level control

192

APPENDIX A

230

193

SEMICONDUCTORS

.No.
233

:
195

NOTATTION

196

198

IC1

199

201

IC2

204

Ultrasonic

module
207

T1,T2,T3

210

DIS1-DIS4- LTS

1.
236
2
COMPONENT

231

Notation

232

234

C1, C2

235

237

C4, C5

238

240

C3

241

No.

239
AT89S52

.
microcontroller
243
202
7805, 5V242
regulator
245
246
248
249
205
HC-SR04
251
252
Table 3: Capacitors
253
208
2N2222 npn
254
MISCELLANEOUS
transistor
255
211
common-anode,
7-

256
S
segment display
Table 1: Semiconductor
.No.
Components
259
213
1.
RESISTORS (all -

542
212

214

257

Notation

258

260

X1

261
to
262

watt, 5% carbon):
215

.No.
218
1.

216

Notation

219

R1, R2, R3,

R8, R9,R10, R11


222
R12

266

224
.
227
228

225

269

XTAL

267

S1

268

270

S2

271

273

TX1

274

RX1

tra
277

R13

.
275

Table 2: Resistors

6
.

278
CAPACITORS

264

272

sec
265

R4, R5, R6, R7,

221

229

263

ele
244
247
250

276

rec

279
Table 4: Miscellaneous

280
281

APPENDIX-B

282

PCB

LAYOUT

287

APPENDIX- C

288

RESISTANCE

289

290
291

The electrical

DESIGN

resistance

283

circuit component or

of

device is defined as
the

ratio

of

the

voltage applied to
the electric current
which flows through
it:

292
293
284

Figure 7: PCB layout


(Top)

285

If the resistance is
constant

over

considerable
of

range

voltage,

then

Ohm's law, I = V/R,


can

be

used

to

predict the behavior


of

the

material.

Although

the

definition

above

involves DC current
286

Figure 8: PCB layout


(Bottom)

and
same

voltage,

the

definition

294

holds for the AC

conditions, and the resistance

application

of a wire can be expressed as

of

resistors.
Whether or

not

297

material obeys Ohm's law, its


resistance can be described in
terms of its bulk resistivity.
The resistivity, and thus the
resistance,
dependent.

is

temperature

Over

sizable

ranges of temperature, this


temperature dependence can
be

predicted

temperature

from

coefficient

of

resistance. \

295

299

The

factor

in

the

resistance which takes into


account the nature of the
material is the resistivity.
Although it is temperature
dependent, it can be used at a
given temperature to calculate
the resistance of a wire of

RESISTIVITY

AND CONDUCTIVITY
296

298

The electrical resistance

given geometry.
300

The

inverse

of

of a wire would be expected

resistivity

to be greater for a longer wire,

conductivity.

less for a wire of larger cross

contexts where the use of

sectional area, and would be

conductivity

expected to depend upon the

convenient.

is

called

There
is

are
more

material out of which the wire


is made. Experimentally, the
dependence

upon

these

properties is a straightforward
one for a wide range of

301

Electrical conductivity

= = 1/

302

dependence

RESISTOR

these

properties is a straightforward

COMBINATIONS
303

upon

The combination rules

for any number of resistors in


series or parallel can be

one for a wide range of


conditions, and the resistance
of a wire can be expressed as

derived with the use of Ohm's


Law, the voltage law, and the
current law.

307
308

304

Resistance = resistivity

x length/area

305

RESISTIVITY

CALCULATION
306

The electrical resistance

of a wire would be expected


to be greater for a longer wire,
less for a wire of larger cross
sectional area, and would be
expected to depend upon the
material out of which the wire
is

made

Experimentally,

(resistivity).
the

309

APPENDIX-D

region between the plates that


is proportional to the amount

310

CAPACITOR
A capacitor consists of

of accumulated charge. This

two electrodes or plates, each

potential difference V = Ed

of which stores an opposite

between the plates of this

charge. These two plates are

simple

conductive and are separated

capacitor.

311
312

electric

field

creates

parallel-plate

by an insulator or dielectric.
The charge is stored at the
surface of the plates, at the
boundary with the dielectric.
Because each plate stores an
equal but opposite charge, the

316

total charge in the capacitor is

317

always zero.

Figure 10: Capacitor


Charge formation 2

318

The electrons in the

molecules move or rotate the


molecule

toward

the

positively charged left plate.


This

process

creates

an

opposing electric field that


partially

313
314

Figure 9: Capacitor
charge formation

315

When electric charge

accumulates on the plates, an


electric field is created in the

annuls

the

field

created by the plates. (The air


gap is shown for clarity; in a
real capacitor, the dielectric is
in direct contact with the
plates.)

319

Capacitance
320

conducting)

substance

that

separates the plates.

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

323

Stored energy

324

As

opposite

charges

accumulate on the plates of a


capacitor due to the separation
of charge, a voltage develops
across the capacitor owing to

between the plates:

the electric field of these

In SI units, a capacitor

charges. Ever increasing work

has a capacitance of one farad

must be done against this ever

when one coulomb of charge

increasing electric field as

causes a potential difference

more charge is separated. The

of one volt across the plates.

energy (measured in joules, in

Since the farad is a very large

SI) stored in a capacitor is

unit, values of capacitors are

equal to the amount of work

usually

required

321

expressed

in

to

establish

the

microfarads (F), nanofarads

voltage across the capacitor,

(nF) or picofarads (pF).

and

therefore

the

electric

field. The energy stored is


322

The

capacitance

is

given by:

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-

325
326

where V is the voltage

across the capacitor.

327

In electric circuits

328

Circuits

just the time integral of the

with

DC

sources
329

Electrons

directly

cannot

pass

across

current

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
at

all

times

electrically neutral. In fact, the


current through the capacitor
results in the separation rather
than

the

electric

accumulation
charge.

of
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

is

the

mathematically as:

the

the capacitor to the other.

is

through

capacitor. This is expressed

330

dielectric from one plate of

capacitor

directly

proportional to the amount of


charge separated Q. But Q is

331
332

where
I is the current flowing

in the conventional direction,


measured in amperes
333

dV/dt

is

derivative

the

of

time

voltage,

measured in volts / second.


334

C is the capacitance in

farads
335

For

circuits

with

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.

336

Series

or

parallel

arrangements
337

to increase the overall voltage


rating. In practice, a very

Capacitors in a parallel

large

resistor

might

configuration each have the

connected

same

difference

capacitor to divide the total

(voltage). To find their total

voltage appropriately for the

equivalent capacitance (Ceq):

individual ratings.

potential

343

338

across

be
each

Capacitor/inductor

duality
344

In mathematical terms,

the ideal capacitor can be


considered as an inverse of
the ideal inductor, because the

339
340

The

current

voltage-current equations of
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:
341

the

two

devices

can

be

transformed into one another


by exchanging the voltage and
current terms. Just as two or
more

inductors

can

be

magnetically coupled to make


a transformer, two or more
charged conductors can be
electrostatically

coupled

to

make a capacitor. The mutual


capacitance

of

two

conductors is defined as the


One possible reason to

current that flows in one when

connect capacitors in series is

the voltage across the other

342

changes by unit voltage in

348

unit time.

349
350

345

Capacitor symbols

10

11

12

13

14

15

346

351

352
353
354
355
356
357
358
359
360
361

362
APPENDIX-E
363
364
DATASHEET -IC
89C2051
365
366
FEATURES
Compatible with MCS-51
Products
2 Kbytes of Reprogrammable
Flash Memory
367

Endurance: 1,000

Write/Erase Cycles
2.7 V to 6 V Operating Range
Fully Static Operation: 0 Hz
to 24 MHz
Two-Level Program Memory

347

Lock
128 x 8-Bit Internal RAM
15 Programmable I/O Lines
Two 16-Bit Timer/Counters
Six Interrupt Sources

Programmable Serial UART

following standard features: 2

Channel
Direct LED Drive Outputs
On-Chip Analog Comparator
Low Power Idle and Power

Kbytes of Flash, 128 bytes of


RAM, 15 I/O lines, two 16-bit
timer/counters, a five vector
two-level

Down Modes

interrupt

architecture, a full duplex

368

369
370
371

DESCRIPTION

serial port, a precision analog

The AT89C2051 is a

comparator, on-chip oscillator

high-

and

8-bit

addition, the AT89C2051 is

microcomputer with 2 Kbytes

designed with static logic for

of Flash programmable and

operation

erasable read only memory

frequency and supports two

(PEROM).

software

low-voltage,
performance

CMOS

The

device

is

clock

circuitry.

down

to

selectable

In

zero
power

manufactured using Atmels

saving modes. The Idle Mode

high

stops the CPU while allowing

density

nonvolatile

memory technology and is

the

compatible with the industry

serial

standard MCS-51 instruction

system

set and pinout. By combining

functioning. The Power Down

a versatile 8-bit CPU with

Mode

Flash on a monolithic chip,

contents

the Atmel AT89C2051 is a

oscillator disabling all other

powerful

chip functions until the next

which

microcomputer

provides

highly

flexible and cost effective


solution to many embedded
control

applications.

AT89C2051

provides

The
the

RAM,

timer/counters,

port

and
to

saves
but

interrupt
continue

the
freezes

hardware reset.
372
373
PIN
CONFIGURATION

RAM
the

374

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

400

Figure 11: IC 89C2051


Pinout Diagram
401
402

Figure 12: IC 89C2051


Block Diagram
403

Pin Description

404
405

406
407
408
409
410
411
412
413

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.
BLOCK DIAGRAM
399

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

will

1s are written to Port 1 pins,

because of the pullups.

they can be used as inputs.

source

current

(IIL)

Port 3 also serves the

416

When pins P1.2 to P1.7 are

functions of various special

used

features of the AT89C2051 as

as

inputs

and

are

externally pulled low, they


will

source

because

of

current
the

listed below:

(IIL)

417

internal

pullups. Port 1 also receives


code

data

programming

during
and

Flash
program

verification.
414
415
P3.5,

418

PORT 3
Port 3 pins P3.0 to
P3.7

are

seven

bidirectional I/O pins with


internal pullups. P3.6 is hardwired 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

420

Table 5: Port 3
Functions
419
Port 3 also receives

some control signals for Flash


programming

and

programming verification.
421

RST

422

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.
423

XTAL1

424

Input to the inverting

maximum voltage high and

oscillator amplifier and input

low time specifications must

to the internal clock operating

be observed. Notes: C1, C2 =

circuit.

30 pF, 10 pF for Crystals= 40

425

XTAL2

426

Output

pF,
from

the

inverting oscillator amplifier.

10

pF

for

Ceramic

Resonators
431
432

427

428
OSCILLATOR
CHARACTERISTICS
429

430
the

XTAL1 and XTAL2 are


input

and

output,
(a)

respectively, of an inverting
amplifier

which

can

be

configured for use as an onchip 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

(b)

433
Figure13:
(a) Oscillator Connections,
434
(b)
External Clock Drive
Configuration
435
436
PROGRAM
MEMORY LOCK BITS
437
438

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:

439

resumes program execution,


from where it left off, up to

440

two machine cycles before the


internal reset algorithm takes
control.

On-chip

hardware

inhibits access to internal


441

Table 6: Program
Memory Lock Bits

RAM in this event, but access


to

the

port

pins

is

not

inhibited. To eliminate the

442

possibility of an unexpected

443

IDLE MODE

444

In idle mode, the CPU

puts itself to sleep while all


the on-chip peripherals remain
active. The mode is invoked
by software. The content of
the on-chip RAM and all the
special

functions

registers

remain unchanged during this


mode. The idle mode can be
terminated by any enabled
interrupt or by a hardware
reset. P1.0 and P1.1 should be
set to 0 if no external pull
ups are used, or set to 1 if
external pullups are used. It
should be noted that when idle
is terminated by a hardware
reset, the device normally

write to a port pin when Idle


is terminated by reset, the
instruction following the one
that invokes Idle should not
be one that writes to a port pin
or to external memory.
445
446

POWER

DOWN

MODE
447

In the power down

mode the oscillator is stopped,


and

the

instruction

that

invokes power down is the


last instruction executed. The
on-chip RAM and Special
Function Registers retain their
values until the power down
mode is terminated. The only
exit from power down is a

hardware

reset.

Reset

any non-blank byte, the entire

redefines the SFRs but does

memory array needs to be

not change the on-chip RAM.

erased electrically.

The reset should not be

453

activated

before

454

restored

to

VCC

its

is

normal

INTERNAL

ADDRESS COUNTER: The

operating level and must be

AT89C2051

held active long enough to

internal

allow the oscillator to restart

counter which is always reset

and stabilize. P1.0 and P1.1

to 000H on the rising edge of

should be set to 0 if no

RST and is advanced by

external pullups are used, or

applying a positive going

set to 1 if external pullups

pulse to pin XTAL1.

are used.

455

448

PROGRAMMING

THE FLASH
The

AT89C2051

is

shipped with the 2 Kbytes of


on-chip

PEROM

code

memory array in the erased


state (i.e., contents = FFH)
and ready to be programmed.
The code memory array is
programmed one byte at a
time.

address

PROGRAMMING

456

450

452

PEROM

an

ALGORITHM:

449
451

contains

Once

the

array

isprogrammed, to re-program

457
The first part of the
program
sets
the
initial
conditions. Port 0 and P0rt 1 are
set as output ports for sending
digit drive patterns and digit
drive signals respectively. Port
pin 3.0 is set as an output pin for
sending the trigger signal to the
ultrasonic module for starting
transmission and port pin 3.1 is
set as an input pin for receiving
the echo. TMOD register of the
microcontroller is so loaded that
the Timer 1 operates in mode2 8
bit auto-reload mode. Timer 0 of
the microcontroller is not used
here. In the next part of the

program (loop MAIN) the TL1


and TH1 registers of Timer1 are
loaded with the initial values. TL1
is loaded with the initial value to
start counting from and TH1 is
loaded with the reload value. This
is how timer 1 in mode 2 works:
When TR1 bit of the TCON
register is set the TL1 starts
counting from the initial value
loaded into it and keeps counting
untill roll over (ie; 255D). When
roll over occurs, TF1 flag is set
and TL1 is automatically loaded
with the reload value stored in
TH1 and the sequence is repeated
until TR1 is made low by the
program. The TF1 goes high at
the first roll over and if you want
it as an indicator for each roll
over, you have to clear it using
the program after each roll over.
In the next part of the MAIN loop
P3.0 is set high for 10uS and then
cleared to make 10uS triggering
pulse. The ultrasonic module
issues a 40Khz pulse wave form
after receiving this trigger and
the program waits until a valid
echo is received at P3.1. The pulse
width of the echo signal is
proportional to the distance to
the obstacle and so the next job of
the program is to measure the
pulse width. Whenever there is a
valid echo pulse at P3.1, the
Timer1 starts and it counts from
the initial value to 255 ie: 255207= 48 counts. Then the
counter restarts and accumulator
increments by one for every

restart. This sequence is repeated


until the echo signal at P3.1
vanishes (ie; P3.1 goes low). Now
the content in A will be equal to
the number of Timer1 reloads
which is in fact proportional to
the distance. From the datasheet
it is clear that 58uS echo pulse
width indicates 1cM distance.
When the processor is clocked by
a 12MHz crystal, 58 counts of
Timer1 indicates 1cM. That
means 1 reload is equal to 1cM.
But here we are letting the
Timer1 to count only 48 times
before reload and this is done in
order to compensate for the time
lags caused by the branching
instructions used for checking the
status of P3.0 and P3.1 pins. If
this trick is not done, the
individual time lags caused by the
branching instructions will be
cumilatively
added
to
the
observed pulse width and the
range finder will show a reading
higher than the original distance.
Some trial and error was required
for getting the correct Timer1
reload value and with the 207D
(ie; 48 counts) used here the
error was found to be less than
half a centimeter which is quite
fine in this context. The next part
of the program does necessary
mathematics on the current
content in A and displays it as 3
digit readout on the display.

458

data on P1.7. Once the write

Notes.

459
1) The LUT used here was
originally made for a common
cathode seven segment display
and here we are using common
anode displays. The CPL A
instruction will just complement
the obtained digit drive pattern
and make is suitable for the
common anode scheme. If you
have time ,then cook up an LUT
for common anode scheme and
replace the current one using it.
By this you can avoid the extra
CPL A instruction and it is the
correct method.
460
2)The entire circuit can be
powered from 5V DC.
4613) Be careful while handling the
Ultrasonic module. There are a
lot of sensitive surface mount
devices fabricated on its back
side.
462
4)Go
through
these
articles: Interfacing
seven
segment display to 8051, Delay
using 8051 timer, Software delay
routines using 8051.

463
464

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.
465
466

READY/BUSY:

The

Progress of byte programming


can also be monitored by the
RDY/BSY output signal. Pin
P3.1 is pulled low after P3.2
goes

High

programming

during
to

indicate

BUSY. P3.1 is pulled High


again when programming is
done to indicate READY.
467
468

PROGRAM VERIFY:

If lock bits LB1 and LB2 have


not been programmed code

DATA POLLING: The

AT89C2051

features

Data

data can be read back via the


data lines for verification:

Polling to indicate the end of a

469

write cycle. During a write

470

1. Reset the internal

cycle, an attempted read of the

address counter to 000H by

last byte written will result in

bringing RST from L to H.

the complement of the written

471

2.

Apply

the

478

appropriate control signals for

479

READING

THE

Read Code data and read the

SIGNATURE BYTES: The

output data at the port P1 pins.

signature bytes are read by the

472

3. Pulse pin XTAL1

same procedure as a normal

once to advance the internal

verification of locations 000H,

address counter.

001H, and 002H, except that

473

4. Read the next code

data byte at the port P1 pins.


474

to a logic low. The values

5. Repeat steps 3 and 4

until the entire array is read.


475

P3.5 and P3.7 must be pulled


returned are as follows.(000H)
= 1EH indicates manufactured

The lock bits cannot be

verified directly. Verification


of the lock bits is achieved by

by Atmel (001H) = 21H


indicates 89C2051
480

PROGRAMMING

observing that their features

INTERFACE : Every code

are enabled.

byte in the Flash array can be

476

written and the entire array

477

CHIP ERASE:

The

can be erased by using the

(2

appropriate combination of

Kbytes) and the two Lock Bits

control signals. The write

are

operation cycle is self-timed

entire

PEROM

erased

array

electrically

by

using the proper combination

and

of control signals and by

automatically time itself to

holding P3.2 low for 10 ms.

completion.All

The code array is written with

programming vendors offer

all "1"s in the Chip Erase

worldwide support for the

operatio and must be executed

Atmel microcontroller series.

before any non-blank memory

481

byte can be re-programmed.

482

once

initiated,

will
major

483

FLASH

490

PROGRAMMING MODES
484
485

486

(a)

Table 7: Flash

Programming Modes
487
488
489

(b)

491

Figure 14: (a)

Programming the Flash


Memory

492

(b)Verifying the

499

Flash Memory
493
494

500

Figure 15: Flash

Programming and Verification


Waveforms
501
502
503
504
505
495

506

Table 8:Flash

MAXIMUM POWER

Programing and Verification


496

497

VERIFICATION
WAVEFORMS
498

RATING
507

FLASH

PROGRAMMING

ABSOLUTE

508

AND

509

Table 8: Absolute

519

Maximum Power Rating

EXTERNAL CLOCK

DRIVE WAVEFORM

510

511

520

DC

CHARACTERSTICS
512
513

521

Figure 16: External


Clock Drive Waveform

522

523

EXTERNAL CLOCK

DRIVE
524
525

514

Table 9: DC

526

Table 9: External Clock


Drive

Characterstics
515
516
517
518

527

528

REFERENCES

529

1)

Electronics

you - September 1998.

for

530

2)

536

Gadre,

www.electronicsforu.com

www.scribd.com/doc/7370615

538

Programming

and

537

Controller.

8)

Mattiat. OE, The


Transducers

Materials.

4)
539

533

V.

Ultrasonic

/Ultrasonic-Distance-Meter
532

Dhananjay

Customizing the AVR

3)

531

7)

9)

David

A.

Bell,

www.atmel.com/atmel/acrob

Electronic

at/doc0368.pdf

Circuits, Oxford University

5)

Press, 2008.

Kenneth J. Ayala, The

8051

Microcontroller

540

10)

Devices

and

Sensors

&

Architecture, Programming &

Transducers Journal, Vol. 95,

Applications, West Publishing

Issue 8, August 2008, pp.

Company, College & School


Division, 1996.
534

6)

Mazidi,

542

Muhammad Ali
Janice

&

Gillispie

Pearson Education.

11)

Alan

Systems,

Andrews,

Barker Limited,
543

Microcontroller

Embedded

49-57

ABCs of Ultrasonic, Arthur

Mazidi, The 8051


535

541

544
545

London, 1961.

You might also like