How does an ultrasonic distance sensor work?

My thoughts:

A microcontroller (Arduino nano) sends a signal to an amplifier that makes it into a 40kHz pulse, which then goes to the transmitter which sends it out. After some time the receiver get the pulse, where it runs it though an op amp (because of the loss in air?) and then sends it back to the Arduino.

If this is true, how does the Arduino / microcontroller convert this information into time?

  • \$\begingroup\$ "Some time" is linearly related to how far away the object reflected off with. \$\endgroup\$ Feb 28, 2019 at 11:57
  • \$\begingroup\$ How about watching some tutorials? For instance howtomechatronics.com/tutorials/arduino/… > how does the Arduino / microcontroller convert this information into time? With the sensor from the example above: Using an edge sensitive timer: Start counting when the rising edge occurs and stop at falling edge. <br> \$\endgroup\$
    – mic
    Feb 28, 2019 at 12:08
  • \$\begingroup\$ Try reading this document from NXP. It explains how it works, and gives flow charts and program code for a specific microprocessor. Once you've got some idea what is going on, you can ask better questions about the details of how it works - and use the diagrams to illustrate the points you need help with. \$\endgroup\$
    – JRE
    Feb 28, 2019 at 12:25

1 Answer 1


Some US sensors send a continuous sinus signal, that is therefore reflected and received by US sensor. Due to the fact, that signal needs some time to travel, the received sinus will be phase-shifted.

enter image description here

Consider red sine wave as transmitted signal and blue sine wave as received. They are shifted related to each other.
This phase-shift can be computed using autocorrelation.

Other sensors may send single pulses and then calculate the difference between transmitted and received time. Then the distance can be computed as follows:

enter image description here

where v is the speed of sound. Computed distance is divided by 2 because the sound had to travel from the sensor to the object and then back from the object to the sensor.

  • 4
    \$\begingroup\$ The first part of your answer is way oversimplified. CW ultrasound, like CW radar, frequency-modulates the signal. The phase analysis is done on the modulation, not the carrier. Remember, the wavelength of 40 kHz sound in air is less than a centimeter! \$\endgroup\$
    – Dave Tweed
    Feb 28, 2019 at 13:07
  • \$\begingroup\$ @DaveTweed Even if it is not CW, you would still send a chirp, since it reduces the required power output quite significantly due to the bandwidth compression. \$\endgroup\$
    – user110971
    Aug 3, 2019 at 16:14
  • \$\begingroup\$ @user110971: Not necessarily. Low-cost ultrasound distance sensors wouldn't want to invest in the hardware required to process a chirp. You may be thinking of radar, where this is much more common. \$\endgroup\$
    – Dave Tweed
    Aug 3, 2019 at 19:03
  • \$\begingroup\$ @DaveTweed Yeah, I was thinking about radar. But you don’t need extra hardware to process the chirp. Just a simple ADC / DAC can be used. It does require extra engineering effort though. \$\endgroup\$
    – user110971
    Aug 3, 2019 at 19:06
  • 1
    \$\begingroup\$ The problem with the first part of your answer is that it only works if the total round trip delay and phase shift of the signal is less than 360 deg. If it's longer than that, then you have a modulo-360 problem in that a total phase shift of 20 deg looks the same as a total phase shift of 380 deg which looks the same a 740 deg, ... So you need some way of unwrapping the multiple 360 deg phase shifts. \$\endgroup\$
    – SteveSh
    Apr 4, 2020 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.