NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

wrt floating point, keep the code in the integer/long range. Optionally do the math in millimeters (multiply all with 10) and bring it back to cm in the end (divide by 10) That gives higher precision without the overhead of the float. Did that in one of the conversion variations (prev post).

wrt Humidity, we discussed a year(?) ago measuring the depth of a water pit (well?). There the humidity was close to 100% so it affected the ping sensor readings to the max, so in the end the working allways depends on the context :wink:

I could also add a microsecond to cm and inch conversion where you could also specify the temperature from a temperature sensor. I do plan on sticking with using integers for basic conversions to save space and speed.

imho set the temperature seperately to choose the divider to use from a small lookup table. Temp does not change that often, so conversion time will be minimized, no need to do the lookup agaiin and again.

(snippet, you get the idea)

byte table[] = { ...,57,58,59,60, ...}
div = 58; // default
rnd = div/2;  //rnd is short for rounding

setTemperature(int F)  
{
  F = F/20;
  div = table[F];
  rnd = div/2;
}

unsigned int convert_cm(unsigned int echoTime)
{
  return (echoTime + rnd)/ div;
}