ultrasonic range finder

28
CHAPTER 1: INTRODUCTION TO PROJECT Measuring the distance is a need of human being always because of many reasons. Knowing distance of any object is so important in lots of categories. In nowadays world, cars, planes, robots, rockets… etc. are need to measure or sense the distance of the objects that are near to them. In addition that, in astronomy, army, security works, research works as water, petrol or mine; distance measuring is very important subject for efficient working, and success. Distance measuring is done with many ways. For example with sound, light, laser, infra‐red, radio navigation, etc. In nowadays world, with the help of developing technology, measuring distance is getting so easy with the sensors. Most of the distance measuring systems have become so common and so easy to use in the daily life of humans. For example, to park a car, to search anything under the land, to have a safe travelling for airplanes, ...etc. and lots of using areas are so common. In the project that is explained in this report is about measuring distance and its called “Ultrasonic Range Finder” because of using the ultrasonic sensors in our project for this purpose. Ultrasonic principle is based on high frequency sound waves that human ear can not 1

Upload: rahul-mahajan

Post on 10-Feb-2016

19 views

Category:

Documents


3 download

DESCRIPTION

3

TRANSCRIPT

Page 1: ULTRASONIC RANGE FINDER

CHAPTER 1: INTRODUCTION TO PROJECTMeasuring the distance is a need of human being always because of many

reasons. Knowing distance of any object is so important in lots of categories. In

nowadays world, cars, planes, robots, rockets… etc. are need to measure or sense the

distance of the objects that are near to them. In addition that, in astronomy, army, security

works, research works as water, petrol or mine; distance measuring is very important

subject for efficient working, and success.

Distance measuring is done with many ways. For example with sound, light, laser,

infra‐red, radio navigation, etc. In nowadays world, with the help of developing

technology, measuring distance is getting so easy with the sensors.

Most of the distance measuring systems have become so common and so easy to use

in the daily life of humans. For example, to park a car, to search anything under the land,

to have a safe travelling for airplanes, ...etc. and lots of using areas are so common.

In the project that is explained in this report is about measuring distance and its

called “Ultrasonic Range Finder” because of using the ultrasonic sensors in our project

for this purpose.

Ultrasonic principle is based on high frequency sound waves that human ear can not

hear. The reasons of using this high frequency waves are can be said as below:‐These waves radiate extremely smooth and linear‐Energy of these waves are in high level‐These waves can be easily reflected from hard planes

1

Page 2: ULTRASONIC RANGE FINDER

The measure of the distance is done simply by following below steps-

Fig1- Block diagram of Ultrasonic Range finder

Firstly ultrasonic waves are sent and then wait until reflected signal has come. After

that, the time is calculated between sent and received signal. Finally, time and the

velocityof the sound multiplied each other, so the half of the result shows the distance of

the object.

2

Page 3: ULTRASONIC RANGE FINDER

CHAPTER-2: INTRODUCTION TO 8051 MICROCONTROLLER

The heart of the project is the 8051 microcontroller which is controlling all the

project.

2.1: FEATURES

The 8051 is an 8-bit processor

The 8051 has 128 bytes of RAM

4K bytes of on-chip ROM

Two 16 bit timers

One serial port

Four I/O ports, each 8 bits wide

6 interrupt sources

Separate 64k programme and 64k data memory

The CPU can work on only 8 bits of data at a time

2.2: PIN DIAGRAM

Fig2- Pin diagram of 8051

3

Page 4: ULTRASONIC RANGE FINDER

2.3: PORTS

The 8051 has four I/O ports

Port 0 (pins 32-39)

Port 1(pins 1-8)

Port 2(pins 21-28)

Port 3(pins 10-17)

Each port has 8 pins

• Named P0.X (X=0,1,...,7), P1.X, P2.X, P3.X

• P0.0 is the bit 0(LSB)of P0

• P0.7 is the bit 7(MSB)of P0.

2.4: CLOCK GENERATION

Fig3- clock generation

4

Page 5: ULTRASONIC RANGE FINDER

8051 has 2 oscillator pins called XTAL1 and XTAL2. A resonance circuit is connected to

these 2 input pins to create a supply for the oscillators that inside of the IC. Generally a

crystal and 2 capacitors is enough for that circuit. A connected resonance circuit that is

also used in our design is seen in the figure below. Here, no matter the value of the

capacitors. They can be chosen between 27 – 47 pF.

2.5: RESET CIRCUIT

The RST input on pin 9 is the master reset for the 8051. When this signal is brought high,

for at least two machine cycles the 8051 internal registers are loaded with appropriate

values for an orderlysystem start-up.

Fig4-Reset circuit

5

Page 6: ULTRASONIC RANGE FINDER

