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.

HC1

The connections are pretty simple:

Sensor Arduino
GND GND
Echo PIN 8
Trig PIN 7
Vcc 5V

With the connections made, lets go to programming.

References

http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor
http://arduinobasics.blogspot.pt/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html

Leave a Reply

Your email address will not be published. Required fields are marked *