10.07.2015 Views

ATMEGA ULTRASONIC RANGE FINDER FAKHRUL ADLEE BIN ...

ATMEGA ULTRASONIC RANGE FINDER FAKHRUL ADLEE BIN ...

ATMEGA ULTRASONIC RANGE FINDER FAKHRUL ADLEE BIN ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

vABSTRACTManual distance measuring is always done at the expense of human error.Precise and fix measurement of low range distance, is the main objective for thisproject. This device can measure distance in the range of 0.5m to 4m with theaccuracy of1cm.This project is used to measure the distance by using ultrasonicsensors. It works by transmitting an ultrasonic waves at 40 kHz. Then, the tranducerswill measure the amount of time taken for a pulse of sound travel to a particularsurfaces and return as the reflected echo. After that, the circuit that have beenprogrammed with ATmega microcontroller will calculate the distance based on thespeed of sound at 25°C which an ambient temperature and also the time taken. Thedistance then will be display on a LCD module.


viABSTRAKPengukur jarak secara manual sentiasa dilakukan dengan mengorbankan ralatmanusia. Ketepatan dan ketetapan ukuran dari julat jarak yang dekat merupakanobjektif utama untuk projek ini. Alat ini boleh mengukur jarak dalam julat 0.5 m ke4 m dengan ketepatan 1 cm. Projek ini digunakan untuk mengukur jarak denganmenggunakan pengesan ultrasonik. Ia berfungsi dengan menghantar satu gelombangultrasonik pada frekuensi 40 kHz. Kemudian, transducer akan mengukur jumlahmasa yang diambil untuk nadi bunyi bergerak ke permukaan tertentu dan kembalisebagai gema pantulan. Selepas itu, litar yang telah diprogramkan dengan pengawalmikro ATmega akan mengira jarak berdasarkan kelajuan bunyi pada suhu 25° Ciaitu suhu persekitaran dan juga dengan menggunakan jumlah masa yang telahdiambil. Jarak yang dikira akan dipaparkan di modul LCD.


viiTABLE OF CONTENTSCHAPTER TITLE PAGEDECLARATIONDEDICATIONACKNOWLEDGEMENTABSTRACTABSTRAKTABLE OF CONTENTSLIST OF TABLESLIST OF FIGURESLIST OF SYMBOLSLIST OF APPENDICESiiiiiivvviviiixxxixii1 INTRODUCTION 11.1 Introduction 11.2 Problem Statement 11.3 Objectives 21.4 Scope Of Work 22 BACKGROUND AND LITERATURE REVIEW 32.1 Overview 32.2 Ultrasonic Waves 32.3 Ultrasonic Transducer 42.4 Ultrasonic Transmitter 52.5 555 Timer 62.6 Ultrasonic Receiver 82.7 Atmega 8951 Microcontroller 92.7.1 Instruction Set 103 RESEARCH METHODOLOGY 153.1 Introduction 153.2 Scope Of Study 163.3 Review On Previous Research 163.4 Section Of Methodology 173.5 Research Technique 17


ixLIST OF TABLESTABLE NO. TITLE PAGE2.1 Datasheet Of 555 Timer 74.1 Timeline For Working Progress 206.1 Speed Of Sound At Different Temperature 386.2 The Ultrasonic Wave Speed Through Different Medium 407.1 Distance Measurement With Error 44


xiLIST OF SYMBOLSIC- Intergrated Circuitµs - micro secondλ- wavelength of soundm/s - metre per secondns- nano secondm- metreΩ- OhmkΩ - kilo OhmnF - nano Faradf- frequencymW - mili WattV- Volts°C - degree CelciusGND - GroundRST - resetkHz - kilo HertzMHz - Mega Hertz


xiiLIST OF APPENDICESAPPENDIX TITLE PAGEA C Language ForATmega Ultrasonic Range Finder 49-54


CHAPTER 1INTRODUCTION1.1 IntroductionThis project proposes the implementation of ultrasonic range finder. This firstchapter includes the problem statement, objectives, and scope of the project.1.2 Problem StatementNowadays, we have some difficulties in obtaining the distance that we wantto measure. Eventhough, we have a measuring tape, but this kind of tool will have alimit for us to measure a distance. Before this, engineers have produce a range findermodule but in the end, they find out the module have many disadvantages likelimitation for distance, different result for different coloured obstacles, and need acalibration for everytime before starts using it.


