# How does an ultrasonic distance sensor work?

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?

• "Some time" is linearly related to how far away the object reflected off with. – Scott Seidman Feb 28 '19 at 11:57
• 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> – mic Feb 28 '19 at 12:08
• 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. – JRE Feb 28 '19 at 12:25

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. 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: 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.

• 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! – Dave Tweed Feb 28 '19 at 13:07
• @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. – user110971 Aug 3 '19 at 16:14
• @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. – Dave Tweed Aug 3 '19 at 19:03
• @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. – user110971 Aug 3 '19 at 19:06
• 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. – SteveSh Apr 4 at 12:41