Code For Sharp 2Y0A02 distance sensor

I'm a beginner in this. I recently got my self a sharp 2Y0A02 distance sensor. Can anyone give me the code to at least print out the distance in the serial? I have tried it and failed, I have no idea whether the sensor is spoiled or I just suck.

Try this simple loop.
I found my numbers using linear regression. For better results, the funtion may be split onto two.
You can also use a lookup-table and do interpolation.

void setup()

void loop()
int val=analogRead(A0); // read the sensor