We are still shipping! However, order processing may take longer than usual and we cannot guarantee same day shipments due to staffing guidelines from the CDC. Please see all COVID-19 updates here. Thank you for your continued support.

Member #688825

Member Since: June 4, 2015

Country: United States

  • The last diagram in the datasheet is essentially a linear correlation between the sensor's output voltage (on the y axis) and 1/L + .42 (on the x axis), where L is the length in cm. In the form y = mx + b it has an m of about 12.7. Solving for the length gives L = 12.7/V - .42, in cm. On a 5V Arduino with 10-bit ADC conversion, V = 5 x (analogReading/1023). So you can substitute V and crunch a few numbers to get a nice little conversion formula:

    int reading = analogRead(sensorPin);
    reading = max(1, reading);  // avoid dividing by zero!
    float cm = (2598.42/reading) - .42;

    I found that this gave very good results, and the calculation is simple and fast. Hope this helps others using this sensor!

No public wish lists :(