HC-SR04 + NewPing Library: Measurement in millimeter?

I am an absolute beginner when it comes to arduino programming. I got the distance measurement to work with the help of the following sktech:


#include <NewPing.h>

#define TRIGGER_PIN 6
#define ECHO_PIN 5
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

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

void loop() {
delay(50);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm());
Serial.println(“cm”);
}

But I would like to see the result of the distance measurement in mm. Maybe someone can help me?
Thx

1 CM = 10MM

100mm = 10cm * 10

I meant a more accurate measurement than just 4 cm. For example, 39.37mm. The serial monitor only supplies numeric values ​​before the comma with the simple sktech.

Sorry, I did not get a clear understanding of your post.

Please try this and see if it helps. The call you are making, does this bit of math for you and returns as an int. This should help.
Also, please be aware that the accuracy might not be as accurate as you would like,

Temp, Humidity , altitude can all impact this.

    unsigned int uS = sonar.ping();
    float distance_cm = uS/57.0;    // The constant "US_ROUNDTRIP_CM" = 57
    Serial.print("Ping: ");
    Serial.print(distance_cm,2);
    Serial.println("cm");

core2k:
But I would like to see the result of the distance measurement in mm. Maybe someone can help me?

The accuracy of the sensor is not to the millimeter level.

The NewPing library uses the micros() function to time echo pulses. You can use sonar.ping(MaxDistanceInCM) to get the raw microsecond value as an unsigned int. Multiply by 0.344 to get the round-trip distance in mm and divide by 2 to get the one-way distance (or multiply by 0.172 directly). Because the micros() timer has a four-microsecond resolution your precision won't be any better than 0.688mm.

Who knows what precision the HC-SR04 is capable of but if you want to measure the Echo pulse with finer resolution you can use the Input Capture Register feature of Timer1. This will give you a pulse length resolution of 1/16th of a microsecond (0.0215 mm).

Don't confuse precision with accuracy.

gfvalvo:
Don't confuse precision with accuracy.

Amen...

Graphics:
figure-1.png

figure-1.png