42.3 Ultrasonic TransducerUltrasonic sensors (also known as transceivers when they both send andreceive) work on a principle which evaluate attributes of a target by interpreting theechoes from radio or sound waves respectively. Ultrasonic sensors generate highfrequency sound waves and evaluate the echo which is received back by the sensor.Sensors calculate the time interval between sending the signal and receiving the echoto determine the distance to an object.Figure 2.1 :Ultrasonic Transmitter And Receiver PairFigure 2.2 :Ultrasonic Transmitter And Receiver Pair Used In This Project.


52.4 Ultrasonic TransmitterThe transmitter consists of an electronics circuitry and an electromechanicaltransducer.The electronic circuitry generates the required frequency electrical signaland the electromechanical transducer converts that electrical signal into the physicalform and activates the open medium surface. This oscillating physical surfacecreates the ultrasonic Waves. The oscillating surface creates a pressure variation andultimately a pressure wave with a frequency equal to that of the surface oscillation.Figure 2.3: The transmitter circuit design.The transmitter was designed to oscillate at a resonant frequency of about 40KHz. The 555 timer generates a 40 KHz sinusoidal ultrasonic wave.


62.5 555 TimerThe 555 monolithic timing circuits is highly stable controller capable ofproducing accurate time delays, or oscillation .In the delay time of operation, thetime is precisely controlled by one external resistor and capacitor .For a stableoperation as an oscillator, the free running frequency and the duty cycle are bothaccurately controlled with two external resistors and one capacitor.Figure 2.4 :The 555 timer block diagram.


7The Table 2.1 shows the datasheet of the 555 timer, the parameter rating andthe units characterized by each component.Table 2.1 : Datasheet of the 555 timerSymbol Parameter Rating UnitV CC Supply Voltage +16 VPdMaximum allowablepower dissipation600 mWTAOperating ambienttemperature range0 to 70 ºCVTH(Vcc = 5v) Threshold voltage 3.33 VVTRIG(Vcc = 5v) Trigger Voltage 1.67 VVRESET Reset Voltage 0.3 to 1.0 V


82.6 Ultrasonic ReceiverThe receiver also has the same configuration except that it has a receiverelectronic circuitry and a transducer, which converts the ultrasonic sound waves intoan electrical signal. The sound waves travel into the medium and are reflected by anobject in the path of the waves. This reflected wave is then sensed by the receiver,which actually calculates the time of flight of the signal to find the distance.Figure 2.5 : The receiver circuit design.


92.7 AT89S51 MicrocontrollerThe microcontroller is used to generate 40 kHz sound pulse. It reads whenthe echo arrives, it finds the time taken in microseconds for to and from travel ofsound waves. Using velocity of 330 m/s, it does the calculations and shows on theLCD Module and display the distance in centimetres. It used In-Systemprogramming (ISP) to be programmed and this programmer will be elaborate morein chapter 5.Figure 2.6 : The microcontroller top view.


102.7.1 Instruction Set51 in AT89S51 means that this microcontroller have 51 instruction set.Instruction set is a subroutine that have been used in order to complete any processusing microcontroller. But not all the 51 instruction set have been used in certainprojects. There are a few instruction set which is popular and always been used togenerate algorithms,moving or to do another functions.ACALL - Absolute CallACALL unconditionally calls a subroutine at the indicated code address.ACALL pushes the address of the instruction that follows ACALL onto the stack,least-significant-byte first, most-significant-byte second. The Program Counter isthen updated so that program execution continues at the indicated address.The newvalue for the Program Counter is calculated by replacing the least-significant-byte ofthe Program Counter with the second byte of the ACALL instruction, and replacingbits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicatethe page. Bits 3-7 of the most-significant-byte of the Program Counter remainunchaged.ADD and ADDC - Add Accumulator and Add Accumulator With CarryADD and ADDC both add the value operand to the value of theAccumulator, leaving the resulting value in the Accumulator. The value operand isnot affected. ADD and ADDC function identically except that ADDC adds the valueof operand as well as the value of the Carry flag whereas ADD does not add theCarry flag to the result.AJMP - Absolute JumpAJMP unconditionally jumps to the indicated code address. The new valuefor the Program Counter is calculated by replacing the least-significant-byte of theProgram Counter with the second byte of the AJMP instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate thepage of the byte following the AJMP instruction. Bits 3-7 of the most-significantbyteof the Program Counter remain unchaged.


