075582814553
HC-SR04 Ultrasonic Sensor Guide: How It Works and How to Use It

FREE-SKY (HK) ELECTRONICS CO.,LIMITED / 01-15 17:48

The HC-SR04 Ultrasonic Sensor is a distance-measuring modules in electronics, known for its simplicity, affordability, and reliable performance. This article will discuss the HC-SR04 ultrasonic sensor in detail, including its working principle, usage, pinout, specifications, and more.


Catalog

1. What is HC-SR04 Ultrasonic Sensor?
2. HC-SR04 Ultrasonic Sensor Pinout Details
3. Alternatives & Equivalent Model
4. HC-SR04 Technical Specifications
5. Features and Advantages
6. HC-SR04 Timing Diagram
7. Working Operation and Usage
8. HC-SR04 Ultrasonic Sensor Applications
9. HC-SR04 vs HY-SRF05 Comparison
10. Mechanical Dimensions
11. Conclusion
HC-SR04 Ultrasonic Sensor

What is HC-SR04 Ultrasonic Sensor?

The HC-SR04 Ultrasonic Sensor is a low-cost distance-measuring module that uses ultrasonic sound waves to detect objects without physical contact. It works by sending a short ultrasonic pulse and measuring the time it takes for the echo to return, allowing accurate distance calculation even in dark or dusty environments.

This module typically operates at 5 V and features four pins: VCC, Trig, Echo, and GND, making it easy to connect to microcontrollers such as Arduino and similar development boards. With a measuring range of about 2 cm to 400 cm and stable performance, it is widely used in robotics, obstacle avoidance, level sensing, and basic automation projects.

If you are interested in purchasing the HC-SR04 Ultrasonic Sensor, feel free to contact us for pricing and availability.

HC-SR04 Ultrasonic Sensor Pinout Details

HC-SR04 Ultrasonic Sensor Pinout Details
Pin Number
Pin Name
Description
1
VCC
Supplies power to the module. It typically requires a 5 V DC input to operate properly.
2
Trig
Trigger input pin. A short HIGH pulse (usually 10 µs) sent from the microcontroller starts the ultrasonic distance measurement.
3
Echo
Output pin that sends a pulse back to the controller. The pulse width represents the time taken for the ultrasonic wave to return, which is used to calculate distance.
4
GND
Ground pin. Connects to the ground of the power supply or microcontroller.

Alternatives & Equivalent Model

Sensor Model
Sensor Type
Typical Range
Notes
JSN-SR04T
Ultrasonic (Waterproof)
20 cm – 600 cm
Waterproof probe, suitable for outdoor or liquid-level sensing
HY-SRF05
Ultrasonic
2 cm – 450 cm
Improved version of HC-SR04 with better stability
Parallax PING)))
Ultrasonic
2 cm – 300 cm
High-quality ultrasonic sensor, single-pin control
URM37
Ultrasonic
4 cm – 500 cm
Industrial-grade ultrasonic module with serial output
Sharp GP2Y0A21YK0F
IR Analog Distance Sensor
10 cm – 80 cm
Analog output, good for short-range indoor use
Sharp GP2Y0A02YK0F
IR Analog Distance Sensor
20 cm – 150 cm
Longer range IR distance sensing
VL53L0X
Time-of-Flight (Laser)
Up to 200 cm
High-precision digital distance sensor (I²C)
E18-D80NK
IR Proximity Sensor
3 cm – 80 cm
Adjustable digital output, simple obstacle detection

HC-SR04 Technical Specifications

Parameter
Specification
Product Model
HC-SR04 Ultrasonic Sensor
Sensor Type
Ultrasonic distance measuring module
Operating Voltage
5 V DC
Operating Current
< 15 mA
Ultrasonic Frequency
40 kHz
Trigger Pulse Width
≥ 10 µs
Echo Signal
TTL pulse output (5 V)
Measuring Distance (Theoretical)
2 cm – 400 cm
Measuring Distance (Practical)
2 cm – 80 cm
Distance Resolution
~3 mm
Measuring Angle
< 15°
Interface Type
Digital (Trig & Echo pins)
Response Time
~60 ms
Accuracy
±3 mm
Operating Temperature
0 °C to +70 °C
Storage Temperature
−40 °C to +85 °C
PCB Dimensions
~45 × 20 × 15 mm
Mounting Holes
Yes (2 holes)
Weight
~9 g
Compatibility
Arduino, ESP8266, ESP32, STM32, Raspberry Pi (with level shifting)

Features and Advantages

• Non-contact ultrasonic distance measurement

• Operates at 5 V DC

• Measuring range from 2 cm to 400 cm

• High distance resolution (~3 mm)

• Narrow measuring angle (<15°)

• Uses 40 kHz ultrasonic frequency