2.6: CONSTITUTION OF PORT3

The port 3 of 8051 provides alternative functions as shown in following table

Table1- Alternative functions of port3

6

Page 7: ULTRASONIC RANGE FINDER

3: INTRODUCTION TO ULTRASONIC SENSORS

400SR100 type ultrasonic sensor is has two parts as transmitter and receiver parts.

Transmitter part transmits the high frequency signal to object and receiver part gets the

reflected signal from any object. These ultrasonic sensors work with high frequency that

more than a human ear can hear.

Fig5- Ultrasonic sensors

Ultrasonic sensor couples are connected themselves with respect to the diagram of

the circuit diagram . The first sensor is transmitting sensor and it has an input pin to get

the PWM.

This input is used for giving high frequency signal. The second one is receiver sensor and

it has an output pin that would be connected to 8051. That output from receiver is

connected to the microcontroller to make it work when received signal is taken from any

object.

7

Page 8: ULTRASONIC RANGE FINDER

3.1: TIMING DIAGRAM

Fig6-Timing diagram of sensor

The ultrasonic transmitter unit with a 40 kHz pulse burst and expect an echo from the

object whose distance you want to measure. Fig. 7 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 above.

8

Page 9: ULTRASONIC RANGE FINDER

3.2BEAM PATTERN

Fig7-Beam pattern of ultrasonic transmitter

The signal at the main lobe is having maximum power whereas at the side lobes it

is having less power.

3.3 SPECIFICATIONS OF 400SR100:

Driving voltage – 10 to 20 v

Driving current- 20mA

Frequency - 40kHz

Maximum range- 3 meters

Minimum range- 3 centimeters

Beam angle -72º

Operating Temperature- -30º to 80ºC

9

Page 10: ULTRASONIC RANGE FINDER

3.4 DISTANCE MEASURMENT

The distance is measured by using the relation of distance and velocity of sound

DISTANCE= (TIME X VELOCITY OF SOUND IN A MEDIUM.)/2

The velocity of sound is approximately 330m/s in air.

This value is divided by two because the ultrasonic wave will take time to reach at the

object as well as to return as an echo.

10

Page 11: ULTRASONIC RANGE FINDER

4: CIRCUIT DESCRIPTION OF ULTRASONIC RANGE FINDER

4.1: CIRCUIT DIAGRAM AND WORKING

Fig. 9 shows the circuit of the microcontroller-based distance meter. The 40kHz

pulse bursts from the microcontroller are amplified by transistor. Inverting buffer 4049

drives the ultrasonic sensor used as the transmitter. Three inverters (N1, N2and N3) are

connected in parallel to increase the transmitted power.