11CJNE - Compare and Jump If Not EqualCJNE compares the value of operand1 and operand2 and branches to theindicated relative address if operand1 and operand2 are not equal. If the twooperands are equal program flow continues with the instruction following the CJNEinstruction.CLR - Clear RegisterCLR clears (sets to 0) all the bit(s) of the indicated register. If the register is abit (including the carry bit), only the specified bit is affected. Clearing theAccumulator sets the Accumulator's value to 0.CPL - Complement RegisterCPL complements operand, leaving the result in operand. If operand is asingle bit then the state of the bit will be reversed. If operand is the Accumulatorthen all the bits in the Accumulator will be reversed. This can be thought of as"Accumulator Logical Exclusive OR 255" or as "255-Accumulator." Ifthe operand refers to a bit of an output Port, the value that will be complemented isbased on the last value written to that bit, not the last value read from it.DIV – Divide Accumulator by BDivides the unsigned value of the Accumulator by the unsigned value of the"B" register. The resulting quotient is placed in the Accumulator and the remainderis placed in the "B" register.DJNZ - Decrement and Jump if Not ZeroDJNZ decrements the value of register by 1. If the initial value of register is0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new valueof register is not 0 the program will branch to the address indicated by relative addr.If the new value of register is 0 program flow continues with the instructionfollowing the DJNZ instruction.


12INC - Increment RegisterINC increments the value of register by 1. If the initial value of register is255 (0xFF Hex), incrementing the value will cause it to reset to 0. Note: The CarryFlag is NOT set when the value "rolls over" from 255 to 0.JBC - Jump if Bit Set and Clear BitJBC will branch to the address indicated by reladdr if the bit indicated by bitaddr is set. Before branching to reladdr the instruction will clear the indicated bit. Ifthe bit is not set program execution continues with the instruction following the JBCinstruction.Figure 2.7 :Atmega 8951 Microcontroller Used In This Project.There is a reason why we use AT89S51 in this project. First of all, AT89S51is a low-power, high-performance CMOS 8-bit microcontroller with 4K bytes of In-System Programmable Flash memory. The device is manufactured using Atmel’shigh density nonvolatile memory technology and is compatible with the industry


13standard 80C51 instruction set and pinout. The on-chip Flash allows the programmemory to be reprogrammed in-system or by a conventional nonvolatile memorypro-grammer. By combining a versatile 8-bit CPU with In-System ProgrammableFlash on a monolithic chip, the Atmel AT89S51 is a powerful microcontroller whichprovides a highly flexible and cost effective solution to many embedded controlapplications. The AT89S51 provides the following standard features: 4K bytes ofFlash, 128 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, two 16-bit timer/counters, a five-vector two level interrupt architecture, a full duplex serialport, on-chip oscillator, and clock circuitry. In addition, the AT89S51 is designedwith static logic for operation down to zero frequency and supports two softwareselectable power saving modes. The Idle Mode stops the CPU while allowing theRAM, timer/counters, serial port, and interrupt system to continue functioning. ThePower-down mode saves the RAM contents but freezes the oscillator, disabling allother chip functions until the next external interrupt or hardware reset.


Figure 2.8 : The block diagram of AT89S51 microcontroller14


CHAPTER 3RESEARCH METHODOLOGY3.1 IntroductionThis project aim to measure a distance from any obstacles. Besides that, thisproject also want to findout a distance from 0.5m up to 4m. The flow of this projectfrankly start from the connection of all hardware components and after we done withall the hardware works, we need to create the coding or C language for themicrocontroller. Actually, the hardest part of this project is to create the assemblylanguage because we need to find heeqution for microcontroller to to calculate thedistance travel by the ultrasonic waves.By measuring the time taken for the whole process, it will use the arithmeticoperation that have been programmed in AT89S51 microcontroller in order to obtainthe distance. Lastly, the output will be display at LCD Module.


