Track My Order
Frequently Asked Questions
International Shipping Info
Mon-Fri, 9am to 12pm and
1pm to 5pm U.S. Mountain Time:
Chat With Us
June 4, 2015
about 5 years ago
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 :(