Please see all COVID-19 updates here as some shipments may be delayed due to CDC safety and staffing guidelines. If you have an order or shipping question please refer to our Customer Support page. For technical questions please check out our Forums. 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 :(