analogRead different value with direct pin number and variable


I have a problem here, when I giving a dc voltage to A1, from 0v to 5v slowly and then use analogRead command to get values:

  1. Serial.print(analogRead(A1)); // the values are correct 0V=0, 5V=1023.

  2. char[] pin="A1"; analogRead(pin); // the values always 5-20% lower than analogRead(A1) return values, and not linear.

why and any suggestions?

Thank you very much.

analogRead takes a uint8_t, not a string. Turn up the level of warnings if you haven't already and the compiler will tell you about it.

Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR,148850.0.html.

Can you post your code please.

Thanks.. Tom.... :)

What you wanted was:

const byte Pin = A1;
void setup()

void loop() {}