I have te same problem with my Grove Pi Ultrasonic Sensor. It has been working great since I started using at a week ago, but then yesterday it started reporting the same value over and over. I have rebooted the system several times, made sure the Raspberry Pi is properly seated, and installed a freshly charged battery pack. Nothing worked!
So, I just copied, pasted, and ran this code:
The software prints one “0” (zero) after the other.
I have been testing out the Grove Ultrasonic Sensor in your given contexts and I haven’t had any problems.
I think these symptoms indicate faulty sensors, but first I need to talk to some people who know more on this issue: at the moment it’s 4th of July and they are not in the office at the moment.
I think you both have defective ultrasonic sensors.
If you have bought the sensor from us, then please, go over to this page: https://www.dexterindustries.com/contact/
Once you get to this page, head over to General Questions and Feedback section and explain your situation and what you need to have replaced.
Someone will contact you back for further details.
On the other hand, if you have bought the sensor from a reseller / distributor, then you have to ask them for a replacement.