Converting IR value to distance

  1. You are reading an analog voltage value so the Arduino will be quite sensitive to the voltage you supply it unless you are using a Aref voltage (which is not in your code). Are you sure you have stable voltage (5v from your conversion factor) power supply? Actually measure the voltage using a voltmeter of you are not sure. My experience with the supply through the USB connector has not been good, varying from 4.2 to 5V.

  2. An alternative approach may be to use a table of values (or a case statement) indexed on the voltage returned by the and interpolate between the two closest values in the table supplied in the data sheet. Over a short span of the graph you can probably assume a linear interpolation will be accurate enough.