HC-SR04 Ultrasonic Sensor

Introduction

The HC-SR04 Ultrasonic Sensor is one of the most popular distance-measuring modules used in Arduino, robotics, automation and electronics projects.

It measures the distance to an object without physically touching it. Because of its simple interface and low cost, the HC-SR04 is widely used by students, hobbyists and electronics developers.

In this guide, we will learn:

  • What the HC-SR04 is
  • How ultrasonic distance measurement works
  • HC-SR04 pinout
  • Specifications
  • Circuit connections
  • Arduino programming
  • Distance calculation
  • Common applications
  • Troubleshooting
  • Project ideas
  • How to choose an ultrasonic sensor

What Is the HC-SR04?

The HC-SR04 is an ultrasonic distance sensor module.

It uses high-frequency sound waves to determine the distance between the sensor and an object.

The module contains two main ultrasonic transducers:

       HC-SR04

   ┌───────────────┐
   │  [ TX ] [ RX ]│
   │               │
   │  Ultrasonic   │
   │    Sensor     │
   └───────────────┘

One transducer sends the ultrasonic signal and the other receives the reflected signal.

How Does HC-SR04 Work?

The sensor works using the time-of-flight principle.

The basic process is:

Arduino
   ↓
TRIG pulse
   ↓
HC-SR04 sends ultrasonic wave
   ↓
Wave hits object
   ↓
Reflection returns
   ↓
HC-SR04 produces ECHO pulse
   ↓
Arduino measures time
   ↓
Distance calculated

The longer the echo takes to return, the farther away the object is.

Circuit Diagram

                 ARDUINO UNO
              ┌───────────────┐
              │               │
        D9 ───┤               │
       D10 ───┤               │
              │               │
        5V ───┤               │
       GND ───┤               │
              └───────┬───────┘
                      │
                      ↓
              ┌───────────────┐
              │    HC-SR04    │
              │               │
              │ VCC  ← 5V     │
              │ TRIG ← D9     │
              │ ECHO → D10    │
              │ GND  → GND    │
              └───────────────┘

HC-SR04 Applications

The sensor can be used in many electronics projects.

🤖 Obstacle Avoiding Robot

Use the HC-SR04 to detect obstacles and change the robot's direction.

Related products:

Arduino UNO

L298N Motor Driver

BO Geared Motor

Robot Chassis

HC-SR04 Project Ideas

Once you have learned the basic sensor, try these projects:

Beginner

  • Distance meter
  • LED proximity indicator
  • Digital ruler
  • Parking distance indicator

Intermediate

  • Water-level monitor
  • Obstacle-avoiding robot
  • Automatic dustbin
  • Ultrasonic security alarm

Advanced

  • Servo-based scanning system
  • Multi-sensor robot
  • IoT distance monitoring
  • Smart parking system

Conclusion

The HC-SR04 is a simple and useful ultrasonic distance sensor for learning electronics, Arduino programming and robotics.

Its straightforward TRIG/ECHO interface makes it suitable for projects ranging from basic distance measurement to obstacle-avoiding robots, water-level monitoring and smart automation.

Before purchasing or designing a project, always check the specifications of the exact HC-SR04 module because different manufacturers may provide slightly different electrical and performance characteristics.