Appendix F. Digital and Analog Pins

Tables F-1 and F-2 show the digital and analog pins for a standard Arduino board and the Mega board.

The “Port” column lists the physical port used for the pin—see Recipe 18.11 for information on how to set a pin by writing directly to a port. The introduction to Chapter 18 contains more details on timer usage.

Table F-1. Analog and digital pin assignments common to popular Arduino boards

Digital pin

Arduino 168/328

Arduino Mega (pins 0–19)

Port

Analog pin

Usage

Port

Analog pin

Usage

0

PD 0

 

USART RX

PE 0

 

USART0 RX, Pin Int 8

1

PD 1

 

USART TX

PE 1

 

USART0 TX

2

PD 2

 

Ext Int 0

PE 4

 

PWM T3B, INT4

3

PD 3

 

PWM T2B, Ext Int 1

PE 5

 

PWM T3C, INT5

4

PD 4

  

PG 5

 

PWM T0B

5

PD 5

 

PWM T0B

PE 3

 

PWM T3A

6

PD 6

 

PWM T0A

PH 3

 

PWM T4A

7

PD 7

  

PH 4

 

PWM T4B

8

PB 0

 

Input capture

PH 5

 

PWM T4C

9

PB 1

 

PWM T1A

PH 6

 

PWM T2B

10

PB 2

 

PWM T1B, SS

PB 4

 

PWM T2A, Pin Int 4

11

PB 3

 

PWM T2A, MOSI

PB 5

 

PWM T1A, Pin Int 5

12

PB 4

 

SPI MISO

PB 6

 

PWM T1B, Pin Int 6

13

PB 5

 

SPI SCK

PB 7

 

PWM T0A, Pin Int 7

14

PC 0

0

 

PJ 1

 

USART3 TX, Pin Int 10

15

PC 1

1

 

PJ 0

 

USART3 RX, Pin Int 9

16

PC 2

2

 

PH 1

 

USART2 TX

17

PC 3

3

 

PH 0

 

USART2 RX

18

PC 4

4

I2C SDA

PD 3

 

USART1 TX, Ext Int 3

19

PC 5

5

I2C SCL

PD 2

 

USART1 RX, Ext Int 2

Table F-2. Assignments for additional Mega pins

Arduino Mega (pins 20–44)

Arduino Mega (pins 45–69)

Digital pin

Port

Usage

Digital pin

Port

Analog pin

Usage

20

PD 1

I2C SDA, Ext Int 1

45

PL 4

 

PWM 5B

21

PD 0

I2C SCL, Ext Int 0

46

PL 3

 

PWM 5A

22

PA 0

Ext Memory addr bit 0

47

PL 2

 

T5 external counter

23

PA 1

Ext Memory bit 1

48

PL 1

 

ICP T5

24

PA 2

Ext Memory bit 2

49

PL 0

 

ICP T4

25

PA 3

Ext Memory ...

Get Arduino Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.