Free shipping on orders above โ‚น599
SALE UPTO 40%

HC-SR04 Ultrasonic Sensor: Working, Features, Applications, and Uses

Quick answer: the HC-SR04 is a 5 V ultrasonic distance sensor that measures from 2 cm to 4 m. It sends a burst of 40 kHz sound, times the echo, and outputs a pulse whose length is proportional to distance. Distance in centimetres is the echo time in microseconds divided by 58.

Distance measurement is a critical requirement in modern electronics, especially in robotics, automation, and embedded systems. One of the most widely used and beginner-friendly solutions for this purpose is the HC-SR04 ultrasonic sensor module.

In this blog, weโ€™ll explore what the HC-SR04 ultrasonic sensor is, how it works, its key features, applications, and why it remains a popular choice for students, hobbyists, and engineers.


HC-SR04 ultrasonic sensor module with transmitter and receiver

What Is the HC-SR04 Ultrasonic Sensor?

The HC-SR04 ultrasonic sensor is an electronic module designed to measure distance using ultrasonic sound waves. It works by transmitting high-frequency sound pulses and calculating the time taken for the echo to return after hitting an object.

Based on this time delay, the sensor accurately calculates the distance between itself and the object in front of it. This simple yet effective principle makes the HC-SR04 a go-to solution for non-contact distance measurement.

HC-SR04 Specifications

These values are taken from the HC-SR04 datasheet.

ParameterValue
Working voltage5 V DC
Working current15 mA
Ultrasonic frequency40 kHz
Measuring range2 cm to 4 m
Ranging accuracyUp to 3 mm
Measuring angle15 degrees
Trigger input10 ยตs TTL pulse
Echo outputTTL pulse, width proportional to distance
Dimensions45 ร— 20 ร— 15 mm

How the HC-SR04 Ultrasonic Sensor Works

The working principle of the HC-SR04 is straightforward:

  1. The sensor sends out an ultrasonic pulse through the Trigger (Trig) pin.
  2. The sound wave travels through the air and reflects back after hitting an object.
  3. The reflected signal is received by the sensor through the Echo pin.
  4. The time between sending and receiving the signal is measured.
  5. Distance is calculated using the speed of sound.

This process happens in microseconds, allowing real-time distance measurement.

Timing: what happens on the Trig and Echo pins

  1. Your microcontroller holds Trig high for at least 10 ยตs.
  2. The module transmits a burst of eight 40 kHz ultrasonic cycles.
  3. The module raises Echo high and keeps it high until the reflected sound returns.
  4. The width of the Echo pulse is the round-trip travel time of the sound.

HC-SR04 distance formula

The datasheet gives the range as distance = echo high time ร— speed of sound (340 m/s) รท 2. The division by 2 is needed because the sound travels to the object and back. In practice this simplifies to:

  • Distance in cm = echo time in ยตs รท 58
  • Distance in inches = echo time in ยตs รท 148

Example: an Echo pulse of 1,160 ยตs means the object is 1,160 รท 58 = 20 cm away.


HC-SR04 Pin Configuration

The HC-SR04 module typically comes with four pins:

  • VCC โ€“ Power supply (usually 5V)
  • Trig โ€“ Used to trigger the ultrasonic pulse
  • Echo โ€“ Outputs the pulse duration based on distance
  • GND โ€“ Ground connection

The clearly labeled PCB pins make it easy to integrate the sensor with microcontrollers like Arduino and other development boards.

How to Connect the HC-SR04 to Arduino

You need an UNO R3 board or a Nano R3 board, four jumper wires and, if you like, a 400-point breadboard. The pin numbers below match the example code; any two free digital pins will work.

HC-SR04 pinArduino pin
VCC5V
TrigD9
EchoD10
GNDGND

HC-SR04 Arduino code

const int trigPin = 9;
const int echoPin = 10;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);   // 10 microsecond trigger pulse
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH, 30000);  // echo time in microseconds, 0 if no echo
  float distanceCm = duration / 58.0;

  Serial.print("Distance: ");
  Serial.print(distanceCm);
  Serial.println(" cm");

  delay(60);  // datasheet suggests a measurement cycle over 60 ms
}

Open the Serial Monitor at 9600 baud to see the distance. A reading of 0 means no echo came back within the timeout, usually because the object is out of range.

Tips for stable readings

  • Wait at least 60 ms between measurements so an old echo is not mistaken for a new one (datasheet recommendation).
  • Connect GND before VCC; the datasheet warns that powering the module without ground first can affect its operation.
  • Aim at a flat, hard surface. The datasheet recommends a smooth target of at least 0.5 square metres for accurate results.
  • Keep the target inside the 15 degree measuring angle and between 2 cm and 4 m.
  • Echo is a 5 V signal. On 3.3 V boards such as the ESP32, use a level shifter or resistor divider on the Echo line.

Key Features of the HC-SR04 Ultrasonic Sensor

  • Accurate distance measurement using ultrasonic waves
  • Non-contact sensing (no physical wear)
  • Simple interface with microcontrollers
  • Compact and lightweight PCB design
  • Stable performance for indoor applications
  • Cost-effective solution for learning and prototyping

These features make the HC-SR04 ideal for both beginners and professionals.


Applications of the HC-SR04 Ultrasonic Sensor

The HC-SR04 ultrasonic sensor is used in a wide range of applications, including:

1. Robotics

Used for obstacle detection and navigation in robots.

2. Distance Measurement Projects

Commonly used in Arduino-based distance measuring systems.

3. Automation Systems

Helps in detecting object presence or proximity.

4. IoT and Smart Devices

Used in smart bins, parking systems, and level monitoring projects.

5. Educational Projects

Popular in schools, colleges, and training labs for learning sensors and embedded systems.


Why the HC-SR04 Is Still Popular

Despite the availability of newer sensors, the HC-SR04 remains popular because it offers the perfect balance of simplicity, accuracy, and affordability. Its clear documentation, strong community support, and ease of use make it an excellent choice for prototyping and learning.

For anyone starting with embedded systems or robotics, this sensor provides a practical introduction to real-world distance sensing.


HC-SR04 FAQ

What is the range of the HC-SR04?

2 cm to 4 m, with a ranging accuracy of up to 3 mm according to the datasheet.

What voltage does the HC-SR04 need?

5 V DC. Its working current is 15 mA, so it can be powered from the 5V pin of an Arduino board.

Why do we divide by 58?

Sound travels at about 340 m/s, and the echo time covers the trip to the object and back. That works out to roughly 58 ยตs of echo time for every centimetre of distance.

What frequency does the HC-SR04 use?

It transmits a burst of eight cycles at 40 kHz, which is above the range of human hearing.

Related Sensors and Guides

For short-range obstacle detection, see the HW-201 IR obstacle avoidance sensor; for detecting people, the HC-SR501 PIR motion sensor. Browse all sensor modules, or get project ideas from 10 best final year electronics projects under โ‚น2000.


Conclusion

The HC-SR04 ultrasonic sensor continues to be a reliable and widely used distance measurement module in electronics. Whether you are a student building your first project or an engineer prototyping an automation solution, this sensor delivers consistent performance and ease of integration.

With its clean PCB layout, accurate sensing, and versatile applications, the HC-SR04 is a must-have component in any electronics toolkit.


Buy the HC-SR04 ultrasonic sensor module

1 comment

    […] to this sensor? Our HC-SR04 working, pinout and Arduino code guide covers the wiring and the distance formula used in this […]

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping