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. The table shows:

  • USART RX is hardware serial receive

  • USART TX is hardware serial transmit

  • Ext Int is external interrupt (followed by the interrupt number)

  • PWM TnA/B is the Pulse Width Modulation (analogWrite) output on timer n

  • MISO, MOSI, SCK and SS are SPI control signals

  • SDA and SCL are I2C control signals

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 ...

Get Arduino Cookbook, 2nd Edition 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.