analogRead problem

I own a Modern Devices BBB and I'm having troubles reading an analog values from a pin.

The problem: I get an almost constant values from analogRead() no matter what voltage I input to the pin. I always get a value around 400.

The code I'm using:

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read
int oldVal =0;
void setup()
{
  //pinMode(analogPin, INPUT); //I tried this line commented and uncommented
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin);    // read the input pin
  if(oldVal != val)
    Serial.println(val, DEC);             // send the read value to the terminal
  oldVal = val;
  delay(50);
}

The hardware: a potentiometer with its outer leads are connected to VCC and gnd, and the middle lead to pin 3. The arduino is powered by the USB cable.

Any ideas on how to get this to work?

Thanks

That sounds like the result you'd get with nothing connected to the analog input.

When you say pin 3, are you sure you mean analog pin 3 or did you accidently connect to digital pin 3?

Most importantly, check your wiring. Maybe the pot is damaged or the leads aren't as you expect. Test the pot with a meter. What is the resistance of the pot?

I was using digital pin 3. I'm so dumb :-[.

Now I know what the "A" besides those pins means! I should have read the documentation better.

Thank you for the tip, everything works fine now. :D

I was using digital pin 3. I'm so dumb :-[.

Now I know what the "A" besides those pins means! I should have read the documentation better.

Thank you for the tip, everything works fine now. :D

I have the opposite problem... because of some space issues and my own obtuseness I ended up hard wiring** (soldering) some digital control lines to the analog pins. Doh! It appears, however that I can use the analog pins by setting them as outputs (14-19) but when I tried that I was seeing some oddness. Does anyone know if there are any issues using the analog pins as digital outputs?

tx - Roy

** this is with the Boarduino - I am including it on a larger circuit board.