It is possible to use more digital terminals (pins) on the Arduino Uno and Mega 2560 boards, in addition to those indicated on the board, transforming analog inputs (A0, A1, A2...) into digital inputs or outputs.
For Arduino Uno, just use the following numbers for each of the analog terminals:
- A0: 14
- A1: 15
- A2: 16
- A3: 17
- A4: 18
- A5: 19
For example, the code:
pinMode(14, OUTPUT);
digitalWrite(14, 1);
pinMode(15, INPUT);
Make the A0 terminal turn into a digital output, and write 1 to it. Finally, it also transforms the A1 terminal into a digital input (to be used with digitalRead).
Already for the Arduino Mega 2560:
- A0: 54
- A1: 55
- A2: 56
- A3: 57
- A4: 58
- A5: 59
- A6: 60
- A7: 61
- A8: 62
- A9: 63
- A10: 64
- A11: 65
- A12: 66
- A13: 67
- A14: 68
- A15: 69
So in the Arduino Mega 2560, the code:
pinMode(69, OUTPUT);
digitalWrite(69, 1);
pinMode(54, INPUT);
It turns the A15 terminal into a digital output, and writes 1 to it. Finally, it also transforms the A0 terminal into a digital input (to be used with digitalRead).
Analogue terminal names can also be used instead of numbers if desired. So, both in the Arduino Uno and in the Arduino Mega 2560, the code:
pinMode(A0, OUTPUT);
digitalWrite(A0, 1);
pinMode(A1, INPUT);
Make the A0 terminal turn into a digital output, and write 1 to it. Finally, it also transforms the A1 terminal into a digital input (to be used with digitalRead), as noted by @carlos-Delfino.
I hope it helps those in need of more inputs or extra outputs in the projects!
Well remembered! I will add this information to the answer.
– carlosrafaelgn