Huge spikes in HC-SR04 ultrasonic sensor reading

Hi

I am testing HC-SR04 ultrasonic sensor using Arduino Mega. It is to be used on a Quadcopter for measuring distance from below.

The sensor gives roughly correct values mostly but sometimes it gives readings of about 1200cm for a few intervals. The spikes happen when I move some solid object in front of the sensor, gradually bringing it closer or farther. When something static is placed in front of it, then there are no spikes.

Here is my circuit:
my_circuit - Album on Imgur?

Here is my code:

Here is one such reading:
Imgur

Can someone please help me find out what is causing this problem and how do I fix it?
Thank you.

Do post your code and other info here as per forum guidelines.

How frequently do you take readings?

wvmarle:
Do post your code and other info here as per forum guidelines.

How frequently do you take readings?

I take real-time readings using the serial port. The ones you see attached in the post are for a few seconds only.
I am sorry about not posting as per guidelines.

If you take readings less than ~50 ms apart the sensor may get confused by echoes of previous readings. Give echoes time to die out.

More members will see your code if posted properly. Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags. If the code is too large to post it can be attached.

It is much better if you post the images so that we do no have to download them. See
How to post images.

An Ultra sonic sensor like the SR04 does not do the thing well when being moved during a reading. Something about a doppler thingy happening.

I never experienced this really, moving the sensor by hand. At that kind of speeds (no more than 1 m/s or about 0.3% of the speed of sound) doppler shift should not be an issue - no way those transducers are that specific.

You should begin testing by running all the motors and props. Likely the props will produce ultrasonic noise that will mask the sensor pulse. Also the air turbulence will disport any echo.
Paul

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.