163.2 Scope of StudyDesigning complete model of ATmega Ultrasonic Range Finder nearlyimpossible for this project because time constraint and limited resources. Scope ofthis project narrowed into few items as follow: Transmission of ultrasonic waves.ATmega programming for arithmetic operation.Measurement of a distance from any obstacles.With this smaller scope of study the realization of the project objectivebecome achievable.3.3 Review on Previous ResearchThrough reading and research, there are one project or module with similarfield. It is the project made by electronic hobbyists and engineers which is “IRRange Finder Module”. But in the end, this projects have some lack characteristicsand disadvantageous which is :Sharp GP2D12 Distance Measurement Sensor has a maximum rangeof 80cm.GP2D120 Distance Measurement Sensor has a maximum range of30cm only.


173.4 Selection of MethodologyBased on this project, it needs two methodologies, which are hardware andsoftware (C language) parts. For hardware, the work is just to design a circuit andfind a suitable components to make sure this project is successful to produce theresult. Next, for software we need to generate and create a C language for AT89S51microcontroller.3.5 Research TechniqueThe programming and coding for the first of all must be test it functionality.The platform used in this project would be ISP. The simulation should perform thecalculation for a measurement by using the speed of ultrasonic wave and time takenfor the waves to bounce back.. After conforming the functionality of theprogramming then we should generate circuit like coding in the ISP.


CHAPTER 4PROJECT MANAGEMENT4.1 IntroductionIn this chapter, there will be an explaination the flow of this project work andhow the project is working. Actually project management is very important partbecause fro there, we can see and check whether our project is going well or not.


194.2 Flowchart Of The ProjectFlowchart is one of many ways that we can use to show and to make sure thatwe are working according to our plan or not. There are several flowchart thati havecreate for this project but not all of them will be shown in this chapter.Figure 4.1 : Flowchart Of Whole Project


204.3 TimelineForWorkProgressNext, is the table for the working progress for this project. This tablesincludes my working and the range of time for me to finish the work.Week 1 Week 2 –Week 4Week 5 –week 7Week 8 –week 11Gather allinformationabout theproject.√Design the basiccircuit of theproject.√Finish thehardware work. √ √Derive anequation andcreate an Clanguage forATMegamicrocontroller.√√


21Week 12 Week 13- –Week 14Week 15Test the project.√Check all the errorsfound and fix all theproblems.√√Prepare forpresentations anddemonstration.√Table 4.1 : Timeline for working process


CHAPTER 5SYSTEM DESIGN5.1 IntroductionIn this chapter, there will be an explaination about the working of the circuit.There will be the function of the main components and also a diagrams for a betterunderstanding.5.2 Circuit DescriptionFigure 5.5 shows the full circuit of this project. The 40kHz pulse bursts fromthe microcontroller are amplified by thyristor. Inverting buffer drives the ultrasonicsensor used as the transmitter. Three inverter are connected parallel to increase thetransmitted power. This inverted output is fed to another set three inverters. Outputsof both sets parallel inverter are applied as a push-pull drive to the ultrasonictransmitter.The positive going pulse is applied to one of the ultrasonic sensor and thesame pulse after 180 degree phase shift is applied to another terminal. Thus thetransmitted power is increased for the increasing the range.


