UNO pin number as used by the software ??

As you go around the UNO board it is obvious that the digital I/O (Do to D13) is number 0 to 13 when using the DATA I/O in the software. What do you use for all the rest of the pins, like the Analog Inputs A0 to A5 and all the other pins on the board?

Do you just use A4, for example or ????? Are the pins just labels and not integer numbers?? I see nowhere in any documentation I have reviewed where this is clearly spelled out. I most certainly could have missed it as a newby to this board.

LDBennett

As in the examples A0-4 (A0-5?) are the analog inputs. The other pins are things like power so that should be obvious, and the AREF pin, but that's for another day.

If you're using digitalRead or digitalWrite, then you would use A0, A1, etc...

If you're using analogRead, then you would use 0, 1, 2, etc...

Aside from digital and analog pins, what other pins are you referring to?

No others. That's it.

LDBennett

LDBennett:
As you go around the UNO board it is obvious that the digital I/O (Do to D13) is number 0 to 13 when using the DATA I/O in the software. What do you use for all the rest of the pins, like the Analog Inputs A0 to A5 and all the other pins on the board?

Do you just use A4, for example or ????? Are the pins just labels and not integer numbers?? I see nowhere in any documentation I have reviewed where this is clearly spelled out. I most certainly could have missed it as a newby to this board.

LDBennett

The Arduino.h (or WProgram.h in older versions) that is included by the IDE defines constants for A0, A1, A2, A3, A4, etc. that are appropriate for the machine you are compiling for. Version 1.0 defines:

  • A0-A7 to be 14-21 for most targets,
  • A0-A11 to be 18-29 for the Leonardo.
  • A0-A16 to be 54-64 for the Mega.

Serial.println(A0)

:wink:

you can also refer to the analog pins as digital pins..

also target them as:

pinMode(14, INPUT);
digitalWrite(14, HIGH);.

etc
etc

If you're using digitalRead or digitalWrite, then you would use A0, A1, etc...

If you're using analogRead, then you would use 0, 1, 2, etc...

If you're using digitalRead, digitalWrite or analogRead on the A0..Ax pins, then just use A0, A1 etc.
It is made to be simple and consistent.

xl97:
you can also refer to the analog pins as digital pins..

also target them as:

pinMode(14, INPUT);
digitalWrite(14, HIGH);.

etc
etc

IIRC, that works for the standard UNO A0-A5 pins. I believe some of the higher analog input pins on some platforms don't work as digital pins.

Note, you do not want to use 14. You want to use A0, otherwise if you swap your UNO for a Leonardo it won't work as A0 is 18 on Leonardo. Similarly on the Mega, A0 is 54. Use A0..An that Arduino.h (or WProgram.h) provides.

I believe some of the higher analog input pins on some platforms don't work as digital pins.

That's correct - even on the Nano, A6 and A7 are analogue inputs only.

pinMode(14, INPUT);
digitalWrite(14, HIGH);.

Huh?

why would you configure the pin as input then write to it?

ardnut:

pinMode(14, INPUT);
digitalWrite(14, HIGH);.

Huh?

why would you configure the pin as input then write to it?

To enable the built in pull up resistor