HC-SR04 Distance Sensor
The HC-SR04 distance sensor uses ultrasonic pulses to detect objects.
Table of contents
- Physical Operating Principle
- Wiring Schematics
- Sample Codes
- Hook-up Notes for Circuit Playground
- Vendor Information
Physical Operating Principle
The HC-SR04 ultrasonic distance sensor infers distance to an object by measuring the time it takes an ultrasonic pulse to travel from a transmitter (speaker) to a receiver (microphone).
The sensor measures the time between the initiation of the the sound and the arrival of its echo. The distance is determined by dividing the one half of the time difference by the speed of sound.
where is the distance to the object, is the time of flight and is the speed of sound. The factor of 2 in the denominator is necessary because the time of flight is for the out-and-back trip of the sound pulse.
Wiring Schematics
Sample Codes
Hook-up Notes for Circuit Playground
The standard HC-SR04 sensor requires a 5V input for Vcc. To make this sensor (powered at 5V) compatible with a Circuit Playground, the output voltage must be stepped down to no more than 3.3V. A simple voltage divider created with two 10 kΩ resistors on the Echo pin achieves that goal. With the voltage divider the Echo output is either 0 or 2.5V, which works with the 3.3V logic.
Vendor Information
- Sainsmart product page, listed as discontinued
- Adafruit product
- SparkFun product