Analog read isn't working (noob)

Arduino Diecimila (ATmega168), IDE 1.6.1.

A real simple sketch to read the analog input from a potentiometer.

I've connected the 2 outer terminals of a pot to 5v and ground, and the center (wiper) of the pot to A0. The input pin (the solder joint on the Arduino A0 pin) measures from 0-5v with reference to ground as I turn the pot fully.

I'm not getting any variation of the timing of the LEDs. The LEDs flash at a fixed rate (as if I used a delay of 1000) no matter the position of the pot. I can put integers in place of "Speed" and vary the timing by changing this value.

What am I doing wrong?


  int RledPin =  11;
  int YledPin =  12;
  int analogPin = 0;
  int Speed = 0;

void setup()   {                
  pinMode(RledPin, OUTPUT); 
  pinMode(YledPin, OUTPUT);
void loop()                     
  Speed = analogRead(analogPin);
  digitalWrite(RledPin, HIGH);
  digitalWrite(RledPin, LOW);
  digitalWrite(YledPin, HIGH);
  digitalWrite(YledPin, LOW);

Try int analog pin = A0;

Thanks for your suggestion.

int analog pin = A0;

No change.

I tried connecting the pot to each of the 6 analog input pins and changing the int statement accordingly.

No joy.

Discovered the problem.

I have a Sparkfun Protoshield on my Arduino Diecimila board. The Protoshield has the analog pins labeled A0 through A5 with A0 closest to the corner of the PCB. Apparently this is incorrectly labeled. I was watching a video on YouTube about Arduino and saw a close-up of the Arduino and Eureka!, A5 is closest to the corner.

I plugged the pot into the pin labeled "A0" and changed the sketch to analogRead(5) and it works!

The Protoshield I have is many years old (4 or 5?). It's not red like the current ones are from Sparkfun but green. I checked the current Protoshields at Sparkfun and the analog pins are labeled correctly.

I'll post a close up photo below.

So I have a mislabeled board. Good to know...finally!


Here's a photo of the incorrectly labeled Protoshield (on top) and the Diecimila (below):


Note the different pin numbers on the two boards.

It pays to take NOTHING for granted. Especially in programming.