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");
}
asked Jun 8, 2015 at 15:55

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.

answered Jun 8, 2015 at 16:00
1
  • 1
    Thank you! I knew it must be something stupid I'd overlooked. Commented Jun 8, 2015 at 17:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.