mBot Ranger (MeAuriga board) ultrasonic sensor is stuck at 400


#1

Hello everyone!

I know that there are a lot of topic oriented to this problem, but I did not find any solution in these topics.
I am using the Arduino IDE to program my Ranger.
So here is the case: If I want to read the output of the ultrasonic sensor (ultraSensor.distanceCm()) in the main loop, then everything is ok, it works. But when I want to read in a function then it stucks at 400.00. I tried to change ports, I tried all of them, and only the PORT_6 seems to work (in the above mentioned manner). I changed several cables (RJ25 cables), I updated the firmware several times, but it does not works.
Any suggestion would be helpful!


#2

Please post your code. :slight_smile:

This code works fine on my Ranger with the Ultrasonic Sensor in port 10.

#include <MeAuriga.h>

const int US_PORT = 10;

MeUltrasonicSensor ultrasonic(US_PORT);

void displayDistance() {
  Serial.println("Distance in cm: " + String(ultrasonic.distanceCm()));
}
void setup() {
  Serial.begin(9600);
}

void loop() {
  displayDistance();
}