Sharp IR Range Sensor always returns 0

Hey guys!

I have one of these sharp IR range sensors:

I have it connected to pin A0, 5v and gnd and I wrote a sketch to read the analog input but sometimes the serial prints 0 and other numbers with little consistency. I am going to assume user error since this is my first time mounting a sensor. But can't seem to fig out what is wrong.

int sensorPin = A0;    // input pin for the IR sensor
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup(void)
{
  Serial.begin(9600); //set baud rate
}

void loop()
{
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue, DEC);
  delay(1000);
}

Any ideas why it is not reading the correct values?

Code looks good, got schematic or good photo of wiring?

Shematic: http://www.dfrobot.com/wiki/images/a/a0/RoMeo_Schematic.png

picture:
http://216.252.110.31/us.f569.mail.yahoo.com/ya/securedownload?fid=Trash&mid=1_3571_AF5hxEIAADhUTTdgAQoW00xm2sE&pid=1&tnef=&YY=1295477237385&newid=1&clean=0&inline=1&cred=sPY9anQ.3VahCdMA3peU7c3S5Ien4luLNavT0YZVsqKr2lIGH9mirbHqNe0dRh3iW2mS53H.dXrKOBQOGQmarVDAT9EHFRIktGdhJAxDkAc7h36B&ts=1295477256&partner=ymail&sig=ijlHDzomMazxfCTHOkkLwQ--

From L to R on the sensor the colors are yellow, black, red. I have the yellow in the A0 pin, the black in the gnd and the red in the 5v.

picture:

Try:

sensorValue = analogRead(0);

A0 is a predefined constant (or macro?) and you have assigned an int of the same name, I am not sure that will work correctly? Easy to try just a 0 and see.

Lefty

I had to use A7 for the input pins when I was programming my analog buttons on the same controller (different project) so I assume I'd use the same format for these analog buttons.

Nope it gave me this.
78
55
53
50
31
60
69
67
61
51
42
40
36
54
70
70
61
43
27
32
33
55
68
67
64
53
45
38
48
58
69
70
63
56
59

Nope it gave me this.
78
55
53
etc

That may be normal for your sensor/wiring setup. Wire a jumper from ground to analog pin 0 and run your program, do you get a steady 0? Then wire it +5vdc, do you then get a steady 1023?

Lefty

Turns out my wiring was actually wrong. There are two gnd pins with only one ground label so I had my 5v in the other ground.

ugh. Thanks anyways guys! I appreciate it.

McK