Ultrasonic sensor - Please Help :(

I’m using arduino UNO, I did a program in which I use an ultrasonic sensor (“SR-04 Ultrasonic Ranging Module Hc - Sr04 for Arduino”) (which measures the distance) and a buzzer. I can provide you the fritzing diagram and code.

Now, my Sensor is attached on the breadboard. When I open the Serial Monitor, It gives me the values as I want,

but the moment I rotate it ( on the desk - different direction) The values start to differ like fluctuation from 210 to 0 to 208 again , this zero for a second creates the problem with the buzzer.

The buzzer beeps at that time. after Every 3 to 4 values, this zero comes. I tried cleaning the sensor , but nothing worked, When I attach these things to a stick, the sensor gives this problem. So What can I do ?]

Find the photo of the serial monitor’s difference from the attachment.

Add code to ignore zeros, or use the NewPing library and its median method.

I don't have good experience with the sr04. I had the same problem and I just choose to ignore the zero readings in the code.

DaveEvans: Add code to ignore zeros, or use the NewPing library and its median method.

I changed the code, and the buzzer was blank, so I added an if function that if distance==0 then (the original function). Thank you, My Problem is solved.

DaveEvans:
Add code to ignore zeros, or use the NewPing library and its median method.

And I discovered one more thing that when the sensor at different angle, like 60 degree , the serial montior gives values fast, when its facing towards 0 degree, the serial monitor goes slow ? Why ?

When the distance is short the update frequency is high as the results come in fast. If the distance is greater than can be measured (or for some other reason no echo is received), it takes time for the device to time out and the results come in slow.

I had a similar problem when first testing my ultrasonic distance sensor. I believe I made an error with the trigger pulse - it was sending a trigger for too long. Could also be a problem with long/unsigned long/float numbers