Bad Ultrasonic distance measure

  • My ultrasonic sensor reports a bad distance. For example, I measure to the ceiling of the room, and it reports 80 cm where it is above 2 meters.

    I have:

    • a Ultrasonic range sensor
    • a M5 CoreInk. The sensor is connected on GPIO 32 and 33.

    This is how I do it. Can you tell me what's wrong or an idea how to debug? thx

    #define M5_I2C_ADDR_ULTRASONIC 0x57
    Ink_Sprite InkPageSprite(&M5.M5Ink);
    void setup() {
      M5.begin(); //Init CoreInk.  
      if( !M5.M5Ink.isInit()) //Init CoreInk screen.
        Serial.printf("[-] M5Ink init failed");  
        while (1) delay(100);
      Serial.printf("[+] Wire begin done\n");
      M5.M5Ink.clear();   //Clear screen. 
      Serial.printf("[+] Clearing eInk screen\n"); 
      if( InkPageSprite.creatSprite(0,0,200,200,true) != 0 ){
        Serial.printf("[-] Ink Sprite create failed");
    void loop() {
      static float distance = 0;
      distance = readDistance();
      Serial.printf("Distance=%.1f cm\n",distance);
      if ((distance < 150) && (distance > 0)) {
          char buffer[30];
          sprintf(buffer,"%.1f cm",distance);
      // Sleep 

  • @aafortinet after more measures, the ultrasonic sensors seems to work correctly. It's just that (1) the units in my program were wrong, (2) it does not work below 2cm and above 150 and gives erroneous answer then. This range isn't very big, and typically I measured 2m.

  • @aafortinet A mate of mine had the same issue -- seemed not to work until he used it within the 2-150cm parameters. The all good.