Sharp gp2d120

The software looks right so the problem is probably in hardware. Check your wiring. Get a multimeter and check the voltage output of the sensor to see if it changes properly (connect to Gnd, +5, and meter between the signal line and Ground). Try a different analog input pin (perhaps A0 has been damaged).