Sei sulla pagina 1di 5

ConstruCtion

MICROCONTROLLERULTRASONIC DISTANCE METER BASED


and receiver), current buffer ULN2003, operational amplifier LM324, inverter here are several ways to measCD4049, four 7-segment displays, five ure distance without contact. transistors and some discreet comOne way is to use ultrasonic ponents. The ultrasonic transmitterwaves at 40 kHz for distance measurereceiver pair is shown in Fig. 1. higher pulse excitation voltage or a ment. Ultrasonic transducers measure Ultrasonic generators use piezo- better transducer. the amount of time taken for a pulse electric materials such as zinc or lead Here the microcontroller is used to of sound to travel to a particular surface zirconium tartrates or quartz crystal. generate 40kHz sound pulses. It reads and return as the reflected echo. The material thickness decides the when the echo arrives; it finds the time This circuit calculates the distance resonant frequency when mounted taken in microseconds for to-and-fro based on the speed of sound at 25Cand excited by electrodes attached on travel of sound waves. Using velocity ambient temperature and shows it either side of it. The medical scanners 333 m/s, it does the calculations and of on a 7-segment display. Using it, used for abdomen or heart ultrasound ParTs LisT you can measure distance up to 2.5 are designed at 2.5 MHz. In this cirmetres. cuit, a 40kHz transducer is used for Semiconductor For this particular application, themeasurement in the air medium. The s: IC1 - AT89C205 m 1 icrocontroll required components are AT89C2051 velocity of sound in the air is around - er ULN2003 current microcontroller, two 40kHz ultrasonic330 m/s at 0C and varies with tem- IC2 IC3 - buffer hex CD4049 transducers (one each for transmitter buffer perature. inverting IC4 - LM324 quad In this project, you excite the ulamplifier operational trasonic transmitter unit with a 40kHzIC5 - 7815, 15V IC6 - regulator 7915, -15V pulse burst and expect an echo from IC7 - regulator 7805, 5V the object whose distance you want to T1- regulator BC557 pnp T - transistor 2N2222 npn T4 measure. Fig. 2 shows the transmitted D1, - transistor 1N4148 switching 5 burst, which lasts for a period of apD3-D6 - diode 1N4007 rectifier D2 DIS1-DIS4 - LTS proximately 0.5 ms. It travels to the diode 542 common7-segment anode, object in the air and the echo signal display Resistors (all -watt, % is picked up by another ultrasonic R1, - 2-megacarbon): R3 - ohm 82-kiloFig. 1: Ultrasonic transmitter and receiver pair transducer unit (receiver), also a 40 R2 - 10-kiloohm kHz pre-tuned unit. The re- R4, R7R5 - 33-kiloR10 ohm ceived signal, which is R6 - ohm 100-kilo- ohm 1-kilovery is amplified several R1 weak, R12- ohm 1.2-kilo1 times in the receiver circuit R15 R1 - ohm 220RNW - ohm 10-kilo-ohm and appears somewhat as 6 networ 1 resistor shown in Fig. 2 when seen VR1 - k 1-kilo-ohm preset on a CRO. Capacitors C - 3.3nF ceramic Weak echoes also occur : 1, C2 C7, C10-C12 - disk ceramic 0.1F due to the signals being C3 - disk ceramic 2.2nF C4 - disk 16V 10F, directly received through C5, C6 - electrolytic 22pF ceramic the side lobes. These are C8, C9 - disk 1000F, 50V ignored as the real echo Miscellaneou electrolytic X - 230V AC primary received alone would give s: 15V-0-15V, to the correct distance. That 1 secondary 500mA is why we should have a XTAL - transformer 12MHz S1 - Push-to-on crystal level control. Of course, S2 - switch On/off the signal gets weaker if TX - switch 40kHz transmitte 1 ultrasonic the target is farther than RX - r 40kHz ultrasonic 2.5 metres and will need a 1 Fig. 2: The ultrasonic pulse, echo signal and time measurement receiver
K.

PADMANABHAN

68 f e B r uA r y 2w . 0 8 y m a e . c o m n i c s f o r yo ww 0 eF el gctro u

ConstruCtion
shows on the four 7-segment displays the distance in centimetres and millimetres (three digits for centimetres and one for millimetres).

Circuit descriptio Fig. 3 shows the n

Fig. 4: Two dimensional beam pattern of ultrasonic signal showing main lobe and side lobe energy levels

a ferrite-core step-Microcontroller based distance meter circuit Fig. 3:


70 f e B r uA r y 2w . 0 8 y m a e . c o m n i c s f o r yo ww 0 eF el gctro u

circuit of the microcontroller-based up pulse transformer, which steps-up distance meter. The the transmitter output to 60V (peak40kHz pulse bursts to-peak). from the microconThe echo signal received by the troller are ampli- receiver sensor after reflection is very fied by transistor weak. It is amplified by quad operaT5. Inverting tional amplifier LM324. The first stage buffer CD4049 drives (A1) is a buffer with unity gain. The the ultrasonic sen- received signal is directly fed to the sor used as the non-inverting input (pin 3) of A1 and transmitter. Three coupled to the second stage by a 3.3nF inverters (N1, N2 (small-value) capacitor. If you use and N3) are con- the ubiquitous 0.01F capacitor for nected in paralcoupling, there will be enormous hum lel to increase the at the output. The second stage of the transmited power. inverting amplifier uses a 2-mega-ohm This inverted out- resistor for feedback. The third stage put is fed to anis a precision rectifier amplifier with a other set of three gain of 10. inverters (N4, N5 The rectifier functions, unlike a and N6). Outputs simple diode, even for signal voltage of both sets of par- of less than 0.6V. The output is filtered allel inverters are to accept 40kHz frequencies and fed to applied as a push- pin 12 of microcontroller AT89C2051, pull drive to the which is an analogue comparator. Pin ultrasonic trans13 is the other pin of the comparator mitter. used for level adjustment using preset The positiveVR1. going pulse is apThe ultrasonic transducer outputs plied to one of the a beam of sound waves, which has terminals of the more energy on the main lobe and less ultrasonic sensor energy (60 dB below the main lobe) on and the same pulsethe side lobes as shown in Fig. 4. Even after 180-degree this low side-lobe signal is directly phase shift is ap- picked up by the receiver unit. So plied to another you have to space the transmitter and terminal. Thus the receiver units about 5 cm apart. The transmitter power two units are fixed by cellotape onto a is increased for in- cardboard, with the analogue circuit creasing the range. at one end. If you want to Microcontroller AT89C2051 is at increase the range the heart of the circuit. Port-1 pins P1.7 up to 5 metres, usethrough P1.2, and port-3 pin P3.7 are connected to input pins 1 through 7 of

ConstruCtion
Using switch S1 you can manually reset the microcontroller, while the power- signal for on reset the microcontroller is derived from the combination of capacitor C4 and resistor R8. A 12MHz crystal is used to generate the basic clock frequency for the microcontroller. Resistor R16 connected to pin 5 of Fig. 5: Power supply circuit for distance meter DIS2 enables the decimal point. The comparator is inbuilt in microcontroller AT89C2051. The echo signal will make port-3 pin 3.6 low when it goes above the level of voltage set on pin 13. This status is sensed by the microcontroller as programmed. When port-3 pin P3.6 goes high, we know that the echo signal has arrived; the timer is read and the 16-bit number is divided by twice the velocity of sound and then converted into decimal format as a 4-digit number. Power supply. Fig. 5 shows the circuit of the power supply. The 230V AC mains is stepped down by transformer X1 to deliver the secondary output of 15V-0-15V, 500 mA. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D3 through D6, filtered by capacitors C8 and C9 and then regulated by ICs 7815 (IC5), 7915 (IC6) and 7805 (IC7). Regulators 7815, 7915 Fig. 6: Actual-size, single-side PCB for the microcontroller-based ultrasonic distance meter and 7805 provide +15V, -15V and + regulated supply, respectively. 5V IC2 (IC ULN2003), respectively. These display DIS1. Similarly, transistors T2Capacitors C10 through C12 bypass pins are pulled up with a 10-kilo-ohmthrough T4 provide anode currents to the ripples present in the regulated resistor network RNW1. They drive the other three 7-segment displays. power supply. all segments of the 7-segment display Microcontroller IC1 provides the the Construction and testing with the help of inverting buffer segment data and display-enable sigIC2. ort-3 pins P3.0 through P3.3 of nal simultaneously in time-division An actual-size, single-side PCB for the P the microcontroller are connected multiplexed mode for displaying a microcontroller-based distance meter to the base of transistors T1 through particular number on the 7-segment is shown in Fig. 6 and its component T4 to provide the supply to displays display unit. layout in Fig. 7. DIS1 through DIS4, respectively. Pin Segment data and display-enable Assemble the PCB and put the P3.0 of microcontroller IC1 goes low pulse for the display are refreshed eveprogrammed microcontroller into the to drive transistor T1 into saturation, ry 5 ms. Thus the display appears to socket. After switching on the power be which provides supply to the com- continuous, even though the individual supply and microcontroller automatimon-anode pin (either pin 3 or 8)cally getting reset upon power-on, by one. of LEDs used in it light up one
72 f e B r uA r y 2w . 0 8 y m a e . c o m n i c s f o r yo ww 0 eF el gctro u

ConstruCtion
the level of reference voltage set on pin 13, it will make P3.6 low; the arrival of echo is sensed by the program using jnb p3.6 (jump not bit) instruction.

Software
The software is written in Assembly language and assembled using 8051 cross-assembler. It is well commented and easy to understand. The pulse train for 0.5 ms is started by making pin 8 high and low alternately for 12.5 microseconds so that the pulse frequency is 40 kHz. After 25 such pulses have passed, a waiting time is given to avoid direct echoes for about 20 s. Then the signal is awaited, while the timer runs counting time in microseconds. When the echo arrives, port-3 pin P3.6 goes high, the timer reads and the 16-bit number is divided by twice the velocity and converted into decimal format as a 4-digit number. If the echo does not arrive even after 48 milliseconds, the waiting loop Fig. 7: Component layout for the PCB is broken and the pulse train sequence is pin 8 will pulse at 40kHz bursts. This observe the echo signal. It will appear started once again. If the echo comes within this time, it is displayed for can be seen using an oscilloscope. as shown in Fig. 2. a second before proceeding to another Give this signal to channel 1 of the The two transducers can be fixed half measurement. Thus, the display aposcilloscope. Adjust the time base to to a thick cardboard with two wires pears continuous and flicker-free. 2 ms per division and set it to trigger leading to the circuittwo 40cm long mode instead of normal mode. Adjust shielded cables will do. The laser the potmeter on the oscilloscope la- pointer is fixed such that it is axial Other uses Simply by changing this program, the beled level such that the trace starts the transducers. Channel 2 is conto same unit can be made to detect movwith the burst and appears steady asnected to pin 12, which is the positive ing shown in Fig. 2. non-inverting terminal of AT89C2051s objects (such as cars racing on the street) and find their range and speed. Connect the transmitter and re- comparator. The negative inverting terIt ceiver ultrasonic units either by a minal (pin 13) is connected to a preset can also be used with suitable additional software as a burglar alarm unit twisted pair of wire or by a shielded reference. Adjust the preset such that for cable to the board. Give the receivedvoltage is 0.1V-0.2V at pin 13. This homes or offices. the EFY note. $OO WKH UHOHYDQW OHV RI signal to channel 2 of the oscilloscope. enable detection of weak echoes will this project are included in this months Then, place an A4-size plastic sheet in also. EFY-CD. front of the ultrasonic transducers and When the echo signal goes above

Program listing: $mod5 1 ORG 0H AJMP 30H ORG 0BH ;TIMER 0 INTERRUPT VECTOR ; AJMP TIMER0ISR ;Timer 0 Interrupt service routine address ORG 30H SP,#60H ;set stack MOV pointer MOV P3,#0FFH ;set all port 3 bits high to enable inputs also P1,#03 ;set port 1 to all MOV zeros expect bits 0,1

MOV TMOD,#01100001B ;TIMER 1 MODE 2 COUNTER,TIMR-0 TO MODE 1 BEG: MOV TH0,#0H ;TIMER REG.0 IS SET TO GIVES 0, 64ms TL0,#0 ; timer low reg. is also MOV so ;TOTAL CYCLE TIME IS 64.6ms , 350m/s gives 0.35mx65=22.5m 10 metres say! .35 ; up and down m/ms, .35 mm/us, 1mm per 3 microsand down .35/2 mm/us = 1/6 ; up mm/us ; VELOCITY OF SOUND IN AIR IS 350 M/S ; AFTER 100 TIMES, WE HAVE TO STOP TRANSMITTING FOR A TIME OF ABOUT . 1 S

ultrsnd.as m

; SO WE STOP FOR THIS AMOUNT OF TIME and expect an echo. r2,#25 ; 25 pulses 26 us =.53 mov ms (343m/s*.5ms=17c m) pulse: setb p3.4 ;generates 40KHz mov r1,#5 djnz r1,$ clr p3.4 mov r1,#5 djnz r1,$ ;wait for 13 us djnz r2, pulse ; 20pulses ;start timer setb tr0

www.eFymag.com

e l e c t r o n i c s f o r yo u f e B r uA r y 2 0 0 8 7 3

Potrebbero piacerti anche