This inverted output is fed to another set of three inverters (N4, N5and 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-degreephase shift is applied to another terminal. Thus

the transmitter power is increased for increasing the range.

The echo signal received by the receiver sensor after reflection is very weak. It is

amplified by quad operational amplifier LM324.

The first stage 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.

The second stage of theinverting amplifier uses a 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 voltageof less than

0.6V. The output is filtered to accept 40kHz frequencies and fed to pin 12 of LM324

which is non inverting input of the fourth comparator. Pin13 is the inverting pin of the

comparator used for level adjustment using trimmer which is set to Vref=0.17v.

The output of this comparator which will be amplified echo pulse given to the pin

P3.2 of microcontroller for counting of time. When port-3 pin P3.2 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.

11

Page 12: ULTRASONIC RANGE FINDER

12

Page 13: ULTRASONIC RANGE FINDER

4.2: SOFTWARE

PROGRAM:

#include<reg51.h>

sfrldata=0xA0; // assign port2 to for lcd data

sbitrs=P1^2; // assign lcd rs, rw, enable pins

sbitrw=P1^1;

sbit en=P1^0;

sbit echo=P3^2; // assign echo pin

sbit trig=P1^4; // assign pin for 40kHz pulse

int a,p,count=0, d=0,e,e1,f,f1,g,g1,h,h1,t,t1;

unsigned char r[]=" ULTRASONIC";

unsigned char s[]="RANGE FINDER";

unsigned char j[]="DISTANCE=";

void msdelay(unsigned int k) //delay subroutine

{

Unsigned int i, j;

for(i=0;i<=k;i++)

{

for(j=0;j<=1275;j++);

}

}

13

Page 14: ULTRASONIC RANGE FINDER

Void lcdmsg(unsigned int value) //lcd data subroutine

{

ldata=value;

rs=1;

rw=0;

en=1;

msdelay(10);

en=0;

}

Void lcdcmd(unsigned int value) //lcd command subroutine

{

ldata=value;

rs=0;

rw=0;

en=1;

msdelay(10);

en=0;

}

void main()

{

P3=0XFF; // port 3 as input port

14

Page 15: ULTRASONIC RANGE FINDER

P1=0xF8; // pins P1.0, P1.1, P1.2 as output

P2=0x00; // port 2 as output port

trig=0;

echo=0;

TMOD=0X22; // timer0, timer1, both in mode2 i.e. auto reload

TH0=0xF5; // count in timer 0 for 40kHz pulse

TH1=0xCB; // count in timer1 for pulse width(14.5mS)

lcdcmd(0x38); // lnitialise lcd as 2 lines and 5x7 matrix

lcdcmd(0x0E); //lcd on

for(a=0;a<11;a++)

{

lcdmsg(r[a]);

}

lcdcmd(0xc0);

for(a=0;a<12;a++)

{

lcdmsg(s[a]);

}

while(1)

{

15

Page 16: ULTRASONIC RANGE FINDER

count=0;

{

for(p=0;p<26;p++) // send 25 40kHz pulses to Tx

{

TF0=0;

TH0=0XF5;

trig=0;

TR0=1;

while(TF0==0){}

trig=1;

TF0=0;

while(TF0==0){}

}

}

if(echo==1) // check whether echo is available

{

while (echo==1)

{

TR1=1; // if yes, start timer1

lcdcmd(0x01);

for(a=0;a<9;a++)

16

Page 17: ULTRASONIC RANGE FINDER

{

lcdmsg(j[a]);

}

while(TF1==0)

{}

count++;

TF1=0;

}

TR1=0; // stop timer

d=(count*0.0145*330)/2; // count distance

e=d/1000;

t=d%1000;

f=t/100;

t1=t%100;

g=t1/10;

h=t1%10;

e1=0x30|e;

f1=0x30|f;

g1=0x30|g;

h1=0x30|h;

17

Page 18: ULTRASONIC RANGE FINDER

lcdcmd(0x89); // display distance on lcd

lcdmsg(e1);

lcdcmd(0x8A);

lcdmsg(f1);

lcdcmd(0x8B);

lcdmsg(g1);

lcdcmd(0x8C);

lcdmsg(h1);

lcdmsg('c');

lcdmsg('m');

}

}

}

PROGRAM DESCRIPTION

The program is written in embedded C language.

The pin P1.4 is used for giving the 40 kHz pulse which is done with the help of

timer0. Port 2 is assigned for data sending to lcd. RS, RW ,E pins ofl lcd are connected

to P1.2, P1.1,P1.0 respectively.

The echo pulse from the comparator output is given to P3.2. By using timer1 the

high level width of the pulse which is proportional to the distance between object is

calculated. ( distance= time x velocity of sound/2).

18

Page 19: ULTRASONIC RANGE FINDER

19

Page 20: ULTRASONIC RANGE FINDER

4.3: APPLICATIONS

Automatic parking system.

Obstacle warning system

Terrain monitoring robots

Industrial distance measurement

Burglar alarm unit for office or home

Airplane landing

4.4: ADVANTAGES OF ULTRASONIC DISTANCE MEASUREMENT

It can give very accurate measurement which is highly important in military

applications, airplane landing, etc.

We can also measure distance of an object through water.

By making few modifications we can also detect a moving objects and find their

range and speed.

4.5: DISADVANTAGES OF ULTRASONIC DISTANCE MEASUREMENT

It requires very precise frequency, a slight change in frequency of pulse may

affect the accuracy.

The characteristics of ultrasonic sensor change with change in temperature, so

special attention is required to be given for applications where high accuracy is

required.

20

Page 21: ULTRASONIC RANGE FINDER

CONCLUSION

Ultrasonic distance meter project was very useful application for us because of using

several elements, hardware design, connecting them, and programming microcontroller

as software. This project has taught us how a real project can be realized, to develop our

programing ability, and hardware design.

By the help of this project work, our ability of setting up circuit, connecting elements,

soldering, and hand practice are developed and so that we got a good trust of ourselves to

success something in real.

In addition to that, this project‐work is as a start of an experiment for our job that we

will do in future. With the help of that, we learnt how to see the difficulties and problems,

how to overcome all of them and solve all problems so that to reach the success.

Beside all them, we have found the possibility to realize a real thing. It’s not as the

same to do it by simulations on PC. Seeing a real thing and its running make us feel more

positive.

We believe that with the continuing of similar applications project, our ability in most

of subject will be raised day by day.

21

Page 22: ULTRASONIC RANGE FINDER

REFERENCES-

E-Book

The 8051 microcontroller by Md. Ali Mazidi

Websites

www.8051project.com

www.alldatasheets.com

www.datasheetarchieves.com

www.efymag.com

www.midascomponents.uk

22