Sunteți pe pagina 1din 3

TEST&MEASUREMENT

Distance Measurement
using Infrared
with a new proximity sensor module
In the form of the GP2D02, Sharp have produced a sensor which, with
the aid of a microcontroller, can provide reasonably accurate measure-
ments of distances in the range 10 to 80 cm.

reported as an 8 bit value output seri- over an interface, whereupon it can


ally on a single pin, which can be be processed further.
subsequently processed in software.
The sensor includes an infrared
transmitter diode along with a suit- Reading the distance
able receiver and processing elec- information
tronics. The component is so The sensor is read by taking the
designed that ambient light and the input signal Vin low for at least
colour and reflective properties of the 70 ms. During this period the
object being detected have practi- infrared transmitter diode emits 16
cally no effect on the measurement bursts. The internal logic calculates
results. the average of the 16 digital distance
measurements taken, thereby reduc-
ing the effect of measurement errors.
Operation of the GP2D02 Vin is then clocked eight times
The heart of the sensor, whose inter- and on each falling edge one bit of
nal circuit is shown in Figure 1, is a the digital value representing the
PSD (position sensitive device), set distance to the target object can be
behind an optical lens. The mea- read from pin Vout by the microcon-
surement method uses the triangu- troller. The sensor must always be
lation principle. Using precision supplied with an external clock, and
optics, the transmitter is made to therefore cannot work without some
emit a highly focussed beam of light external ‘intelligence’. Figure 3
which is reflected from the target shows the timing diagram for opera-
object. The angle of the reflected tion of the device. The relationship
beam varies with the distance between the actual distance and the
between sensor and target object digital value is not linear. The reso-
(Figure 2). lution is around 1 cm, and falls to
At the receiver the light passes around 10 cm with increasing dis-
through a further lens, which focuses tance. The non-linearity is a conse-
the beam to a point on a photosensi- quence of the optical method used
tive device. As the distance between and of the relatively small distance
target object and sensor changes, so between the transmitter and the
the focussed point of light moves receiver in the sensor enclosure. Fig-
Originally developed for use as a proximity along the photodetector. The posi- ure 4 shows an example of the rela-
switch in sanitary ware, this sensor is also tion-dependent output signal from tionship between the measured
ideal for detecting objects in robotics applica- the photodetector is amplified, digi- value (shown converted into deci-
tions or as a parking aid. The distance is tised, processed and then sent out mal) and the actual distance. The

88 Elektor Electronics 7-8/2002


TEST&MEASUREMENT
GND VCC cuitry. Above about 80 cm the curve becomes
1 3 so flat that it is practically impossible to
VCC obtain a distance measurement. It is impor-
Reg tant to note that this curve only holds good
VCC for an object with particular reflective char-
acteristics: different materials exhibit differ-
12kΩ
Signal ent relationships between output value and
processing distance.

Control circuit
circuit The sensor is available in various alterna-
4 VOUT
Light detector tive versions. Here we will just mention the
GP2D05, which has the facility for setting a
LED drive threshold distance to the target object using
circuit 2 VIN a potentiometer. This device operates with-
(Control
IR LED signal out an external clock and requires only a trig-
input)
Reflective VCC ger signal to initiate a measurement cycle.
object
This simplifies the electronics, but does not
020010- 11 allow us to measure actual distances.
Although the GP2D02 is specified for a
Figure 1. Internal circuit block diagram of the Sharp GP2D02. supply voltage of 4.4 V to 7 V, the voltage at
the Vin pin should not be allowed to exceed
3 V. As can be seen from the circuit diagram
distance 2 object in Figure 5, this can be prevented by fitting
a protection diode. In the example circuit the
distance to the target object is measured con-
tinuously. The measured value from the
distance 1 GP2D02 is shown as a three-digit decimal
value on the display. In addition, pin P1.2 of
microcontroller IC1 is connected to a buzzer
(with integrated oscillator) which is turned
on when an object comes closer than a dis-
tance set via P2.0 and P2.1. The settings are
Sender
as follows:
PSD
P2.0 P2.1 Threshold value
H H > 219
displacement L H > 209
020010 - 12 H L > 199
L L > 179
Figure 2. Measuring distance by triangulation. Pins P2.0 and P2.1 are fitted with internal
pull-up resistors, so for a threshold value of
219 no external connections are necessary. Of
interesting parts of the curve are the case the output value starts to rise course, the switched output could be used to
regions below about 10 cm and with decreasing distance, which can operate a relay (with flyback diode!) in order
above around 80 cm. In the former confuse subsequent processing cir- to switch other equipment. P1.2 is an active-
low open drain output.

