ModulesOctober 27, 2026

HC-SR04 Ultrasonic Distance Sensor Module: Working, Pinout, Specifications and Applications

Learn how the HC-SR04 ultrasonic distance sensor works, its pinout, specifications, Arduino connections, applications, and tips for reliable measurements.

wdesa

The HC-SR04 Ultrasonic Distance Sensor Module is a popular electronic component used to measure the distance between a sensor and an object without physical contact. It is widely used in Arduino projects, robotics, smart parking systems, home automation, and educational electronics projects.

Whether you are building an obstacle-avoiding robot, developing an automatic water-level monitoring system, or experimenting with an embedded electronics project, the HC-SR04 offers a practical way to introduce distance measurement into your design.

This module uses ultrasonic sound waves to detect nearby objects and calculate their distance based on the time taken for the reflected sound to return. Its simple four-pin interface makes it relatively easy to integrate with compatible microcontrollers.

In this guide, we will explain how the HC-SR04 ultrasonic sensor works, its pin configuration, technical specifications, applications, wiring requirements, and important factors to consider when using it.

What Is the HC-SR04 Ultrasonic Distance Sensor Module?

The HC-SR04 is a non-contact distance measurement module that uses high-frequency sound waves to estimate the distance to an object. Unlike contact-based measurement methods, it does not need to touch the object being measured.

The module contains two prominent ultrasonic transducers. One transmits ultrasonic sound waves, while the other receives the reflected waves. An onboard control circuit processes the signal and provides an output pulse that a microcontroller can use to calculate the distance.

The HC-SR04 commonly measures distances from 2 cm to 400 cm, with a typical specified accuracy of up to approximately ±3 mm under suitable conditions. Actual readings may vary depending on the object, its surface, the surroundings, and the sensor itself.

Its straightforward interface and accessible design make it a useful component for beginners, engineering students, hobbyists, and prototyping projects.

You can explore or purchase the HC-SR04 Ultrasonic Distance Sensor Module from Component Wala.

Key Features of the HC-SR04 Ultrasonic Sensor

The module offers several features that make it suitable for general-purpose distance measurement and object detection.

  • Non-contact measurement: Detects an object's distance without physical contact.
  • Measuring range: Approximately 2 cm to 400 cm.
  • Operating voltage: 5V DC for the standard HC-SR04 module.
  • Specified accuracy: Up to approximately ±3 mm under suitable test conditions.
  • Ultrasonic frequency: 40 kHz.
  • Simple four-pin interface: Uses VCC, GND, TRIG, and ECHO connections.
  • Microcontroller integration: Commonly used with Arduino and, with appropriate signal-level precautions, ESP32 and Raspberry Pi projects.
  • Multiple applications: Suitable for robotics, smart parking prototypes, object detection, and educational experiments.

These features make the HC-SR04 a practical choice for projects that need basic distance sensing without requiring a more complex measurement system.

HC-SR04 Ultrasonic Sensor Specifications

The following table summarizes the commonly published specifications of a standard HC-SR04 module.

Parameter

Specification

Sensor type

Ultrasonic distance sensor

Model

HC-SR04

Operating voltage

5V DC

Measuring range

Approximately 2–400 cm

Specified accuracy

Up to approximately ±3 mm

Operating frequency

40 kHz

Trigger input

High pulse of at least 10 microseconds

Output

Echo pulse whose duration represents distance

Interface pins

VCC, GND, TRIG, ECHO

Typical module dimensions

Approximately 45 × 20 × 15 mm

Specifications such as current consumption, dimensions, and measurement performance can vary slightly among module versions and suppliers. Always check the specifications of the particular board you receive before integrating it into a final design.

How Does the HC-SR04 Ultrasonic Distance Sensor Work?

The working principle of the HC-SR04 is based on the time-of-flight method. It measures how long an ultrasonic sound wave takes to travel to an object and return to the sensor.

The process works in four basic steps.

1. Trigger the sensor

A microcontroller sends a short HIGH pulse, typically lasting at least 10 microseconds, to the TRIG pin. This instructs the module to begin a measurement.

2. Transmit ultrasonic sound waves

The sensor sends out a short burst of ultrasonic sound at approximately 40 kHz. These sound waves travel through the air toward nearby objects.

3. Receive the reflected sound

When the sound waves hit an object, some of the energy reflects toward the sensor. The receiving transducer detects the returning echo, and the ECHO pin produces a pulse whose duration corresponds to the sound's round-trip travel time.

4. Calculate the distance

A microcontroller measures the ECHO pulse duration and calculates the distance using the speed of sound.

The general formula is:

Distance = (Time × Speed of Sound) ÷ 2

The result is divided by two because the sound travels to the object and then back to the sensor.

For the common HC-SR04 implementation, a convenient approximation is:

Distance in centimetres ≈ Echo pulse duration in microseconds ÷ 58

For example, if the measured ECHO pulse lasts approximately 580 microseconds, the calculated distance is about 10 cm.

