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 the numbers still appear. Ant ideas? 

Is the sensor connected to the correct pin on the Arduino?

I once had this problem:

First try: worked

Second try: bunch of numbers between 300 and 600

Solution: The analog output of the sensor was connected to digital pin 1 instead of analog pin 1…

Tried that

I tried that but the weird thing is that when nothing is connected to the arduino it still spits out numbers

The Arduino will spit out numbers…

It sounds like there is a disconnect somewhere in your system; the arduino is not getting the analog value from the proximity sensor.

Can you post pictures and schematics? 

**Thanks **

I tried to secure the wire in. When i ran the sketch the numbers that came out made sence however there was the ocasional number that was completly diff from the others. Also it is not as accurate as before. Do you think this is the best I can do?

 

BTW if you would like i could post some pics…

Sounds like a loose wire

I’d find the cause, I dont think the numbers would randomly have a different number.(outlier is the fancy term used in statistics)

If its not to hard post the numbers you get and a picture or two.