EE 401 PROJECT # 2 ULTRASONIC DISTANCE METER GROUP 1‐B PROJECT REPORT MEMBERS Metehan Dilaver 2004502023 Adil Palabıyık 2004502051 H. Anıl Abay 2001502073 SPRING 2009
EE 401
PROJECT # 2
ULTRASONIC DISTANCE METER
GROUP 1‐B
PROJECT REPORT
MEMBERS
Metehan Dilaver 2004502023 Adil Palabıyık 2004502051 H. Anıl Abay 2001502073
SPRING 2009
2
CONTENTS
INTRODUCTION 3
AIM OF PROJECT 4
8051 MICROCONTROLLER 4
PIN CONNECTION OF 8051 4
Usage of EA 4
Usage of PSEN and ALE 4
RAM ROM Connection 5
Usage of RESET Pin 6
Oscillator Pin 6
Constitution of Port 3 6
REALIZATION OF THE PROJECT 7
SPECIFICATIONS OF SRF04 11
BEAM PATTERN 12
TIMING DIAGRAM 13
CALCULATING THE DISTANCE 13
WORKING PRINCIPLES OF PROJECT 14
TROUBLESHOOTING 20
CONCLUSION 21
REFERENCES 22
3
INTRODUCTION
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 Distance Meter” 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
The measure of the distance is done simply like that: ,
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 velocity of the sound multiplied each other, so the half of the result shows the distance of the object.
4
AIM OF THE PROJECT
In this project, the subject that we want to realize is to set up an ultrasonic distance meter with using a AT89c52 type microcontroller. For this purpose, it is needed to have a main design, to connect all elements rightly, to write the program codes for microcontroller, to simulate it in order to check whether it works rightly or not, to supply the necessary elements for our real design, and finally to set up whole project and running it.
In addition that, in the project design it’s planned to show the measure result on an LCD display after measuring the distance of object.
Simply the aim of the project is “designing and running an ultrasonic distance meter which shows the result on LCD screen “.
8051 MICROCONTROLLER
8051 based microcontrollers typically include one or two Uarts, two or three timers, 128 or 256 bytes of internal data RAM (16 bytes of which are bit‐addressable), up to 128 bytes of I‐O, 512 bytes to 64 kB of internal program memory, and sometimes a quantity of extended data RAM (ERAM) located in the external data space. The original 8051 core ran at 12 clock cycles per machine cycle, with most instructions executing in one or two machine cycles. With a 12 MHz clock frequency, the 8051 could thus execute 1 million one‐cycle instructions per second or 500,000 two‐cycle instructions per second. Enhanced 8051 cores are now commonly used which run at six, four, two, or even one clock per machine cycle, and have clock frequencies of up to 100 MHz, and are thus capable of an even greater number of instructions per second.
PIN CONNECTION OF 8051
USAGE OF EA
The EA input signal on pin 31 is generally tied high (+5V) or low (ground). If It’s high, the 8051, 8052 executes programs from internal ROM when executing in the lower 4K/ 8K of memory. If It’s low programs execute from external memory only. (PSEN pulses low accordingly).
5
USAGE OF “PSEN” AND “ALE”
PSEN is a control signal that enables external program (code) memory. It’s usually connected to the EPROM’s output enable (OE) pin to permit reading of program bytes.
The PSEN signal pulses low during the fetch stage of an instruction .The binary codes of a program (op‐codes) are read from EPROM. Travel across the data bus and are latched into the 8051’s instruction register for decoding. When executing a program from internal ROM, PSEN remains in the inactive (high) state.
The ALE output signal on pin 30 will be familiar to anyone who has worked with Intel’s 8085 8088 and 8086 microprocessors. The 8051 similarly uses ALE for de multiplexing the address and data bus. When PORT 0 is used in its alternate mode as the data bus and the low‐byte of the address bus ALE is the signal that latches the address into an external register during the first half of a memory cycle. This done , The PORT 0 lines are then available for data input or output during the second half of the memory cycle , when the data transfer takes place.
RAM‐ ROM CONNECTIONS
In our project design, external RAM and external ROM are used and their connections are done as similar in the figure above. Here, the connections of these elements will be explained. Firstly we need to use a LATCH to stop crossing the address and data information of P0. When ALE is active, the address info is sent to the address pins of EPROM. Also P2 pins are used for the address info as well to the address pins of EPROM.
While ALE is inactive, that time the data is read from the EPROM. This data reading is done with the signal of PSEN. While data is reading from EPROM, PSEN is active.
6
USAGE OF “RESET” PIN
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 orderly system start‐up.
OSCILLATOR PINS
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.
CONSTITUTION OF PORT3
It’s clearly seen the explanation of the PORT 3 pins in the table below. Here, in the usage of MAX232, the T1 IN pin is connected to the PORT 3.0 (serial port data), the R1OUT pin of MAX232 is connected to the PORT3.1
7
REALIZATION OF THE PROJECT
To realize the project, firstly, all the necessary researches are done and information are supplied that are related to design, program and elements that are used.
After research studies a main board design is required. For that purpose a PCB design is done. PCB is designed as suitable as to use 8051 microcontroller, PIO, external RAM and ROM, ADC, latch, logic gates…etc. To design the project, ISIS and ARES programs are used. Firstly simple design of main board is drawn on ISIS program and after that it is created on ARES program. In the figures below, it’s seen the design and PCB schematics in Proteus program.
Figure 1‐a: Designed schematic of PCB on Proteus ISIS
8
Figure 1‐b : 3‐D PCB schematic in ARES
Here in the figure above, the ARES modification of PCB is seen in the 3 dimensions. In this ARES program before printing the PCB It’s possible to see how will the PCB be, It’s top and side views, connections, and elements.
In the next page figures the realized PCB boards are seen.
9
Figure 2‐a : Realized PCB
Figure 2‐b: Realized PCB
10
In the figure in the previous page, it’s easily seen the working of the PCB. When we look at the first picture of PCB, we see the led light. And in the second picture It’s seen another led light. Because that PCB is working from external ROM with the help of EA pin of microcontroller. In the ROM, the program is written to lighting the led one by one. That s why the different leds are seen as lightning in the picture above.
After finishing design procedure of PCB, It’s started to work on the real project. Firstly, with the help of researches, It’s determined which elements are suitable to use, as sensors, LCD, and other elements of circuit design. While choosing them, their working conditions, suitability with other parts in design, easy to find, and the cost of them are cared. As a result of them SRF04 type ultrasonic sensors (transmitter and receiver) are determined to use with 89C52 microcontroller. In this project choosing the sensor type was the most important and necessary subject.
SRF04 type ultrasonic sensor is has two parts as transmitter and receiver parts. Transmitter part transmits the high frequency signal to medium 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.
In the next page the connection diagram and the circuit of ultrasonic sensors is seen clearly.
Figure 3‐a: Ultrasonic sensor design
11
Ultrasonic sensor couples are connected themselves with respect to the diagram of the above. 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.
Figure 3‐b: Ultrasonic sensor design
To get more information about ultrasonic sensors that is used in this project, in the table below some specifications for SRF04 can be seen.
SPECIFICATION VOLTAGE 5 VOLTS CURRENT 30mA Typ. 50mA Max FREQUENCY 40kHz MAX RANGE 3 meters MIN RANGE 3 centimeters ECHO PULSE Positive TTL level signal, proportional to range WEIGHT 0.4 oz SENSITIVITY Detect a 3cm diameter stick at > 2 m INPUT TRIGGER er10uSec minimum, TTL level pulse
12
Beam Pattern:
The SRF04 Timing diagram is shown in the next page. We only need to supply a short 10uS pulse to the trigger input to start the ranging. The SRF04 will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo line high. It then listens for an echo, and as soon as it detects one it lowers the echo line again. The echo line is therefore a pulse whose width is proportional to the distance to the object. By timing the pulse it is possible to calculate the range in inches/centimeters or anything else. If nothing is detected then the SRF04 will lower its echo line anyway after about 36mS.
13
Calculating the Distance
The SRF04 provides an echo pulse proportional to distance. If the width of the pulse is measured in uS, then dividing by 58 will give you the distance in cm, or dividing by 148 will give the distance in inches. uS/58=cm or uS/148=inches.
While choosing the elements for project, the program is determined as well to be written in C codes in Keil u_version to create hex file for microcontroller. The whole program is given at the end of this report clearly.
14
WORKING PRINCIPLE OF PROJECT
As a simple working principle of the project, the diagram can be drawn as seen in the figure below.
Figure 3: Simple working diagram of project
In the project, to make able to work it rightly It’s necessary to give a high frequency signal to ultrasonic sensors. The signal frequency that is used in project is about 40 KHz. For that purpose, It’s planned to set up a circuit that gives an out as a 40 KHz square wave signal. That signal is given to input of ultrasonic sensors.
To set up a square wave oscillator circuit NE 555 IC is used. To create a square wave 555 timer ICs are so useful and common integrated circuits that are used. With the help of adjusting resistors and capacitors It’s easy to have a circuit that gives output 40 KHz square wave signal.On the figure‐4 , It’s seen the oscillator circuit and also It’s output, that is set up with NE 555 IC.
15
Figure 4: 40 KHz square wave oscillator circuit.
The output of this circuit is given to sensors input so that it can make radiation to medium these signals.
When this high frequency signal given to input of sensors, the transmitter sensor starts to radiate it and if these signals reflected from ant object, the receiver sensor gets reflected signals and it gives a sinusoidal output voltage. With the help of this output voltage sensors can detect if there is any object or not in front of them.
When the receiver gets reflected signal from any object, as said, it gives an output sinusoidal voltage, but these output voltage is in so little level. It’s about 0.1 – 0.3 Volt. Because of little amount, these output voltage is not suitable to use for microcontroller. To make able to use this signal with microcontroller, It’s necessary to amplify this low voltage output signal with the help of an amplifier circuit.
To set up an amplifier circuit an op‐amp IC is used for the project. For this purpose LM358 op‐amp IC can be used. In our project, LM358 type op‐amp IC is used for amplifier circuit. In the next page, the op‐amp amplifier circuit can be seen in the figure‐5 clearly.
16
Figure 5: Op‐amp amplifier and its output
As seen in the figure above the op‐amp amplifier circuit is set up and an input sinusoidal signal is given in so little amount of voltages just in milivolts. In the left oscilloscope screen input sinusoidal and as result of amplifier, the amplified sinusoidal is seen. Input sinusoidal voltage amount is here 50 milivolts, and amplified signal is in amount of about 8 Volt. That means our amplifier amplifies the signal for 50 times.
Here , in the figure, two op‐amp is used. First op‐amp is used to amplify the input sinusoidal voltage, and second one is used as comparator. When that comparator gets the amplified signal, it gives an output as +5 Volt (supply voltage) for positive cycle, and it gives 0 Volt for negative cycles of the amplified signal. The comparator output is seen in the second oscilloscope screen above.
The reason of using comparator in the design is, to get +5 V and 0 V exactly. Because these voltage levels are suitable to use for 8051 microcontroller. When the receiver sensor gets any reflected signal from an object, it will give an output in little voltage, it’s amplified and in the output of the comparator a square wave will be supplied to say a message to 8051 as “reflected signal received”.
17
The simple design of our project consist of 8051 microcontroller, It’s sensor input, and its LCD output ports. As seen in the figures below, the connection of sensors, LCD and start button are done.
Figure 6‐a: Completed design of project in simulation program
Figure 6‐b: Completed design of project in simulation program
18
To run the simulation of design, It’s necessary to press the “start button”. When that button is pressed, NE555 oscillator circuit starts to send 40 KHz square wave to the input of transmitter sensor. That square wave is taken from 3 rd pin of NE555 IC, so this pin is connected to sensor input. Also, at the same time when that button pressed, a message signal is sent to 8051 microcontroller to say “signal transmission started”. So, when this message is sent, 8051 starts to run its timer until reflected signal reaches receiver sensor. In addition that, until reflected signal reach, microcontroller shows a writing on LCD display as “No object found”. Because there is no reflected signal reached.
In simulation program, there is no sensor figure, so It’s planned to make the design behave as sensor working with the help of “sensor button”. When that button is pressed, a message signal is sent to microcontroller to say “reflected signal received”. When microcontroller gets this message, it stops the timer running, calculates the distance of the object with respect to the saved time in timer, and shows the result on the LCD display screen in term of cm.
In the next page, It’s clearly seen the completed project design as hardware and software as well. When the real design is run, the result can be seen on the LCD as seen in the figures below and in the next page.
In the figure‐7, completed hardware design of project is seen. Ultrasonic transmitter and receiver sensors, the oscillator circuit that connected to sensors, 8051 microcontroller, LCD display and amplifier circuit are completed and ready to work.
Figure 7: Completed hardware design
19
When the start button is pressed high frequency oscillator starts sending signal to sensors. And until received signal reach to receiver sensor, on the LCD display a message is seen as “Cisim Bulunamadi” means no object found. It’s seen clearly in the Figure‐8.
Figure 8: LCD display after start button pressed
When the received signal reach to the receiver sensor, that time 8051 microcontroller calculates the distance of the object and shows the result on the LCD display in terms of cm value as seen in the Figure 9.
Figure 9: LCD display after received signal reached
20
TROUBLESHOOTING
While working on project, many difficulties and problems occurred. The most important problem was determining the suitable sensor type with our microcontroller. After long and deep researches, SR type ultrasonic transmitter and receiver couple sensors are chosen suitable element for our project.
Another problem occurred in the programming of the microcontroller. Because of wrong or missing headers or punctuation marks, program gives errors. To overcome this problem we have got the error list and it helped us find the errors easily and faster.
In addition that most of difficulties are occurred while we were working on hardware. Firstly while soldering the PCB elements, some short circuit occurred and PCB is unable to work. To overcome this problem, all the elements checked one by one and their connections are checked as well if there is any short circuit or open circuit too. Because of controlling all the PCB deeply, there was a big time loss and tired full struggle for all of us. Because while time passing and unless problem couldn’t be solved that is a demoralizating and demotivating situation. But eventually, all the problem solved and PCB work without any problem.
Beside them another big problem was lived while setting up amplifier circuit. In amplifier circuit, op‐amp ICs are used. But choosing them is so important. Because operating frequency of op‐amp is important parameter to choose them. By ignoring that parameter most of our amplifier circuits didn’t work properly. For that problem, by searching different type amplifier circuit design, we found an amplifier circuit that is set up LM358 op‐amp and we decided to set up similar amplifier circuit as well.
21
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 programming 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 positively.
We believe that with the continuing of similar applications project, our ability in most of subject will be raised day by day.
22
REFERENCES
Web sources
http://www.biltek.tubitak.gov.tr/gelisim/elektronik/dosyalar/diger/ultrasonik.pdf
http://www.8051turk.com/site/
http://hobby_elec.piclist.com/e_srm1_1.htm
http://www.quasarelectronics.com/3123‐atmel‐89‐series‐programmer.htm
http://www.ai‐robotlab.ogu.edu.tr/research_files/kiris2004.pdf
e‐book sources
‐ Endüstri standardı 8051 Ailesi Mikrodenetleyiciler & Analog Devices MicroConverters(ADuC 8xx) Selim Dilmaç
‐ Exploring C for Microcontrollers A Hands on Approach (Jivan S. Parab , Vinod G. Shelake , Rajanish K. Kamat , Gourish M. Naik)
‐ 8051 Microcontroller ARCHITECTURE , PROGRAMMING and APPLICATIONS (Kenneth J. Ayala ‐ Western Carolina University)
‐ Prentice Hall ‐ The 8051 Microcontroller 2nd Edition 1995 ‐ 8051 Mikrodenetleyici Uygulamaları (Özcerit, Çakıroğlu ve Bayılmış)