This method allows a microcontroller to obtain distance readings and use them to trigger other actions, such as stopping a robot, displaying a measurement, or activating an alert.

HC-SR04 Pinout and Pin Configuration

The HC-SR04 has four pins, which makes it relatively straightforward to connect to a compatible development board.

Pin

Function

VCC

Connects to a suitable 5V DC supply

TRIG

Receives the trigger pulse from the microcontroller

ECHO

Outputs a pulse representing the measured distance

GND

Connects to the circuit ground

Understanding the connections

VCC: Supplies power to the sensor module. The standard HC-SR04 is designed for 5V DC operation.

TRIG: Receives a short trigger pulse to initiate a measurement.

ECHO: Provides the pulse that the controller measures to calculate distance. The pulse width increases as the measured distance increases.

GND: Provides the common ground reference between the sensor and the controller.

Before connecting the module, check the pin labels and the operating-voltage requirements of your development board.

Important wiring note for ESP32 and Raspberry Pi

The standard HC-SR04 can produce a 5V-level signal on its ECHO pin. Raspberry Pi GPIO pins are not 5V tolerant, and ESP32 GPIO voltage limits must also be respected.

When connecting the standard module to an ESP32 or Raspberry Pi, use an appropriate voltage divider or logic-level converter on the ECHO signal to bring it down to a safe input voltage. Do not connect a potentially 5V ECHO signal directly to a 3.3V GPIO pin.

How to Connect the HC-SR04 to Arduino

The Arduino Uno is a common platform for experimenting with ultrasonic distance measurement because its digital I/O operates at 5V logic levels.

A basic connection is as follows:

HC-SR04 pin

Arduino Uno connection

VCC

5V

GND

GND

TRIG

A selected digital output pin

ECHO

A selected digital input pin

For example, you could connect TRIG to digital pin 9 and ECHO to digital pin 10. These are example assignments; your program must use the same pins.

After connecting the sensor, the usual programming sequence is to configure the TRIG pin as an output and the ECHO pin as an input, send the trigger pulse, measure the echo duration, and calculate the distance.

The Arduino IDE provides the pulseIn() function, which can be used to measure the duration of an input pulse.

For reliable measurements, keep the sensor pointed toward the target and allow an adequate interval between readings. Also, ensure that the signal levels and wiring are appropriate for the exact hardware being used.

Applications of the HC-SR04 Ultrasonic Distance Sensor Module

The HC-SR04 is used in many educational, hobbyist, and prototype applications.

1. Obstacle-Avoiding Robots

A mobile robot can use an HC-SR04 to detect objects in front of it. When the measured distance falls below a programmed threshold, the controller can stop the motors, turn the robot, or select another direction.

This makes the sensor useful for learning about autonomous movement and basic robotics.

2. Distance Measurement Projects

The module can measure the approximate distance between itself and a suitable target. This capability is useful in electronics experiments, measuring demonstrations, and microcontroller-based distance displays.

3. Water-Level Monitoring Systems

An ultrasonic sensor mounted above a container can estimate the distance to the water surface. The measured distance can then be used to estimate the water level when the container's geometry and sensor placement are known.

For dependable real-world water-level monitoring, account for condensation, splashing, irregular surfaces, and the environmental limitations of the module. The standard HC-SR04 is not a waterproof sensor.

4. Smart Parking Systems

In a parking prototype, the sensor can detect whether a vehicle is within a defined distance. A microcontroller can process the reading and display an occupied or available status.

Multiple sensors and appropriate installation may be required for larger systems.

5. Home Automation Projects

The sensor can help detect nearby objects or the approach of a person in simple experimental automation projects. A controller can respond by switching an indicator, activating a small mechanism, or sending a signal to another device.

It should not be treated as a guaranteed security or safety sensor without proper system design and validation.

6. Robotics and Embedded Systems Learning

Students can use the HC-SR04 to understand pulse timing, digital input and output, embedded programming, and sensor-based decision-making.

It also provides a useful introduction to combining hardware and software in practical electronics projects.

7. STEM and Educational Projects

Because the module uses a simple interface and a clear measurement principle, it is suitable for classroom demonstrations and beginner electronics experiments involving sound waves, timing, and automation.

Advantages of Using the HC-SR04 Sensor

The HC-SR04 offers several benefits for projects that require basic proximity or distance measurement.

Easy to integrate: Its four-pin interface simplifies connections to many development boards.

Non-contact operation: It measures distance without touching the target.

Useful measurement range: The nominal 2–400 cm range covers many short-distance experiments and prototypes.

Accessible for beginners: The sensor is commonly used in Arduino tutorials, student projects, and introductory robotics.

Flexible applications: The same basic sensing approach can support several kinds of object-detection and distance-measurement projects.

However, it is important to choose the sensor according to the project's requirements. Applications that demand certified safety performance, very high precision, long-distance detection, or reliable operation in difficult environmental conditions may need a different sensing technology.

Tips for Getting More Reliable HC-SR04 Readings

