Arduino HC-SR04 Ultrasonic sensor

HC-SR04

The HC-SR04 Ultrasonic Sensor is a very cheap and neat sensor tha gives eyes to your Arduino. This one comes in a Robot kit from Deal Extreme. It works by sending and receiving (bouncing) ultrasound pulses, thus giving you the distance to the nearest object.

In this sketch we’re going to do, we’ll send a pulse to trigger the detection and then listen for the echo using the pulse() function. The duration of this second pulse is equal to the time taken by the ultrasound to travel to the object and back to the sensor. Using the speed of sound, this time can be converted to distance.
(more…)