Mbot ranger ultrasonic sensor stays at 400


#1

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);
}


#2

Think your port is wrong. Port 3 is a motor driver on the ranger. Try plugging it into Port 10 and running this:

#include <MeAuriga.h>

MeUltrasonicSensor ultrasonic(PORT_10);

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print("distance(cm) = "); // Print the results to the serial monitor
Serial.println(ultrasonic.distanceCm()); // Distance value from 3cm - 400cm
delay(50); // Wait 50 milliseconds before next measurement
}


#3

This document might help you further:


#4

That solved the problem, thank you.


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.