The HC-SR04 ultrasonic distance sensing module

Placed on
ultrasonic module ultrasonic module

How is the distance calculated?

The SR04 uses the principle of sound reflection. The module sends out a sound pulse of 40 kHz and waits for it to be received.

The time between sending and receiving this sound signal can then be used to calculate the distance. The speed of sound through air is about 340 meters per second or

The time between sending and receiving must be divided by 2 because the sound signal has traveled 2 times the distance to the object (there and back).

With this data, the distance can be calculated using the following formula:
Distance(cm) = T(µs) * 0.034 / 2
Ultrasonic sensor function Ultrasonic sensor function
Ultrasonic module timing diagram Ultrasonic module timing diagram

How does the SR04 module work?

The module contains 2 separate ultrasonic sensors with the necessary electronics to send and receive the sound pulses.

When a start pulse (10μs) is given by a microcontroller, the module will send 8x a pulse of 40kHz and then listen for an echo.

From this moment the output pin of the module will give a high signal, which will go low again when an echo is received. To prevent later echo signals from interfering, it is advisable to wait at least 60ms until the next measurement.

Arduino code voorbeeld


The HC-SR04 object detection is a very handy module, where you can measure the distance to an object with a few lines of code. This makes it possible to make non-yet switches or to scan the environment with a robot. The measuring range is also increased by using a servo motor and a bracket to hold the module in place.
HC-SR04 Ultrasonic distance detection moduleThe HC-SR04 module measures distance to objects by means of ultrasonic reflection. This is done by firing pulses of 40 kHz to the environment, after which the time required to receive the reflected signals is measured. In stock € 3,25
Ultrasonische sensor mount transparantSensor mount for attaching the HC-SR04 ultrasonic sensor module. In this way the sensor can easily be mounted on a base or servo. By placing this bracket on a servo motor, it can be used as a sonar on a robot car, for example. In stock € 2,50
Posted by Website I am interested in electronics, programming and especially the combination between them. For Opencircuit I write blogs in which I explain how electronics and modules work.


Webwinkelkeur Kiyoh Trustpilot Opencircuit