Arduino HC-SR04 (Ultrasonic sensor)


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.


The connections are pretty simple:

Sensor Arduino
Echo PIN 8
Trig PIN 7
Vcc 5V

With the connections made, lets go to programming.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.