0

I'm trying to read 5 analog inputs, but all the pins are reading the same as pin A0, plus or minus a couple points. I tried using pulldown resistors on all 5 pins and it made no difference. The board is a Leonardo. Thanks for any ideas/help!

void setup() {
    Serial.begin(115200);
    analogReference(EXTERNAL);
}

void loop() {
    int A0, A1,A2,A3,A4;
    delay(200);
    A0= analogRead(A0);
    A1= analogRead(A1);
    A2= analogRead(A2);
    A3= analogRead(A3);
    A4= analogRead(A4);

    Serial.print(A0);
    Serial.print(" ");
    Serial.print(A1);
    Serial.print(" ");
    Serial.print(A2);
    Serial.print(" ");
    Serial.print(A3);
    Serial.print(" ");
    Serial.print(A4);
    Serial.print("\n");
}

1 Answer 1

6
int A0, A1,A2,A3,A4;
delay(200);
A0= analogRead(A0);
A1= analogRead(A1);
A2= analogRead(A2);
A3= analogRead(A3);
A4= analogRead(A4);

Your local variables (A0 through A4) are shadowing the global variables for the pins (A0 through A4). Give your local variables different names.

1
  • 1
    Thank you! I knew it must be something stupid I'd overlooked.
    – Alisha F
    Jun 8, 2015 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.