# Ultrasonic and taking measurements

Hello,

I have an Arduino Uno and I’ve hooked up my Ultrasonic Range Finder

Using the code provided by this site to get it up and running is great, and everything is fine. I had a question about a how to convert the inches and cm to Meters and Feet. With the Feet given to me in precision like 1.4ft or 2.3ft instead of just 1ft, 2ft, 3ft. Here is part of the code:

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("ft, ");
Serial.print(cm);
Serial.print(“in”);
Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 900 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 74 / 2;
}

****Can anyone help me with rearranging / rewriting the code to make it work the way I’ve explained? Hopefully I’ve explained it well. I just want to have it measure in Meters/Feet with the Feet being a little more accurate.

Thank you so much,

Sincerely,

Davi