HC-SR04 ultrasonic sensor and pulseIn function

Hi All,

So I'm still pretty new to Arduino but am enjoying learning what it can do and the programming behind it. One thing I'm tying to wrap my brain around is why the pulseIn function works for the ultrasonic sensor..

At first, what I understood is that a short 10us signal is sent to the sensor to trigger the short pulse that gets sent by the transmitter (let's say, at time=0). At this same time, the receiver is sending a LOW signal to the echoPin. which sees LOW. The pulse travels to an objet, gets bounced back, hits the receiver, and now it is HIGH and the pulseIn command starts timing, and measures how long it is HIGH at the echoPin. This however, is counter-intuitive to what I would think, because it is only measuring the signal of the pulse, and not the time it was actually travelling from the transmitter to the receiver.

Since I know the pulseIn command works for this while measuring the HIGH signal, the only thing I can figure is that at t=0 when the signal leaves the transmitter, the integrated circuit in the sensor at the same instant, sets the receiver signal to HIGH, and the echoPin is reading HIGH right away. Then when the signal gets received at the receiver, the integrated circuit makes the signal LOW to the echoPin and hence the pulseIn receives a LOW signal. Hence, the pulseIn will read the signal HIGH for the time the signal travels, then LOW when it is received by the receiver of the sensor.

Can someone please confirm if my reasoning is correct?
Thanks!
Ron

Maybe this page will help you to understand how the rangefinder works.

Hi groundFungus,

yes that's an excellent website providing a good visualization of the HIGH signal from the receiver. I guess I was pretty much correct in my assumption.

Thanks for the response!

Stay safe,
Ron