HC-SR04 has stable performance and high ranging accuracy. HC-SR04 is inexpensive but it has the same ranging accuracy and longer ranging distance than more expensive version.
Specification
- Power supply: 5V DC
- Effectual angle: < 30 degrees
- Ranging distance: 2cm to 500 cm
- Resolution: 1 cm
- Ultrasonic Frequency: 40k Hz
A short ultrasonic pulse is transmitted at the time 0, reflected by an object. The senor receives this signal and converts it to an electric signal. The next pulse can be transmitted when the echo is faded away. This time period is called cycle period. The recommend cycle period should be no less than 50ms. If a 10μs width trigger pulse is sent to the signal pin, the Ultrasonic module will output eight 40kHz ultrasonic signal and detect the echo back. The measured distance is proportional to the echo pulse width and can be calculated by the formula above. If no obstacle is detected, the output pin will give a 38ms high level signal.
Sample application
#include Ultrasonic ultrasonic(12,13);//Init an Ultrasonic object int Distance; void setup() { Serial.begin(9600); } void loop() { Distance=ultrasonic.Ranging(CM);//get the current result; delay(100); Serial.print("the distance is "); Serial.println(Distance); delay(1000); }
References
- Sample Tutorial
- Get Ultrasonic library here: http://freecode.com/projects/hc-sr04-ultrasonic-arduino-library