23The echo signal received by the receiver sensor after reflection is very weak.It is amplified by operational amplifier. The rectifier functions, unlike a simplediode, even for signal voltage of less than 0.6V. The output is filtered to accept40kHz frequencies and fed to pin 12 of microcontroller, which is an analogcomparator.Microcontroller AT89S51is at the heart of the circuit. Port-1 pins P1.7through P1.2, and port-3 pin P3.7 are connected to input pins 1 through 7 of currentbuffer, respectively. These pins are pulled up with a 10-kilo-ohm resistor network.They drive all the segments of the LCD module display with the help ofinverter.Microcontroller AT89S51 provides the segment data and display-enablesignal simultaneously in time-division multiplexed mode for displaying a particularnumber on the LCD module.Segment data and display-enable pulse for the display are refreshed every5ms. Thus the LCD module appears to be continuously display. Using switch S1 wecan manually reset the microcontroller, while the power on reset signal for themicrocontroller is derived from the combination of capacitor and resistor.A 12MHzcrystal is used to generate the basic clock frequency for the microcontroller.The comparator is inbuilt in microcontroller AT89S51. The echo signal willmake port-3 pin 3.6 low when it goes above the level of voltage set on pin 13. Thisstatus is sensed by the microcontroller as programmed. When port-3 pin P3.6 goeshigh, we know that the echo signal has arrived, the timer is read and the 16-bitnumber is divided by twice the velocity of sound and then converted into decimalformat.


245.3 The ProgramThis program is written in C code. It is compiled using the program MicroCin order to generate the Hex file. In-System programming (ISP) is used as aprogrammer to write the coding before being programmed into microcontroller.5.3.1 In-System Programming (ISP)ISP is a technique to load hex file in microcontroller without removingmicrocontroller from its target. This programmer can be used either for in-systemprogramming or as a stand-alone spi programmer for Atmel ISP programmabledevices.


255.3.2 Hardware Of ISPFigure 5.1 shows the circuit diagram of the In-System programmer (ISP)interface, where the power to the interface is provided by the PC USB port whichcan supply a maximum current of 100 mA. This programmer circuit can be used toprogram the 89S series devices and the AVR series devices which are pin compatibleto 8051.Figure 5.1 :Cicuit Diagram Of ISP Programmer Interface


265.3.2 Software Of ISPThis software have the main features as follow :Read and write the intel hex fileRead signature, lock and fuse bitsClear and fill memory bufferReload current hex fileAuto detection of hardwareThe memory buffer contains both code data and the EEPROM data for thedevices which have eeprom memory. The eeprom memory addres in buffer is startedafter the code memory, so it is necessary the hex file should contains the eepromstart address after the end of the code memory last address. The software does notprovide the erase command because this function is performed automatically duringdevice programming.Figure 5.2 : Main screen of the ISP programmer


275.4 FlowchartThe flowchart below show for obtaining the time taken before the distancewill be calculate.


Figure 5.3 : Flowchart of the project obtaining the distance28


295.5 C LanguageC language or in simple word we call as coding is written in ISP. Then, weneed to connect the ISPprogrammer with computer or laptop by using USB cable.After that, we programmed the coding that we have written earlier inside themicrocontroller. The assembly language is shown at Appendix A.5.6 Circuit DesignThe functionality of this system can be divided into three main parts asshown in the transmitter, the receiver, the microcontroller and the digital display.The transmitter, enabled via the microcontroller, is designed to activate a 555oscillator with a frequency of 40 KHz. The width of the pulse is 0.1 ms, every 40 msa pulse is transmitted.


Figure 5.4 :The printed circuit board diagram of the circuit30


Figure 5.5 :Schematic diagram of the circuit31


32Figure 5.6 : Complete circuitHere is list of all components used in this project. There are resistors,capacitors, IC and sockets, diode, transistors, switches and heat sink.100Ω resistor, 1.8 kΩ resistor, 3 kΩ resistor, 10 kΩ resistor, 12 kΩresistor, 470 kΩ resistor (1 unit)390Ω resistor, 120 kΩ resistor (2 units)1kΩ resistor (3 units)0.02 µF capacitor, 10 µF capacitor (1 unit)0.001 µF capacitor, 0.01 µF capacitor, 100 µF capacitor (2 units)LM7805 (+5V IC Voltage Regulator)


33AT8951 (Microcontroller)NE555 (Timer)LM393 (comparator amplifier)8 pin IC socket (2 units), 16 pin IC socket ( 1 unit), 40 pin IC socket(1 unit)1 Ampere diode, LED, PNP transistor, NPN transistor, 12 MHzcrystal resonator, 40 kHz ultrasonic transmitter and receiver, buzzer,LCD Module, switches and 8 way DIP switch.


