Showing results for 
Search instead for 
Did you mean: 

Ultrasonic sensor reading stuck at a particular value after few hours of proper operation

Hemanth V


I am trying to integrate maxbotix MB1003 sensor onto Nucleo L073RZ board. Nucleo board is running mbed OS. After few hours of proper operation, ultrasonic readings get stuck at a particular value like 420 mm. Sensor operation is simple triggered operation, have attached sample code below. Can anyone point out what could be the possible cause.



Timer sonar;

 int sonar_checkdist()



    trigger = 1;



    trigger = 0;

//wait for echo high

  while (echo==0) {};


//echo high, so start timer


//wait for echo low

 while (echo==1) {};

//stop timer and read value


//subtract software overhead timer delay, scale to cm & roundup

 distance = (((sonar.read_us()-correction))/10.0) + 0.5;


 return distance;



Work backward, put a scope on the sensor analog output, or use other interfaces, and confirm if the sensor is the source of the measurement, or if there is some issue on the software side.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..