Arduino Forum

Using Arduino => General Electronics => Topic started by: kaare_t on Sep 26, 2016, 10:00 am

Title: Ultrasonic distance sensor sometimes reports wrong distance
Post by: kaare_t on Sep 26, 2016, 10:00 am
Hi all,

I have a question regarding an ultrasonic distance sensor. I have it working fine, however sometimes it reports a shorter distance than what is expected. This only happens occasionally. I suspect some electrical noise to trigger the input pin, but I am not sure. At the moment I have connected the ultrasonic sensor directly to the Arduino using +5VDC (powered directly from the Arduino board), 0V (directly from the Arduino board) and the signal wire (IN/OUT) directly to the Arduino board. I have no other electronical components installed (no capacitors or resistors).

Note that I use an ultrasonic sensor from seedstudio (SEN136B5B). This sensor use the same wire for both input and output signal. I am switching my pin in the Arduino accordingly, and as mentioned most of the time I'm getting a correct distance - occasionally the returned distance reports a value too low (input pin is triggered too early).

Should I use any other electronical components to avoid getting signal noise on the input pin? If so, what to do?

Thank you very much for any tips.
Title: Re: Ultrasonic distance sensor sometimes reports wrong distance
Post by: AWOL on Sep 26, 2016, 10:17 am
Sometimes you can get unexpectedly short ranges if you "ping" too frequently and don't allow returns from distant objects to die away.
Title: Re: Ultrasonic distance sensor sometimes reports wrong distance
Post by: jremington on Sep 27, 2016, 06:18 am
False reports can occur if there is ultrasonic noise in the environment, and you won't hear it.

Ultrasonic sensors are not particularly reliable and you may have to reject some measurements, for example if they disagree substantially with other recent measurements. Try taking the best two out of three, similar to a moving average.
Title: Re: Ultrasonic distance sensor sometimes reports wrong distance
Post by: kaare_t on Sep 27, 2016, 09:38 am
Great feedback! Thank you very much, will take a closer look at my code (according to both posts).