HC-SR04 Datasheet: Analysis

Top-side view of HC-SR04 breakout board.

The HC-SR04 datasheet provides all the critical information to set up and evaluate the device.

Sensors are an important part of interfacing any microcontroller with the surrounding environment. One method of sensor analysis is object detection. While infrared is a common, cheap manner of object detection, it can suffer from poor responsiveness during conditions where background light affects the sensor’s performance. Ultrasonic sensor detection can bypass some of the challenges inherent to IR detection, and the HC-SR04 is an excellent device for designers wishing to implement an alternative or secondary surface detection method. The HC-SR04 datasheet gives designers important design information, including an attributes overview of the device’s capabilities and performance.

HC-SR04 Datasheet Basics

The HC-SR04 datasheet is the basic resource for electrical, thermal, and physical attributes, as listed in the table below,  that should influence your choice to implement this device for your project.  

HC-SR04 Datasheet: Device Attributes
Attribute Value(s)
Power Supply +5 V (DC)
Quiescent Current <2 mA
Operating Current 15 mA
Effectual Angle <15 degrees
Range 2 - 400 cm / 1 in. - 13 ft.
Resolution 0.3 cm
Measuring Angle 30 degrees
Trigger Input Pulse Width 10 us
Dimensions 45 mm x 20 mm x 15 mm

The HC-SR04 is an ultrasonic sensor detector that can measure distances from 2 cm (0.787 in) to 400 cm (13.123 ft). Unlike infrared sensors, sunlight or black material does not inhibit performance (acoustically absorbent materials – e.g., cloths – can complicate detection). A breakout board for the sensor comes with an ultrasonic transceiver module, and the 2.54 mm header pins make for easy interfacing with a breadboard for microcontroller prototyping. The breakout board has four pins (from L to R when viewing from the board top):

HC-SR04 Breakout Board Pin Descriptions

  • VCC: +5 V DC source
  • Trig: Trigger input of the sensor
  • Echo: Echo output of the sensor
  • GND: Reference/return

To start the measurement, Trig must receive a pulsed logic-high signal (5V) for at least 10 us; after pulsing at the appropriate voltage and duration, the sensor will output eight cycles of ultrasonic burst at 40 kHz and wait for the reflected ultrasonic burst. When the sensor detects an ultrasonic burst from the receiver, it sets the Echo pin high and delays the distance from the reflection proportionally. By measuring the pulse width duration, 

Time = Echo pulse width (in us)

the distance to the reflected surface can be easily determined.

  • Distance in centimeters = Time / 58
  • Distance in inches = Time / 148

Connect the ground pin before VCC to prevent damage to the HC-SR04 device. The detection surface should be 0.5 m2 or greater in area for best results. 

Applications for an ultrasonic sensor detector include:

  • Car distance sensors – While backup cameras tend to dominate modern vehicles, distance sensors can act as a “last line of defense” by alerting drivers when they’re 0.3 m (approximately 1 ft.) to the closest surface. 
  • Liquid level detection – For greater accuracy, the HC-SR04 positioned above a pipe perpendicular to a liquid reservoir can prevent unstable readings due to surface waves, bubbles, etc.

HC-SR04 Code Implementation

Programming for the HC-SR04 is straightforward, using any microcontroller with a digital readout. The code to manipulate the HC-SR04 will differ according to the language, but developers should consider the basic structure of the code blocks:

  • Declarations – Set up variables for the Trig and Echo pins; these data types must be writable at high and low logic levels.
  • Initialization – Start serial communication and set Trig logic low.
  • LoopTrig will alternate between logic high and low levels, sandwiching a short delay. The trigger oscillation will continue while the sensor determines the distance to the incident surface.
  • Conditional – The console prints an error message if the duration (measured as a timing delay) exceeds the sensor’s maximum operating distance. If the duration is within the sensor’s operating distance, it converts the value to the desired units and prints it to the console.

Ultra Librarian Accelerates Product Development

The HC-SR04 datasheet provides the basic functionality and circuit characteristics necessary to create an effective design with the device for ultrasonic sensing. The advantage of the HC-SR04 (and other similar sensor breakout boards) is the ability to prototype rapidly with breadboards (and more customized prototype boards). When time is of the essence during prototyping revisions, Ultra Librarian’s verified library containing millions of component footprints, schematic symbols, and simulation models can free up workflows while maintaining manufacturability. Best of all, getting started with Ultra Librarian is free.

Working with Ultra Librarian sets up your team for success to ensure streamlined and error-free design, production, and sourcing. Register today for free.

UL-Icon.png

The Ultra Librarian Team

Ultra Librarian offers the world’s largest PCB CAD library, putting cutting-edge materials at your fingertips so you can build better products faster—all for free.

Join Our Newsletter

Subscribe to our newsletter to receive the latest news, and important updates

Name(Required)

Related Posts

If you’re looking for any of our component footprints or models, we have readily available and free options for you and your design team. Search our library for the solution you’ve been looking for.

IC Manufacturers

Working with us allows you to target the right audience for your component, provide content to nurture them along their design process, and analyze how your parts are being received and used.

Electronic Component Industry Trends 2024

Download Now to read more about the most impactful drivers of IC component innovation.

Part Details

Pricing by

Free Design Resources

Ultra Librarian is the worlds largest online – and always free – PCB CAD library. Build products better, faster, and more accurately with easy access to vendor-verified symbols, footprints, and 3D models. Register today to start searching the right components for your next design.

Recommended