Download presentation
Presentation is loading. Please wait.
Published byQuentin Warren Modified over 9 years ago
1
1 Ultrasonic Distance Sensor
2
2 How it Works The distance sensor emits short bursts of sound and listens for this sound to echo off of nearby objects The sensor measures the time of flight of the sound burst. A user then computes the distance to an object using this time of flight
3
3 When it won’t work When the sound waves are not reflected back towards the sensor
4
4 An ultrasonic sensor comes with a range chart indicating how far and how wide its ultrasonic waves will travel The waves do not act like laser beams, and objects not directly in front of the sensor can still reflect waves back Specifications For this sensor the waves travel ±20° And up to 7.5 feet
5
5 An ultrasonic sensor contains 2 sensors, a speaker and a microphone The speaker is connected to pin 12, and is an OUTPUT The microphone is connected to pin 11, and is an INPUT There are also connections for 5v and GND Wiring
6
6 6 The sensor will give us the time it took the ultrasonic wave to make the round trip Multiplying the time by the speed of the wave gives us the distance it traveled. We divide by 2 to calculate for one way The speed of sound is 761 MPH, or 1/74 inches per microsecond Computing Distance
7
7 7 void setup() { Serial.begin(9600); pinMode(12, OUTPUT); pinMode(11, INPUT); } void loop() { long duration, inches; digitalWrite(12, LOW); delayMicroseconds(2); digitalWrite(12, HIGH); delayMicroseconds(5); digitalWrite(12, LOW); duration = pulseIn(11, HIGH); inches = duration / 74 / 2; Serial.print(inches); Serial.println("in "); } The Arduino triggers the sensor by sending a 5ms pulse to the speaker through pin 12, which is configured as an Arduino OUTPUT. When the speaker receives the 5ms pulse from the Arduino, it sends a 40kHz (ultrasonic) burst of sound out its “speaker” by setting pin 12 to HIGH. The sensor then waits for the sound burst to reflect off of something and return to the microphone where it is detected; the microphone then sets pin 11 to HIGH. The Arduino uses the pulseIn command to measure the time of flight of the sound wave in microseconds (the time it takes the wave to travel back to the microphone and turn pin 11 HIGH). Code
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.