EmbeddedRelated.com
The 2026 Embedded Online Conference
HC-SR04

HC-SR04

OSEPP Electronics
Multiple Function Sensor Development Tools Ultrasonic Sensor Module

Overview

The HC-SR04 is a low-cost ultrasonic distance sensor module that uses a transmit and receive transducer to detect objects by echo time-of-flight. It provides a simple digital trigger/echo interface so a microcontroller can measure the round-trip time of an ultrasonic pulse and infer distance. The module is common in hobbyist and embedded projects for short-to-medium range proximity and distance sensing.

Why Choose This Part

The HC-SR04 is inexpensive, widely available, and has a straightforward trigger/echo digital interface that integrates easily with microcontrollers. There is extensive community support and example code for platforms like Arduino and Raspberry Pi, which reduces development time. The module is a practical choice when a low-cost contactless distance sensor is needed and environmental conditions are not extreme.

Applications

Robot obstacle avoidance
Use for front or side proximity sensing on mobile robots to detect and avoid obstacles.
Level sensing (solid/non-critical liquids)
Measure fill level in bins, tanks, or containers where contactless sensing and hard surfaces are present.
Presence and proximity detection
Detect the presence of people or objects for automated doors, interactive installations, or safety interlocks.
Simple distance measurement demos and education
Good for teaching timing, interrupts, and basic sensors with microcontrollers or single-board computers.

Getting Started

Connect Vcc and GND to a 5V supply and use a microcontroller GPIO to drive the trigger pin and measure the echo pulse width with an input capture or interrupt/timing routine. Be cautious when connecting to 3.3V microcontrollers: the echo output can be at 5V and may require a level shifter or a simple voltage divider. Libraries and examples are available for Arduino (many community libraries) and for Raspberry Pi (use gpio libraries with proper level shifting).

The 2026 Embedded Online Conference