CHAPTER 6SYSTEM IMPLEMENTATION6.1 Factors Affecting The Performance Of Ultrasonic SensorsPosition/distance measurement using ultrasonic sensors is based on theprinciple of measuring the time of flight of the ultrasonic waves in a particularmedium. There are number of factors which affect the accuracy of measurement andtherefore should be taken into consideration while designing the ultrasonic sensingsystem. The following are some of the factors.


356.1.1 Radiation PatternAll ultrasonic sensors have their specific radiation pattern associated with it.Thisacoustic radiation pattern is a function of spatial angle called beam angle. Beamangle, Ωis defined as the total angle between the points at which the sound powerreduces to half its peak value, commonly known as 3 dB points. The spot diameter ofthe beam can be formulated as :D = 2R tan (0.5 Ω)D = spot diameter in centimeters.R = target range in centimeters.Ω = beam angle in degrees.At minimum range, R = 50 cm and Ω = 30º.D = 2 * 50 * tan (15º) = 26.795 cm.At maximum range, R = 400 cm and Ω = 30º.D = 2 * 400 * tan (15º) = 214.359 cm.Radiation pattern consists of a main lobe and side lobes. Radiation power isdominant mainly in the front region of the sensor, so as to say that the main lobe isdirectly in front of the sensor, followed by side lobes sidewise with null region inbetween these lobes. Radiation pattern is mainly determined by factors such as thefrequency of operation and the size, shape and acoustic phase characteristics of thevibrating surface. The beam pattern of the transducer is independent of its nature as atransmitter or receiver.


36In most of the application, side lobes are suppressed and narrow beams areused. This suppression is achieved by the processing system and so, the radiationpattern of the transducer may not be same as the radiation pattern of the wholeultrasonic sensing system.The narrowness of the beam pattern is a function of thediameter of the radiating surface to the wavelength of the sound at the operatingfrequency. As the D/λ ratio increases, beam narrows out whereas as D/λ ratiodecreases, beam broadens. For most of the application narrow beam is desired andtherefore D/λ ratio should be more.Signal processing is actually the board itself. Theboard still in the designing process. The board will go through few functionalityprocess with various signal. After the board pass the wired testing then it will beintegrate with wireless radio module. Again the board will go through fewfunctionality process with various type of signal.Figure 6.1: Geometric approximation of the ultrasonic beam width.


37Figure 6.2: Beam pattern with respect to amplitude.6.2 Environmental FactorsThe attenuation of sound power depends on the speed of sound, whichdepends on many environmental factors like temperature, medium, pressure,humidity, acoustic interference, radio frequency interference.6.2.1 TemperatureThe velocity of sound in a medium varies with temperature. So, the timetaken by the sound to echo back to the receiver will vary and since this time of flightis proportional to the measured distance. The measured distance will vary with thevariation in temperature. Thus the variation in temperature introduces errors in themeasurement.


38The sound wave propagation speed in the air depends on the temperature. So,to measure the distance more correctly, it is necessary to revise according to thetemperature.The sound wave propagation speed can be calculated using one of thetwo formulas :V = 331.5 + 0.6 * T[ m/sec ]T : The temperature (°C)Temperature (°C) inairSpeed of sound (m/sec)-10 325.50 331.510 337.520 343.530 349.540 355.550 361.5Table 6.1:The speed of sound at different temperature.In this project,the speed of sound used in this program is 340m/s because thisspeed is relative to the temperature 20 ºC which is an average value. A temperaturesensor could be added to this project with a small manipulation to the program, inorder to use the right speed value. In this way, this device would be used in allatmospheric conditions.


396.2.2 Pressure And HumidityAs the pressure reduces, the density of particle in the medium decreases thusproviding less and less resistance to the traveling wave. Although slightly pressureeffects the velocity of sound wave, humidity which is defined as the moisturecontent in the medium basically has a very little effect on the velocity of sound but itactually effect the radiating surface.The acoustic pressure p must satisfy the threedimensionalwave equation.6.2.3 MediumVelocity of sound depends on the kind of medium the sound travels. Soundspeed varies with different medium. The Table 6.2 summarizes some of the mediumwith the sound velocity in it.