• Simple 4-pin interface (VCC, Trig, Echo, GND)

• Digital TTL pulse output

• Easy integration with microcontrollers

• Compact and lightweight module

• Accurate distance measurement at low cost

• Works reliably in low-light or dark environments

• No physical contact, reducing wear and damage

• Simple wiring and control logic

• Widely supported with libraries and examples

• Suitable for beginners and educational projects

• Low power consumption

• Easily replaceable and widely available

• Minimal calibration required for basic use

HC-SR04 Timing Diagram

HC-SR04 Timing Diagram


The HC-SR04 ultrasonic sensor timing diagram shows the exact sequence of signals used to perform a distance measurement. The process begins when the microcontroller sends a short HIGH pulse, typically 10 microseconds, to the Trig pin. This trigger signal tells the sensor to start a new ranging cycle and prepares the internal circuitry to transmit ultrasonic waves.

After receiving the trigger pulse, the sensor generates an ultrasonic burst made up of several cycles at a frequency of about 40 kHz. These sound waves are emitted from the transmitter and travel through the air toward the target object. During this time, the sensor waits for the reflected sound to return and does not yet output a distance signal.

Once the ultrasonic waves hit an object and bounce back, the sensor detects the echo and sets the Echo pin HIGH. The duration of this HIGH pulse represents the total time taken for the sound to travel from the sensor to the object and back again. The farther the object is, the longer the Echo pulse remains HIGH.

By measuring the width of the Echo pulse, the microcontroller can calculate the distance using the known speed of sound. A short delay between measurements is recommended to avoid signal overlap and ensure stable, accurate readings.

Working Operation and Usage

Working Operation and Usage

The HC-SR04 Ultrasonic Sensor measures distance by sending and receiving ultrasonic sound waves. When a microcontroller sends a short pulse to the Trig pin, the sensor activates its transmitter and emits a brief ultrasonic burst at around 40 kHz. These sound waves travel through the air until they encounter an object, where they are reflected back toward the sensor.

The returning sound waves are detected by the sensor’s receiver through the Echo pin. The sensor then outputs a signal whose duration represents the total time taken by the sound to travel to the object and return. Because the speed of sound in air is known, the microcontroller can calculate the distance by processing this time value and dividing it by two to account for the round trip.

To use the HC-SR04, supply a stable 5 V power source and connect the Trig and Echo pins to digital I/O pins on the microcontroller. By repeatedly sending trigger pulses and measuring the echo response in software, the sensor can provide continuous and reliable distance readings for real-time applications.

HC-SR04 Ultrasonic Sensor Applications

• Obstacle detection and avoidance in robots

• Distance measurement in DIY and educational projects

• Object detection in automation systems

• Water or liquid level monitoring (non-contact)

• Parking assistance and proximity sensing prototypes

• Smart trash bins and automatic lid system

• Security and intrusion detection setups

• Industrial position and spacing measurement

• Interactive electronics and IoT projects

• Motion-based triggering systems

HC-SR04 vs HY-SRF05 Comparison

Specification
HC-SR04
HY-SRF05
Sensor Type
Ultrasonic distance sensor
Ultrasonic distance sensor
Operating Voltage
5 V DC
5 V DC
Operating Current
<15 mA
<15 mA
Ultrasonic Frequency
≈40 kHz
≈40 kHz
Measuring Range
2 cm – 400 cm
2 cm – 450 cm
Practical Range
2 cm – 80 cm (more stable)
Extended stable range
Distance Resolution
~3 mm
~3 mm
Measuring Angle
<15°
<15°
Pins / Interface
4-pin (VCC, Trig, Echo, GND)
4-pin (VCC, Trig, Echo, GND)
Trigger Input
10 µs pulse
10 µs pulse
Echo Output
TTL pulse
TTL pulse
Response Time
~60 ms
~60 ms
Temperature Range
0 °C – +70 °C
0 °C – +70 °C
Dimensions
~45 × 20 × 15 mm
~45 × 20 × 15 mm
Weight
~9 g
~9 g
Compatibility
Arduino, ESP32, Raspberry Pi
Arduino, ESP32, Raspberry Pi
Special Notes
Most widely used beginner module
Improved range, tighter echo reliability
Best for
Budget projects, education
Projects requiring wider detection range

Mechanical Dimensions

Mechanical Dimensions

Conclusion

The HC-SR04 ultrasonic sensor simple working principle, clear timing behavior, and easy integration with microcontrollers make it a reliable choice for obstacle detection, level sensing, and automation systems. By understanding its features, technical specifications, working operation, and how it compares with similar sensors like the HY-SRF05, you can confidently select and apply the HC-SR04 for your specific needs.


Processed in 0.057520 Second , 23 querys.