living with the lab PING Ultrasonic Distance Sensor

living with the lab PING))) Ultrasonic Distance Sensor The PING))) sensor emits short bursts of sound and listens for this sound to echo off of nearby objects. The frequency of the sound is too high for humans to hear (it is ultrasonic). The PING))) sensor measures the time of flight of the sound burst. A user then computes the distance to an object using this time of flight and the speed of sound (1, 126 ft/s). s wave e r u s s ic pre speaker n o s a )) ultr PING) m o r f t and c e j b o off eflects icrophone” r e v a w sound to PING))) “m returns

living with the lab Computing Distance 2

living with the lab Specifications • • • measurement range: 0. 8 in to 120 inches supply voltage: 5 V supply current: 30 m. A sensing distance (feet) as a function of angle www. parallax. com/Portals/0/Downloads/docs/prod/acc/28015 -PING-v 1. 6. pdf 3

POWER 0 1 2 3 4 5 RESET 3 V 3 5 V GND Vin AREF GND 13 12 PMW 11 PMW 10 PMW 9 8 7 PMW 6 PMW 5 4 PMW 3 2 TX 1 RX 0 living with the lab Connection to an Arduino DIGITAL Arduino ANALOG 4

living with the lab Arduino Sketch • • • The Arduino triggers the PING))) by sending a 5 ms pulse to the sensor through pin 7, which is initially configured as an Arduino OUTPUT. Immediately after sending this pulse, pin 7 is switched to an INPUT. When the PING))) receives the 5 ms pulse from the Arduino, it sends a 40 k. Hz (ultrasonic) burst of sound out its “speaker” and sets pin 7 to HIGH. The PING))) then waits for the sound burst to reflect off of something and return to the “microphone” where it is detected; the PING))) then sets pin 7 to LOW. The Arduino uses the pulse. In command to measure the time of flight of the sound wave in microseconds (the time that pin 7, when configured as an input, is HIGH). The “time of flight” of the sound wave in ms is stored in the variable “duration. ” void setup() { Serial. begin(9600); } void loop() { long duration, inches; pin. Mode(7, OUTPUT); // send a 5 microsecond pulse out pin 7 digital. Write(7, LOW); delay. Microseconds(2); digital. Write(7, HIGH); delay. Microseconds(5); digital. Write(7, LOW); pin. Mode(7, INPUT); // make pin 7 an input duration = pulse. In(7, HIGH); // measure the time of flight of sound wave inches = duration / 74 / 2; // 1130 ft/s * 12 in/ft * 1 s/1, 000 us = 74 // factor of 2 since sound travels out and back Serial. print(inches); // display distance in inches Serial. print("in "); Serial. println(); } 5

living with the lab Example Application The picture shows how stiff wire (such as a coat hanger) can be used to mount the PING))) to an aluminum plate. An Arduino and breadboard are also mounted to the plate, and a piezospeaker is installed on the breadboard to allow the device to output an irritating noise whose frequency is proportional to the distance from the PING))) to a target. void setup() {pin. Mode(8, OUTPUT); } void loop() { long duration, inches, tone_freq ; pin. Mode(7, OUTPUT); // make pin 7 an output digital. Write(7, LOW); // send wakeup pulse delay. Microseconds(2); digital. Write(7, HIGH); delay. Microseconds(5); digital. Write(7, LOW); pin. Mode(7, INPUT); // make pin 7 an input duration = pulse. In(7, HIGH); // time of flight of wave inches = duration / 74 / 2; // compute distance in inches tone_freq = inches*100; // a freq of 100*inches is good tone(8, tone_freq); // send a tone out of pin 8 } 6
- Slides: 6