0.2 ms or less 1.5 ms or more 1.5 ms or more Display module


70 ms or more 1 ms or more
Power OFF
IC3 is a highly-integrated LED display sys-
Vin
tem, which, in a very small area and without
additional circuitry, allows 128 different char-
acters to be shown. In a space just 20 mm by
10 mm by 5 mm, this tiny display includes a
ROM, a multiplexer and a driver for the indi-
vidual LEDs of the 5-by-7 matrix that forms
each character. In total four characters can be
displayed and separately addressed. The rel-
Output
evant character position is addressed using
MSB LSB LSB pins A0 and A1, while the data, presented on
Example of distance measuring output (8-bit) 020010 - 13
pins D0 to D6, are written in by taking the
WR pin low. A low level on the CLR pin clears
Figure 3. Timing diagram for reading the digital distance value. the internal RAM (which is not used in this

7-8/2002 Elektor Electronics 89


TEST&MEASUREMENT
application). The display can be dimmed by 250
applying a squarewave signal to the BL pin.
It is also possible to cascade display mod-
ules, connecting all the pins (except WR) in 200
parallel.

Programmed microcontroller 150

output
Thanks to its architecture and simple pro-
gramming, the Philips microcontroller is ideal
100
for this system. It includes 2 k of ROM,
128 bytes of RAM, two 16 bit timer/counters
50

0
0 20 40 60 80 100
distance [cm] 020010 - 14

Figure 4. Relationship between digital output value and distance.

is read as specified in its data sheet. to ground, turning on the connected


After a specified delay the Vin pin is buzzer.
clocked eight times and a bit is read In the Display (‘Anzeige’) subrou-
on each falling edge, MSB first. The tine, the measured value is first con-
GP2D02 enters a quiescent mode verted from hexadecimal form into
when Vin remains high for more than decimal. The SLR2016 intelligent dis-
1.5 ms. play module is driven by presenting
In the Threshold (‘Grenzwert’) the appropriate data on D0 to D6 and
subroutine, the measured value is corresponding addresses on A0 and
tested to determine whether it A1. On the falling edge of WR the data
exceeds the value set on pins P2.0 are transferred and then displayed.
and P2.1. If so, output P1.2 is taken (020010-1)

+5V

Bz1
C1

100µ 16V

15
LD1
VOUT 2 1
P1.7 P0.0 D0 BL CLR
IC2 D1 3 20 Display
P1.6 IC1 P0.1 D1
VIN 4 19
GP2DO2 P1.5 P0.2 D2
1N4148 8 18
P1.4 P0.3 D3
9 87LPC762 17
P1.3 P0.4 D4
along with other internal circuitry which is 10 16
P1.2 P0.5 D5
not used in this application. It is worth not- 11
P1.1 P0.6
14
D6 A0 A1 WR
ing that the (RC) clock oscillator and the reset 12
P1.0 P0.7
13

circuit are fully integrated into the device and SLR2016


X1 X2
* zie tekst
no external circuitry is required. 5 6 7
* see text

The software, which may be obtained on * * voir texte

floppy disk or as Free Download from our * siehe Text


website, is relatively straightforward. After
initialising the microcontroller, including
clearing the 128 bytes of RAM, the main pro- 020010 - 15
gram begins. Three subroutines are executed
in a continuous loop.
In the Sensor routine, the distance sensor Figure 5. Circuit diagram of the distance measuring system.

90 Elektor Electronics 7-8/2002

S-ar putea să vă placă și