Ultrasonic sensors overcome many of the weaknesses of IR sensors as they provide distance measurement regardless of color and illumination of obstacles.
They also provide lower minimum distances and wider detection angles to ensure that obstacles are not lost by a narrow detection beam.
That particular model is an update of the popular HC-SRO4 with better accuracy. It has 5 pins and can be used in 1 pin trigger / echo mode or 2 pins.
- Power supply: 4.5-5.5 VDC
- Power supply current: 10 to 40 mA
- Activation pin format: 10 μs digital pulse
- Echo Pin Output: 0-Vcc
- Echo Pin Format: the output is DIGITAL and directly proportional with range. See our conversion formula below
- Measuring range: 2cm to ~ 4.5m
- Resolution of the measure: 0.3cm
- Measurement angle: up to 15 degrees
- Measuring speed: 40 Hz,
- Connector: standard 5-pin male connector that can be connected directly to boards or proto-boards:
- 1: VCC
- 2: Trig
- 3: Echo
- 4: OUT
- 5: GND
- Size: 45 × 21 mm
The distance measurements can be made with microcontrollers in a simple way:
You can find an Arduino library with the code in the arduino forum.
Send a 10 μs wide pulse to the sensor on the trigger pin (Trigger). The sensor will automatically send a 40 kHz wave.
Begin to supervise the output of Pin Echo and:
- When the Echo Pin goes high, start a timer.
- When the Echo Pin is set low, record the time elapsed from the timer and use the following conversion formula:
- Distance (in cm) = (elapsed time * speed of sound (340 m / s)) / 100/2
Note: we divide the distance by 2 because the sensor returns the round trip time, which doubles the distance measurement.