Sonar Distance

How can you get the exact distance on a sonar? Thanks.:mad::confused:

You probably should tell us which computer language youโ€™re using. RobotC? EasyC? or what?

For RobotC:

In Motors and Sensors setup wizard, you pick what units of measurement you want your values to read in (I believe the options are in, cm, or mm).

Possible commands/uses:

//this returns (I believe) an integer value from the sensor
//note that it is not an actual command, it is just a number.

//to actually use it, you could do things like
//assign it to a variable:

int distanceFromSensor = 0; //declare and initialize
distanceFromSensor = SensorValue[ultrasonicSensorName]; //assign
the current value of the sensor to distanceFromSensor

//how about a logical test?
if(SensorValue[ultrasonicSensorName] < 5)
   //do something if the sensor value goes below 5 (whatever
   // units you selected in the wizard)

Hope this helps you. If not, anyone else can see it and maybe be helped by it.