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

2 How it Works The sensor emits short bursts of sound, and listens for the echo off nearby objects By measuring the time of flight, distance can be computed

3 When it doesn’t work When waves are not reflected back towards the sensor

4 Specifications An ultrasonic sensor comes with a chart indicating how far and wide its waves will travel They are not laser beams, and objects not directly in front can still reflect waves back For this sensor the waves travel ±20° And up to 7.5 feet

5 Wiring An ultrasonic sensor contains 2 sensors, a speaker and a microphone The speaker is an OUTPUT The microphone is an INPUT There are also connections for 5v and GND

6 Distance = Speed x Time Example Miles = MPH x Hours Computing Distance
The sensor will give us the time for the round trip Multiplying the time by the speed of sound, and divide by 2 to calculate for one way The speed of sound is 761 MPH, or 1/74 inches per microsecond

7 Code 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 "); } By setting pin 12 to HIGH, the speaker sends a 40kHz (ultrasonic) burst of sound out its “speaker” The sound burst reflects off something and returns to the microphone; the microphone then sets INPUT pin 11 to HIGH. The pulseIn command measures the time of flight (the time it took the wave to travel back to the microphone and turn pin 11 HIGH). Multiplying TIME x SPEED (1/74) and dividing by 2 gives us the distance traveled

8 Complete the Ultrasonic Distance Sensor
LAB Complete the Ultrasonic Distance Sensor Lab in Unit 11


Download ppt "Ultrasonic Distance Sensor"

Similar presentations


Ads by Google