gp2y0a710k - Getting strange readings

Hey everyone,
I want to use the voltage results of a Sharp IR Sensor GP2Y0A710K and use the voltage readings to drive how a light blinks. During testing I am getting some strange output to the Serial Monitor. Using the code below the numbers tend to stay at the 130 then drop down to Zero when I move close then back up to the 130s and stabilize there. Looking at the other topics on the forum it looks like when working correctly the serial output should follow the curve and give a farily consistent result depending on the distance.

Thanks for your help.

#define sensorPin 0

int sensorValue = 0;
// this is called on startup
void setup() {

beginSerial(9600);
pinMode(sensorPin, INPUT);

}

void loop() {
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue );
Serial.print(' ');

}

U run the sensor from 5V ?
White surface 1m from sensor shall give you a raw reading of ca. 500
Try a short delay between radings (eg 20ms)

Yeah I am running it off 5V.

My readings look like this:
130
131
132
129
130
130
131
50 (When I move forward they drop)
21
20
20
21
19
45
130 (Even if I haven't moved)
131
130
132
129
...

which direction is forward - relative to sensor ?
note: Sharp GP2Y0A710K Distance Sensor (100-550cm)

I cannot explain those enexpected readings.. sorry

Towards the sensor is when the number drops. As in when I reduce the distance from 2m from the sensor to 1.5m from the sensor.

In your code, shouldn't

#define sensorPin 0

be changed to

#define sensorPin A0

? (pin 0 is digital and used for serial communication to the PC)

Link with code you could try:
http://www.dfrobot.com/wiki/index.php?title=Sharp_GP2Y0A710K_Distance_Sensor_(100-550cm)_(SKU:sen0085)

Pin 0 here was changed to A0:

/*Description: sharp 2Y0A710K distance ranger.(Range from 1m to 5.5m.)
This code prints out data of valid range.
However, if we put ranger very close to objects, we will have completely wrong results.
The error is inevitable because of electric character of this device.
So the only way of correct use is to make sure the distance of objects  not close to the ranger. (1m to 5.5m.)
Another tip: it is not very precise. So it is fit for detection,but not for measurement.

Tested by Michael from DFrobot
2012/2/13*/

/*Principle of this ranger: (See details in datasheet.)
Voltage is linear to the inverse of distance. (Distance range is 1m to 5.5m)
Two reference points:
Analog Voltage(V)   Digital value(0-1023)    Distance(cm)
  2.5                512                     100
  1.4                286                     500
Then, we have a linear equation of digital value and distance.
(512-sensorValue)/(1/100-1/distance)=(512-286)/(0.01-0.002)
=> distance=28250/(sensorValue-229.5);
*/
void setup() {
  Serial.begin(9600);

}
int sensorValue;
int distance;
void loop() {

  sensorValue = analogRead(A0);
  if (sensorValue >= 280 && sensorValue <= 512) //Corresponding distance range from 1m to 5.5m
  {
    Serial.print("The distance is: ");
    distance = 28250 / (sensorValue - 229.5);
    Serial.print(distance);
    Serial.println("cm");
  }
  delay(200);
}