40Medium Speed, m/s at 10°CAir 331.5Ammonia 414.8Argon 301.9Carbon Dioxide257.8 (low frequency)Carbon Disulfide 184.7Carbon Monoxide 337.1Chlorine 205.4Ethylene 313.9Helium 969.8Hydrogen 1269.4Illuminating Gas 490.4Methane 431.9Neon 434.9Nitric Oxide 324.9Nitrogen 334.06Nitrous Oxide 261.8Oxygen 317.2Table6.2 :The ultrasonic wave speed through different mediums


416.3 NoiseThe output of the sensor involves noise, which is primarily introducedbecause of the uncertainty of the echo which might comes back from the falseobject/target. Also the attenuation of the sonic burst depends on the position of theobject/target in the lobe region.6.4 ErrorsIn general it is desired to develop the worst case analysis to permit the designof the hand-held ultrasonic range meter device capable of operation under allconditions with a minimum error (maximum acceptable error is +/- 3 cm). The errorsassociated with both calculations and measurements can be characterized with regardto their accuracy and precision as shown in Figure 6.3 Accuracy refers to howclosely a computed or measured value agrees with the true value. Precision refers tohow closely individual computed or measured values agree with each other.


42Figure 6.3: (a) The samples are inaccurate and imprecise. (b) The samplesare accurate and imprecise. (c) The samples are inaccurate andprecise. (d) The samples should be accurate and precise in orderto get the acceptable error.


CHAPTER 7TESTING AND RESULTS7.1 System TestingThis experiment was done at a 17 ºC and that increased the error. It consistedof measuring the distance from the device to a flat wall. Nine measurements weredone in this experiment.% Error = [ (Estimate - Actual) / Actual ] X 100%% error = [ ( 50+ 75+ 100 + 150 + 200 + 250 + 300 + 350 + 400 ) – ( 53 + 77 + 103+ 153 + 204 + 255 + 307 + 355 + 403 ) / ( 50+ 75+ 100 + 150 + 200 + 250 + 300 +350 + 400 ) ] x 100 %% error = [ (1875- 1910) / 1875] x 100 %% error = 1.87 %


44Real measurementsin cmDevice measurementsin cmError in cm50 53 +375 77 +3100 103 +3150 153 +3200 204 +4250 255 +5300 307 +7350 355 +5400 403 +3Table 7.1:Distance measurement with its error.


45There are also some figures that i have taken from the demonstration that Ihave done before. It shows the distance displayed at the LCD module.Figure 7.1 :Atmega ultrasonic range finder is calculating the distance from the sensorto the black box.Figure 7.2 : The distance from the sensor to the black box is 53 cm.


46If we refer back to Figure 7.1 and Figure 7.2,we can see that there is a longruler and short ruler. For a long ruler, its length is 30 cm while the short ruler’slength is 15 cm. We add for both ruler’s length and it is qual to 45 cm. There is somegap between the sensor and the end of short ruler, which means the distancedisplayed at the LCD Module is near to the actual length.From the demonstration and testing value before, this AT89S51 UltrasonicRange Finder measure the range of distance from 0.5 m to 4 m with percentage errorof 1.87 %. For the range below than 0.5 m, this AT89S51 Ultrasonic Range Finderwill display no reading value and the buzzer will keep beeping and calculating forthe next distance of any obstacle.A test to measure a distance which is more than 4 m also have beenconducted, but this AT89S51 Ultrasonic Range Finder gives high percentage of errorand sometimes the LCD Module will turn off due to over limit calculation inside thecircuit.


CHAPTER 8CONCLUSION8.1 Concluding RemarkDuring the process of designing and implementing the AT89S51 UltrasonicRange Finder, we can see that there were some criteriasthat very important..Understanding the concept of the project and discipline were the most importantpart, besides dividing the project into several parts related to each other, managingthe time of completing the project. Each specific part and work need to be doneaccording to the planin Chapter 4 and in the end all the work was combined into awhole working project.From the result in Chapter 7, this AT89S51 Ultrasonic Range Finder haveachieved the objectives of this project. Eventhough it gives some errors, it can beconsider as a useful device. There are some limitation that i have found during thetesting of this project. This AT89S51 Ultrasonic Range Finder will gives accuratereading of a distance if the obstacle is in black colour. The worst reading that thisAT89S51 Ultrasonic Range Finder gives is for any obstacles which are in white andtransparent such as binding cover and Tupperware.


