Notifications
Clear all

Need some help with HC-SR04

3 Posts
2 Users
0 Likes
1,214 Views
Ruplicator
(@ruplicator)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

I'm in the early investigation stages of designing an ultrasonic wind speed and direction system. This is for home hobby use and a learning project so I'm seeing if this can be done with low cost devices. What I'm looking to replicate with cheap components is something like this >>> DIY Ultrasonic Wind Sensor

I'm potentially looking at hacking the HC-SR04 with some discrete components to achieve the switching dynamics I need for the transducers. While doing research on the methods used to measure distance using the HC-SR04  I came across this site Scope Captures that shows the actual trigger, send and receive signals.

All of the code samples I have found basically measure the pulse width of the echo pulse . divide it by 2 and multiply it by a constant to get centimeters or inches. However, looking closely at the signals on the scope, once triggered the transmitter sends a 200 microsecond  ( 8 cycles of 40 Khz) signal. Once the send is complete the echo  pulse goes high and lasts until the first pulses are received back from an object.  The command "pulseIn( echopin, HIGH)" is used to measure the echo pulse. What I'm struggling with is that an accurate measurement should be performed from the start of the transmit to the start of the receive, because obviously the first pulses back are  from the first that were sent.  All the sample code I've seen leave out the 200 microseconds of the transmit phase. 

Now I know this my be splitting hairs but in my application the signal is shorted because it's not bounced, the signal will be sent directly from the transmitter to the receiver over only a few centimeters. And considering I was planning to compensate for the small changes  temperature and humidity have on sound speed this  potential added error becomes more significant.

So am I missing something here or do I need to add 200 micro seconds to the pulse measurement from the echo pulse?


   
Quote
(@jbeazy)
Member
Joined: 5 years ago
Posts: 18
 

The 200 usec is being compensated for somewhere in the device. The transmitter and receiver are not the same.  There are two "speakers" one for transmit other receive. And they may be other delays within the device.  But regardless a few simple experiments would confirm whether a 200 usec time shift is necessary.  Speed of sound @room temp is 343 m/sec which is same as .343mm/usec. .343mm/usec * 200usec /2 = 34mm.  So you could take some measurements (average many) with an object say 100mm away and 200mm away from device.  If you had to compensate you should see a ~30mm error.  Now this device is probably not more accurate or repeatable then about +/-10mm.  But a 30mm error would show up in your data. I have used these and i haven't seen that.


   
ReplyQuote
Ruplicator
(@ruplicator)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

I appreciate your response and your experience with the device. Unfortunately, I  don't have a unit to experiment with but have a couple of the HC-SR04s on order. So after they arrive I can determine if the delay is real.

After looking at the math for wind speed calculation I don't believe if the delay does exist it will make a significant impact on my particular project. Since I will be taking apposing measurements and then subtracting the two to find the difference which will indicate wind speed.


   
ReplyQuote