The quality of the measurement depends on more than the sensor's nominal specifications. A few simple precautions can help improve results.

  • Keep the target within range: Objects closer than approximately 2 cm or farther than the module's rated range may not produce reliable readings.
  • Point the sensor toward the target: Angled surfaces may reflect sound away from the receiver.
  • Consider the target material: Soft, irregular, or absorbent surfaces can produce weaker echoes.
  • Avoid measurement interference: Other ultrasonic sensors operating nearby may interfere with readings.
  • Allow sufficient time between measurements: A measurement interval greater than about 60 milliseconds is commonly recommended for the standard module.
  • Use appropriate power and signal levels: Keep the supply voltage within specification and protect 3.3V GPIO inputs from 5V ECHO signals.
  • Filter inconsistent readings in software: Taking several readings and using a median or another suitable filtering method can help reduce occasional fluctuations.

The ±3 mm figure should be treated as a nominal specification under suitable conditions, not a guarantee that every measurement will be accurate to that level.

HC-SR04 vs. Other Distance Sensors

Choosing an appropriate sensor depends on the type of object being detected, the required range, the environment, and the precision of the application.

Sensor type

Typical strength

Important consideration

HC-SR04 ultrasonic sensor

Affordable, straightforward distance measurement

Readings depend on sound reflection and target conditions

IR proximity sensor

Useful for certain short-range object-detection tasks

Performance can depend on target reflectivity and ambient light

Time-of-flight sensor

Often suitable for compact, optical distance measurement

Range, accuracy, and operating conditions vary by model

Industrial distance sensor

Available in models designed for demanding applications

Specifications, integration requirements, and cost vary significantly

The HC-SR04 is a reasonable starting point for hobby and educational projects when its range, voltage requirements, and environmental limitations meet the application's needs.

Where to Buy the HC-SR04 Ultrasonic Distance Sensor Module?

If you are planning an Arduino experiment, a robotics project, or a microcontroller-based distance-measurement system, the HC-SR04 ultrasonic sensor is a useful component to consider.

You can view the product details and purchase the HC-SR04 Ultrasonic Distance Sensor Module at Component Wala.

Review the product specifications and confirm that the module's voltage, sensing range, and interface suit your project before ordering.

Frequently Asked Questions About the HC-SR04 Ultrasonic Sensor

1. What is the range of the HC-SR04 ultrasonic sensor?

The standard HC-SR04 is commonly specified to measure distances from approximately 2 cm to 400 cm. Actual performance depends on the target, surroundings, and sensor implementation.

2. Does the HC-SR04 require 5V power?

Yes. The standard HC-SR04 module is designed to operate from a 5V DC supply. Check the documentation if you have a different variant.

3. Can I use the HC-SR04 with Arduino?

Yes. It is commonly used with Arduino boards. Connect VCC, GND, TRIG, and ECHO to suitable pins and use a program that measures the ECHO pulse duration.

4. Can I connect the HC-SR04 to an ESP32?

Yes, with appropriate signal-level precautions. Use a suitable voltage divider or level converter on the ECHO signal because the standard sensor may output 5V, which exceeds safe ESP32 GPIO input limits.

5. Can the HC-SR04 work with Raspberry Pi?

Yes, but the ECHO connection must be adapted to a safe GPIO input voltage. Raspberry Pi GPIO pins are not 5V tolerant, so do not connect a standard HC-SR04's potentially 5V ECHO output directly to a GPIO pin.

6. How does the HC-SR04 calculate distance?

It sends ultrasonic sound waves toward an object and measures the time taken for the reflected sound to return. The controller calculates the distance from the echo duration and the speed of sound, dividing by two to account for the outgoing and returning journey.

7. Is the HC-SR04 waterproof?

The standard HC-SR04 is not waterproof. Projects exposed to rain, splashes, or continuous moisture should use an appropriately rated sensor or protective arrangement designed for the environment.

8. What are the four pins of the HC-SR04?

The four pins are VCC, GND, TRIG, and ECHO. They provide power, ground, the measurement trigger input, and the echo output respectively.

9. What projects can I build using the HC-SR04?

You can build obstacle-avoiding robots, distance displays, water-level monitoring prototypes, smart parking demonstrations, and various educational automation projects.

10. Is the HC-SR04 suitable for beginners?

Yes. Its simple interface, straightforward measurement principle, and widespread use in Arduino tutorials make it a useful choice for learning basic electronics, sensor integration, and embedded programming.

Conclusion

The HC-SR04 Ultrasonic Distance Sensor Module is a practical option for learning and experimenting with non-contact distance measurement. Its simple interface, nominal 2–400 cm range, and compatibility with common microcontroller platforms make it useful for a variety of educational, robotics, and automation prototypes.

Understanding its working principle, pin configuration, signal-voltage requirements, and measurement limitations will help you integrate the sensor more effectively into your projects.

If you need a sensor for your next electronics experiment or robotics build, explore the HC-SR04 Ultrasonic Distance Sensor Module on Component Wala and check its specifications for your intended application.


Related products

Components that pair well with this guide.