Finding distance using Ultrasonic Distance Sensor

Hi everyone! I am currently doing my final year project. I am a little confused on the part that I found online by finding the distance between an ultrasonic distance sensor(PING))) Sensor) and an object. I do not really understand how to the microsecondsToCentimeters method works. Because by finding the distance of sound, I can use the formula, distance = speed * time / 2. But microsecondsToCentimeters seems to use another way to get the distance. Can someone explain the concept of the method to me? *Just a little confused here... Thanks! The codes are as follows:

int sensor = 27;

void setup() {

void loop() {
  long duration, distance;

  pinMode(sensor, OUTPUT);
  digitalWrite(sensor, LOW);
  digitalWrite(sensor, HIGH);
  digitalWrite(sensor, LOW);

  pinMode(sensor, INPUT);
  duration = pulseIn(sensor, HIGH);

  distance = microsecondsToCentimeters(duration);



long microsecondsToCentimeters(long microseconds) {
  return microseconds / 29 / 2;

Distance = time / speed / 2.

Distance = time / speed / 2.

Thanks for the reply. But why do I use this calculation instead of using distance = speed * time / 2? What's the difference between them?

One is correct, yours not... multiplication vs division.