HC-SR04 Ultrasonic Sensor

Background

ultrasonic-1.png

An ultrasonic sensor works similar to echo-location in bats. The sensor emits high-frequency sound waves and calculates the time until the waves are reflected back to the sensor. It is used to detect distance to obstacles. To take a reading, a 10 microsecond pulse is sent on the trigger pin. This tells the senor to emit eight 40 kHz sound waves outward. The echo pin goes high and stays high until the sound waves are received back to the sensor. You can calculate the distance using the time-of-flight or ToF by computing how long the echo pin is high.

 

ultrasonic_timing.png

 

Hardware Description

Pinout

 

 

Software Description

Use the pulseIn() to determine the time it takes for the sound waves to travel out and back.