HC-SR04 Ultrasonic sensor module pinouts and tutorials

HC-SR04 pinout- How to work HC-SR04 ? How to use HC-SR04 with Arduino? HC-SR04 arduino code

0
1393

HC-SR04 provides a non-contact measurement between 2 cm – 400 cm.  It uses ultrasonic sound signal for measurement. HC-SR04 works 5V operate voltage. The accuracy can be 3 mm and the effective measurement angle under 15°

HC-SR04 ultrasonic module has ultrasonic transmittter, receiver and control circuit. So it can used in distance reading, radar and robot applications.

How to work HC-SR04?

  • Using IO trigger for at least 10us high level signal
  • The Module sends eight 40 kHz and detect whether there is a pulse signal back.

* IF the signal comes back, through high level , time of high output IO duration is
the time from sending ultrasonic to returning.

Calculation formula: Test distance = (high level time×velocity of sound (340M/S) / 2

HC-SR04 pinout

HC-SR04 is a simple structure and very easy to use sensor. It has only 4 pin. Two of thems are VCC (+5V) and GND (-) pins. Other 2 pins are Echo and Trigger pins. Usually when we make a project we use libraries. HC-SR04 has a library. Every library has a simple code. We when look at this simple code then we see pin connection.

Here is HCSR-04 library. There is an example code in library. Here it is:

#include <HCSR04.h>

HCSR04 hc(5,6);//initialisation class HCSR04 (trig pin , echo pin)

void setup()
{ Serial.begin(9600); }

void loop()
{ Serial.println( hc.dist() ); }//return curent distance in serial

As we seen in this code that trigger pin connected Arduino’s 5. pin and Echo pin connector Arduino 6. pin. Of course you can change this pins.

How to use multi HCSR04 with Arduino?

We have to use multi HCSR04 in many projects. For example I made a helmet project for blind persons a long time ago. I had used 5 ultrasonic sensor in this project. I was being reading measurement always for 5 sensors.

Fortunately HCSR04 library includes multi sensor sample. I took below code from HCSR04 library:

#include <HCSR04.h>

HCSR04 hc(2,new int[6]{5,6,7,8,9,10},6);//initialisation class HCSR04 (trig pin , echo pin, number of sensor)

void setup()
{ Serial.begin(9600); }

void loop()
{ for (int i = 0; i < 6; i++ ) {Serial.println( hc.dist(i) );} }//return curent distance in serial for sensor 1 to 6

You can change the pin numbers. In this example there are 6 sensors. You should change according to the number of sensors.

HC-SR04 Projects: What can you do with HC-SR04?

In this section, I will share some projects made using HC-SR04.

1- How to use HC SR04 to measure distance? 

Answer is here. Measuring distance is demonstrated in this instructables project. If you want, you can add a buzzer to this project. The buzzer sounds at a certain distance. So you can make a simple parking sensor. Look here.

2- HC-SR04 RADAR Using Processing & Arduino

A radar system is demonstrated In this project 

3- How to print measuring distance to LCD display?

You measured distance. Ok. Now tou want to show on LCD display. Then you can make this instructables project.

4- Arduino HC-SR04 Ultrasonic Rover

You can use HC-SR04 for robotic applications. You can make obstacle avoidance robot, labyrint solver robot, Object follower robot and etc…

5.Motion Following Robot with HC-SR04

I made a similar project 4 years ago. I used 3 sensor. But 2 HC-SR04 sensor used in this project 

If you want to use this prencible for making animatronic head (or eyes). You can.

3D printed HC-SR04 holder

A lot of cheap holder products selling on market for HC-SR04. If you have an 3D printer then you dont need to buy. You can download many 3D HC-SR04 model files from web.

You can download 3D printed HC-SR04 model files from here.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here