Sharp IR sensor inaccurate readings

You could try the Pololu library.

However, in order to have accurate voltage readings, the ADC on the Classic Nano must be calibrated to the actual ADC reference voltage, which is usually Vcc and can be anywhere from 3.3V to over 5V. Which of the 6 or so "Arduino Nano" versions do you actually have?

This constant is almost certainly not correct:

  float  val = analogRead(ir)*0.0048828125;