Using the built in firmware for the mbot ranger the ultrasonic sensor works fine. When I try using my own code it only returns a value of 400. As a test I put this code in the setup routine and tried moving my hand close to the sensor but the value never changes.
float distance=0.0;
MeUltrasonicSensor *us = NULL;
if(us == NULL)
{
us = new MeUltrasonicSensor(3);
}
else if(us->getPort() != 3)
{
delete us;
us = new MeUltrasonicSensor(3);
}
while(1)
{distance = distance = (float) us->distanceCm();
Serial.println(distance);
delay(1000);
}