Page 307 - ARM Based Microcontroller Projects Using MBED
P. 307
10.4 PROJECT 3—ULTRASONIC HEIGHT MEASUREMENT 293
10µs
Trigger
40 kHz
acoustic
burst 8 40 kHz
40kHz
reflected
signal
Output of
ECHO pin
Propagation delay
dependent on distance
FIG. 10.12 Operation of the ultrasonic sensor module.
FIG. 10.13 Circuit diagram of the project.
10.4.5 The PDL
Fig. 10.14 shows the program PDL.
10.4.6 Program Listing
The program listing (program: Height) is shown in Fig. 10.15. At the beginning of the pro-
gram variables trig and echo are assigned to GPIO ports PC_6 and PC_7, respectively, and the
interface between the LCD and the development board are defined. The height of the sensor
(variable H) is set to 2m (200cm). The main program calls function CalculateDistance to cal-
culate the distance between the sensor and the head of the person. This value is then
subtracted from the sensor height to find the height of the person which is then displayed
at column 0, line 0 of the LCD. The program repeats after 1s delay.