Been working on a robot recently which uses ultrasonic sensors for an integral part of the navigation. While testing the sensors I noticed a strange behaviour, the sensors seem to frequently stop functioning and bring the entire Arduino Mega I'm working with to a stop. The strange part is that these stops seem to be entirely random, on some occasions the sensor will read values consistently (at maybe 20 vals per second) for 10+ seconds, then all of a sudden the sensor will slow to reading only 2-3 values per second with stalls between.
I have tested several sensors and different codes for pinging distances yet the problem has persisted.
This leads me to believe the issue is with the arduino mega itself, but I am unsure how to verify this. Any advice? Thanks in advance!
PS: other pins on the Mega seem to be working fine, i.e. analog pins for IR reflectance sensors and PWM pins for driving 2 DC motors.