48The importance of the project is calculating accurate distance from anyobstacle that we want to measure. The device can be used in many different fieldsand categories like distance calculation in construction field, robots, car sensor toavoid obstacles and many other applications. The building process of the devicewas based on using as much as possible from the courses taken in the university, likeMicro Processor, Basic Electrical Engineering, Multimedia and systems andElectronics Devices and also practical work in the laboratories.


48REFERENCES1. An Ultrasonic Range Finder Designed for an Autonomous VehicleNavigation System - by JiqiuSai2. Robotic Exploration and Landmark Determination: Hardware-Efficient Algorithms and FPGA Implementations – byK. Sridharan, Panakala Rajesh Kumar3. http://www.zembedded.com/interfacing-ultrasonic-rangefinder-with-avr-mcus-avr-4. http://www.parallax.com/tabid/768/productid/92/default.aspx5. http://www.futurlec.com/AT89LP4052_Controller.shtml


49APPENDIX AC LANGUAGE FOR <strong>ATMEGA</strong> <strong>ULTRASONIC</strong> <strong>RANGE</strong> <strong>FINDER</strong>#include #include #include #define lcd_port PORTD#define LCD_EN 0x80#define LCD_RS 0x20unsignedint count, dist, temp, t; //count the number of40kHz pulses, 1 pulse=2count--------------------------------------------------------------void command (char cmd){DDRD = 0XFF;lcd_port = ((cmd>> 4) &amp; 0x0F)|LCD_EN;lcd_Port = ((cmd>> 4) &amp; 0x0F;_delay_ms(1);lcd_port = (cmd&amp; 0x0F)|LCD_EN;lcd_port = (cmd&amp; 0x0F);}_delay_ms(1);


50--------------------------------------------------------------voiddatawr (char dat){lcd_port = (((dat>> 4) &amp; 0x0F)|LCD_EN|LCD_RS);lcd_port = (((dat>> 4) &amp; 0x0F)|LCD_RS);_delay_ms(1);lcd_port = ((dat&amp; 0x0F)|LCD_EN|LCD_RS);lcd_port = ((dat&amp; 0x0F)|LCD_RS);_delay_ms(5);}--------------------------------------------------------------voidlcd_reset(void){DDRD = 0XFF;_delay_ms(1);lcd_port = 0x03+LCD_EN;lcd_port = 0x03;_delay_ms(1);lcd_port = 0x03+LCD_EN;lcd_port = 0x03;_delay_ms(1);lcd_port = 0x03+LCD_EN;lcd_port = 0x03;_delay_ms(1);lcd_port= 0x02+LCD_EN;lcd_port = 0x02;_delay_ms(1);}--------------------------------------------------------------voidlcd_init (void)


51{lcd_reset();int j=0;charb[]={0x28,0x0C,0x06,0x80,’\0’;while (b[j]!=’\0){command(b[j]);_delay_ms(1);j++;}}--------------------------------------------------------------ISR(TIMER2_COMP_vect){if ((count


52//x++;}--------------------------------------------------------------int main(void){count=0;DDRD= 0XFF;lcd_init();unsigned char string[] = “Distance’;for(int i=0; i


53{if ((PINB&amp; 0x02) &amp;&amp; (count>=4))//if pulse is receivedafter sending 2 pulsest = 4;temp= TCNT1;dist=(int)((double)((temp*0.0000125*34000))/2);//calculate thedistance in cm andspeed of sound is340 m/stemp=dist;while (t!=0)//print the distancein four digits fromright to the lefton lcd{datawr((temp%10) + 0x30);temp = temp/10;t--;}count = 0;}if(TCNT1 > 20000)//if signal does notreceived, reset thecount and send pulseagain about 1.2ms{TCNT1 = 0;


54}}}count = 0;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!