HC-SR04 Ultrasonic Sensor
The HC-SR04 ultrasonic sensor uses sonar to determine the distance to an object like bats or dolphins do. It offers excellent range accuracy and stable readings in an easy-to-use package. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). Similar in performance to the SRF005 but with the low-price of a Sharp infrared sensor.
- Power Supply :5V DC
- Quiescent Current : <2mA
- Effectual Angle: <15°
- Ranging Distance : 2cm – 500 cm/1" - 16ft
- Resolution : 0.3 cm
Using the HC-SR04 with an Arduino
There is an Arduino library for the HC-SR04 that offers two ways to use the sensor. To install, download the “Ultrasonic Library” from this page, unzip the release package into your “Arduino-0022/libraries/” folder. Open the Arduino IDE and include the library by Sketch-Import library-Ultrasonic. There is also an example sketch in File-Examples-Ultrasonic-UltrasonicDemo.
You can directly connect it to your arduino board and measure the distance without wiring with this sketch.
int trigpin = 10;//appoint trigger pin
int echopin = 11;//appoint echo pin
Serial.begin(9600);//set Serial Baud rate
Serial.println("Ultrasonic sensor starting!!!!!");
long microsec = ultrasonic.timing();
cmdistance = ultrasonic.CalcDistance(microsec,Ultrasonic::CM);//this result unit is centimeter
indistance = ultrasonic.CalcDistance(microsec,Ultrasonic::IN);//this result unit is inches
Serial.print(" cmdistance: ");
Serial.print(" indistance: ");