PROXIMITY SENSOR

So a while a go I hooked up one of those sharp proximity sensors to my arduino. I ran a digital read, it went well... when i put my hand infront of the sensor the number got lower but when i moved my hand further the number got higher. Now when I hook it up the numbers change randomly and they only change a few numbers (up or down). I tried many things and i could not figure it out. The weird thing is that when the sensor is not even connected (or anything for that matter) the numbers still appear. Any ideas? this is the code int sensorPin = 1; //analog pin 0

void setup(){ Serial.begin(9600); }

void loop(){ int val = analogRead(sensorPin); Serial.println(val);

//just to slow down the output - remove if trying to catch an object passing by delay(100);

}

int sensorPin = 1; //analog pin 0 Is that right?

How about: int sensorPin = 0; //analog pin 0

I ran a digital read, it went well... when i put my hand infront of the sensor the number got lower but when i moved my hand further the number got higher

You ran an analogue read, I suspect you meant.

The weird thing is that when the sensor is not even connected (or anything for that matter) the numbers still appear. Any ideas?

That's a floating pin, and there is nothing weird about it.