HC-SR04 ultrasonic sensor is one of the most popular sensors in the Arduino ecosystem because it makes measuring distance incredibly simple.
The HC-SR04 uses ultrasonic sound waves (40 kHz) to determine how far an object is from the sensor. It works by transmitting sound waves, waiting for them to bounce back from an object, and calculating the distance based on the time taken for the echo to return.
In this tutorial, we'll learn what the HC-SR04 sensor is, how it works, its key specifications, real-world applications, and how to interface it with an Arduino UNO.
This article is adapted from a project published on Play with Circuit, where we regularly share Arduino, ESP32, IoT, and embedded systems tutorials.
What is the HC-SR04 Ultrasonic Sensor?
The HC-SR04 is a non-contact distance measurement sensor widely used in electronics and robotics projects. Since it uses ultrasonic waves instead of light, it performs reliably in different lighting conditions.
The module contains an ultrasonic transmitter, an ultrasonic receiver, and onboard control circuitry. Whenever the Trigger pin receives a pulse, the sensor emits ultrasonic waves. These waves travel through the air, hit an object, and return to the receiver. The sensor then calculates the distance by measuring the travel time of the sound.
One of the biggest advantages of the HC-SR04 is its simplicity. It requires only four pins and can be connected to an Arduino in just a few minutes.
Key Features of HC-SR04
- Operating voltage: 5V DC
- Operating current: Approximately 15 mA
- Operating frequency: 40 kHz
- Measurement range: 3 cm to 300 cm
- Accuracy: Approximately ±3 mm
- Measuring angle: Less than 15 degrees
- Dimensions: 45 mm × 20 mm × 15 mm
- Supports non-contact distance measurement
- Low power consumption
- Easy interfacing with Arduino and other microcontrollers
These specifications make the HC-SR04 suitable for both beginner and advanced electronics projects.
HC-SR04 Pinout
The HC-SR04 has four pins:
- VCC: Provides power to the sensor and should be connected to 5V.
- Trig: Receives a 10-microsecond pulse to initiate distance measurement.
- Echo: Outputs a pulse whose width represents the distance to the object.
- GND: Connected to the ground of the Arduino.
Because there are only four connections, the sensor is ideal for beginners learning about sensor interfacing.
How Does the HC-SR04 Work?
The HC-SR04 operates using the principle of echolocation, which is similar to how bats and dolphins navigate.
The process works as follows:
- Arduino sends a 10-microsecond pulse to the Trigger pin.
- The sensor emits ultrasonic waves at a frequency of 40 kHz.
- These sound waves travel through the air until they encounter an object.
- The waves reflect back toward the sensor.
- The Echo pin remains HIGH until the reflected signal is received.
- Arduino measures the pulse duration and calculates the distance.
The formula used to calculate distance is:
Distance = (Time × Speed of Sound) ÷ 2
For Arduino projects, a simplified equation is commonly used:
Distance (cm) = Echo Time (µs) ÷ 58.3
For example, if the Echo pulse duration is 1000 microseconds, the calculated distance is approximately 17 centimeters.
Applications of HC-SR04
The HC-SR04 is used in countless electronics projects. Some popular applications include:
- Obstacle avoiding robots
- Smart parking systems
- Water and liquid level monitoring
- Automatic door systems
- Home automation projects
- Security and alarm systems
- Drone navigation
- Object detection systems
- Smart dustbins
- Industrial automation solutions
Its versatility makes it one of the first sensors many makers add to their toolkit.
Hardware Required
To build this project, you'll need the following components:
- Arduino UNO (1)
- HC-SR04 Ultrasonic Sensor (1)
- 16×2 LCD Display (1)
- 10k Potentiometer (1)
- 1k Resistor (1)
- Breadboard (1)
- Jumper Wires
- USB Cable for programming the Arduino
Circuit Connections

Connect the HC-SR04 sensor as follows:
- VCC → Arduino 5V
- Trig → Arduino Pin 6
- Echo → Arduino Pin 7
- GND → Arduino GND
For the LCD connections:
- RS → Pin 12
- Enable → Pin 11
- D4 → Pin 5
- D5 → Pin 4
- D6 → Pin 3
- D7 → Pin 2
The Arduino continuously reads the distance from the HC-SR04 and displays it on the LCD in centimeters.
Tips for Stable Readings
Ultrasonic sensors can occasionally produce unstable values. To improve accuracy:
- Use the NewPing library.
- Average multiple readings.
- Ensure the sensor is firmly mounted.
- Avoid measuring soft or absorbent materials.
- Keep objects within the recommended measurement angle.
- Minimize electrical interference.
For most projects, averaging five to ten readings produces excellent results.
Final Thoughts
The HC-SR04 remains one of the best sensors for learning Arduino and embedded systems. It introduces important concepts such as timing, sensor interfacing, signal processing, and real-time measurements while being inexpensive and easy to use.
Whether you're building a robot, a parking assistant, or a liquid level monitoring system, the HC-SR04 is an excellent addition to your electronics toolbox.
For the complete tutorial, including LCD integration, additional examples, and more Arduino projects, visit Play with Circuit:
https://playwithcircuit.com/ultrasonic-sensor-hc-sr04-interfacing-with-arduino/

Top comments (0)