Also read!
Home / Tools / Arduino / Ultrasonic sensor HC-SR04 for Arduino

Ultrasonic sensor HC-SR04 for Arduino

For those not familiar with Arduino, is an open source platform to simplify the development and teaching of microprocessors. This is a very common sensor, the Ultrasonic sensor HC-SR04, measuring distances between 2 the 450cm.


Below the back of the label. On the front we have the transmitter and receiver of ultrasound. To use the Arduino must download the library This link. If you want to take a look at the datasheet, can follow This link.

The sensor works by sending a sound wave (Ultrasound), that rebate in an obstacle and is received back by label. The time it takes for the sound to be received again upon reflection can be used to calculate the distance to the obstacle.


Now we have, in the picture below, the sensor is connected to a Arduino UNO. Should VDC and GND connect the sensor to the VCC and GND of the Arduino and Trigger pins and Echo to the pins 12 and 13. If you want to change the place of connection of Trigger pins and echo, can, in the sample program, look for the line:

Ultrasonic ultrasonic(12,13);

In this case, the pins 12 and 13 are trigger and echo, respectively. Just change the code to connect the other pins.


The sample program measures the distance, in cm, in front of the sensor, and sends the serial port (USB).


A simpler programme measures only the ultrasound return time.


Very good and cheap! Really liked it. I leave the link to the sensor and to the Arduino UNO:

Ultrasound Sensor – sensor-distance-measuring-module-133,696

Arduino UNO –,374

About Adriano

Professor, Engineer and buyer of products crazy China.


  1. Have you tried the RF modules? It seemed too simple use the USART.

Leave a Reply

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