Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ultrasonic Distance Sensor

Similar presentations


Presentation on theme: "Ultrasonic Distance Sensor"— Presentation transcript:

1 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). ultrasonic pressure waves from PING))) speaker sound wave reflects off object and returns to PING))) “microphone”

2 Computing Distance

3 Specifications Working Voltage : 5V(DC) Working Current : max 15 ma
Working frequency : 40HZ Output Signal : 0-5V (Output high when obstacle in range) Sentry Angle : max 15 degree Sentry Distance : 2cm - 500cm High-accuracy : 0.3cm sensing distance (feet) as a function of angle

4 Interface with Arduino

5 Arduino Connection to an Arduino DIGITAL ANALOG POWER
AREF GND PMW 11 PMW 10 PMW PMW 6 PMW PMW TX 1 RX 0 RESET 3V3 5V GND GND Vin DIGITAL ANALOG POWER Arduino

6 Arduino Sketch The Arduino triggers the PING))) by sending a 5ms 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 5ms pulse from the Arduino, it sends a 40kHz (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 pulseIn 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; pinMode(7, OUTPUT); // send a 5 microsecond pulse out pin 7 digitalWrite(7, LOW); delayMicroseconds(2); digitalWrite(7, HIGH); delayMicroseconds(5); digitalWrite(7, LOW); pinMode(7, INPUT); // make pin 7 an input duration = pulseIn(7, HIGH); // measure the time of flight of sound wave inches = duration / 74 / 2; // 1130 ft/s * 12in/ft * 1s/1,000,000us = // factor of 2 since sound travels out and back Serial.print(inches); // display distance in inches Serial.print("in "); Serial.println(); }

7 Arduino Programming The Arduino triggers the PING))) by sending a 5ms pulse to the sensor through pin 2, which is initially configured as an Arduino OUTPUT. When the PING))) receives the 5ms pulse from the Arduino, it sends a 40kHz (ultrasonic) burst of sound out its “speaker” and sets pin 2 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 3 to LOW. The Arduino uses the pulseIn command to measure the time of flight of the sound wave in microseconds (the time that pin 3, when configured as an input, is HIGH). The “time of flight” of the sound wave in ms is stored in the variable “duration.”

8 Arduino Programming int pingPin = 2 int inPin = 3 long microseconds;
void setup() { Serial.begin(9600); } void loop() { long duration, inches, cm; digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(10); pinMode(pingPin, OUTPUT); pinMode(inPin, INPUT); duration = pulseIn(inPin, HIGH); inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2;

9 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() {pinMode(8, OUTPUT); } void loop() { long duration, inches, tone_freq; pinMode(7, OUTPUT); // make pin 7 an output digitalWrite(7, LOW); // send wakeup pulse delayMicroseconds(2); digitalWrite(7, HIGH); delayMicroseconds(5); digitalWrite(7, LOW); pinMode(7, INPUT); // make pin 7 an input duration = pulseIn(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 }


Download ppt "Ultrasonic Distance Sensor"

Similar presentations


Ads by Google