1. Objectives

  • Using timers to measure pulse duration

  • Using an ultrasonic sensor to measure distance

  • Using character LCD displays

  • Integrating multiple devices in a small project

2. Parts List

  • LPC1769 LPCXpresso board

  • USB A-Type to Mini-B cable

  • Ping)))™ ultrasonic sensor

  • 16x2 character LCD display

  • 5V power supply

  • Jumper wires

  • Breadboard

3. Background

3.1. Ultrasonic Waves

Ultrasonic waves are sound waves transmitted above the human-detectable frequency range, usually above 20,000 Hz. The term sonic refers to the sound waves of high amplitudes. These waves can be used in medical diagnostics. They can also be used in the oil industrial to know the exact borehole where a hole needs to be dug to extract oil or natural gas. Even though humans cannot detect such waves, some animals can detect them, such as dogs, or even use them such as bats. Ultrasonic Waves

3.2. Ultrasonic Sensors

Ping))) Ultrasonic Sensor
Figure 1. Ping))) Ultrasonic Sensor

Ultrasonic sensors are special devices that transmit ultrasonic waves and receive the reflection of the waves after they hit a body. As shown in the Ping))) Ultrasonic Sensor figure, the sensor has two ultrasonic transducers (receiver/transmitter) to get a more accurate reading. Ping))) Ultrasonic sensor uses only a single pin to send and receive data unlike other sensors where they need two pins (one for requesting and one for receiving). This is very helpful because some microcontrollers have a limited number of pins. This ultrasonic sensor can detect distances as low as 2 centimeters and as high as 3 meters.

The signal pin of the Ping))) sensor has two functionalities. The first is to trigger, or request as labeled in the Ping))) Signal Wave Diagram. It can also be refered to as the start pulse. The microcontroller needs to assert a high signal for approximately 2-5 microseconds. Sending the start pulse will make the ultrasonic sensor prepare to send ultrasonic waves. The preparation time is labeled hold off in the diagram, and usually takes 750 microseconds. During the hold off time, the signal pin is set to low by the ultrasonic sensor.

The second function of the signal pin in the Ping))) sensor is the echo, labeled response in the diagram, where the ultrasonic sensor sends the time it took the ultrasoic waves to be transmitted and then received by the sensor after being reflected off a wall or some other object. The high pulse determines the time it took the transmitted signal to get reflected and received. Using this time, we can find the distance of the object off which the signal was reflected.

Please refer to the Ping))) sensor data sheet for more information [ping-ultrasonic-sensor-datasheet].

Ping))) Signal Wave Diagram
Figure 2. Ping))) Signal Wave Diagram

The Ultrasonic Waves figure below shows how the ultrasonic waves propogate from the source to the object and get reflected back to the source.

Ultrasonic Waves
Figure 3. Ultrasonic Waves

4. Tasks

4.1. Read the Response Time of the Echo Wave

Write a program that sends a request (start pulse) to the ultrasonic sensor and then reads the response (echo pulse) time given by the sensor using timer capture pins. Refer back to Experiment 4: Hardware Timers for reviewing timer capture functionality.

  1. Use functions in your program to increase modularity.

  2. Use a global variable to store the response time to make it easier to have a minimal ISR:

    static volatile double elapsed_time;  // holds response (echo) time value

4.2. Calculate the Distance from the Response Time

We learned from physics that:

\$\text{Speed} = \text{Distance} / \text{Time}\$

Since the ultrasonic waves travel at the speed of sound, which is 340.29 m/s, calculate the distance corresponding to the response time received from the sensor.

  1. Remember that the response time is equal to the time it took the waves to propogates from the source, hit an object and then bounce back to the receiver (device).

  2. Use a global variable to store the distance value, similar to what you have done for the response time.

4.3. Show the Distance on the LCD Display

lcd display
Figure 4. LCD 16x2 Display

The 16x2 character LCD display consists of two rows of characters, each of which contains 16 characters. These displays are widely used in embedded systems project to present information to the user of the system.

Show the distance calculated in the previous task in the first row, while showing the status of the alarm buzzer (more on this in the next task) in the second row as shown in the LCD Sample Output figure below. For information on how to use the LCD, refer to the LCD datasheet [lcd-16-2-datasheet].

LCD Sample Output
Figure 5. LCD Sample Output

4.4. Sound an Alarm Using a Buzzer Based on Distance

buzzer
Figure 6. Buzzer

A buzzer is can generate sounds to alert the user. It’s widely used in alarm systems to alarm people for an emergency. One of the applications for ultrasonic sensors is knowing whether there’s an object at some predefined distance or not. Most modern cars have multiple ultrasonic sensors in the back at different angles to notify the driver if he gets very close to the car behind him, or if he is about to hit an object he could not see through the rear-view mirror.

Generate an alarm sound whenever the distance from the ultrasonic sensor to the object is 50 cm or less.

5. Grading Sheet

Task Points

Total

10

Read the response time of the echo wave

4

Calculate the distance from the response time

1

Display the distance on the LCD display

4

Sound the alarm using a buzzer based on distance

1

6. References

[ultrasonic-waves]

Richard E. Berg. 'Ultrasonics'. Encyclopædia Britannica. Retrieved: 2018-3-10.
https://global.britannica.com/science/ultrasonics

[ping-ultrasonic-sensor-datasheet]

Parallax Inc. 'PING))) Ultrasonic Distance Sensor (#28015)'. v2.0 2/4/2013.
https://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdf

[lcd-16-2-datasheet]

Xiamen Amotec Display Co.,Ltd. 'Specifications of LCD Module. Module No: ADM1602K-NSW-FBS/3.3v'. Version 00, 2008-10-29.
https://www.sparkfun.com/datasheets/LCD/ADM1602K-NSW-FBS-3.3v.pdf