Microcontroller Pin Functions

Introduction

This page explains the basic pin functions that most microcontrollers share, and offers some tips for switching from one microcontroller to another. Since the tutorials on this site are all written with the Arduino Uno in mind, and students may be using other controllers, you may need to know how to “convert” a tutorial from the controller it’s written for to your own controller. In order to get the most out of it, you should know something about electrical circuits, and what a microcontroller is and what it can do. This video might help: Hardware functions in a microcontroller

What Do All These Pins Do?

A typical microcontroller can have between 6 and 60 pins on it, to which you’re expected to attach power connections, input and output connections, and communications connections. Every microcontroller has different configurations for its pins, and often one pin will have more than one function. This combining of functions on one pin is called pin multiplexing.

Every microcontroller has names for the pins specific to its hardware, but the Arduino application programming interface (API) provides a set of names for pins and their functions that should work across all microcontrollers that are programmable with the API. So, for example, A0 will always be the analog input pin 0, whether you’re on an Uno, 101, MKRZero, MKR1000, or other Arduino-compatible board. When you connect to the pin with the same function on another board, your code should operate the same, even though the physical layout of pins is different.

Every board has an operating voltage that affects its pins as well. The operating voltage, which is the same as the voltage of the GPIO pins, is labeled below. If you’re connecting a component to a board with a lower voltage than the component, you’ll need to do some level shifting.

Pin Diagrams

Microcontrollers typically come in a variety of physical forms, or packages. Sparkfun has a nice tutorial on integrated circuit package types if you want to know more. Pin numbering on any integrated circuit, including microcontrollers, starts at top left corner, which is usually marked with a dot. From there, you count around the chip counter-clockwise. For modules like the Arduino Uno, this numbering doesn’t hold up, since the board has several pin headers. The pin headers are usually numbered, and the pins of each header are counted. Unfortunately, header numbering does not always follow the same patterns as IC numbering.

Arduino Uno

Here’s a diagram of how the Arduino Uno’s pins are multiplexed. A text chart of this diagram follows the image:

Pin diagram of the Arduino Uno, showing which pins perform which functions.

The Uno has a second microcontroller on board to handle USB-to-serial communications. This is the ICSP header for that microcontroller.

Serial: Serial is attached to pins 0 and 1, and to the USB-Serial micrcontroller on board.We’re going to issue a more formal “application note” to explain some of the new features provided by this pin. For now just treat it as one extra pin available for you to use. Enjoy your Arduino Zero

Arduino MKR Series

Here’s the diagram for the Arduino MKR boards, like the MKRZero, MRK1000, and so forth. The pin numbering follows the pattern of a typical integrated circuit as described above; pin 1 is on the top left, and pin 28 is on the top right:

Pin diagram of the Arduino MKR-format boards.

Arduino MKR Series Pin Chart

A listing of the Arduino MKR series' pin functions.

Pin Label

Location

GPIO

ADC

Communication

PWM

Interrupt

Power

Other

AREF

1

Analog Reference input

DAC0/ADC0

2

15

0

Digital-to-Analog Converter 0

A1

3

16

1

16

A2

4

17

17

A3

5

18

18

A4

6

19

19

A5

7

20

A6

8

21

0

9

0

0

1

10

1

1

1

2

11

2

2

3

12

3

3

4

13

4

4

4

5

14

5

5

5

6

15

6

6

6

Built-in LED

7

16

7

7

7

8

17

8

SPI MOSI

8

8

9

18

9

SPI SCK

10

19

10

SPI MISO

10

11

20

11

I2C SDA

12

21

12

I2C SCL

13

22

13

UART TX1

14

23

14

UART RX1

RESET

24

Reset

GND

25

Ground

Vcc

26

+3.3V voltage supply

Vin

27

Unregulated voltage input

+5V

28

+5V (only active when powered from USB)

Notes on the MKR Series

Serial: The MKR1000 has two hardware UARTs.The first one, UART0 (aka Serial in your sketches) is attached directly to the USB port not to any pins. GPIO pins 13 and 14 are Serial1

Notes on the 101

Interrupts: All GPIO pins can be used as interrupts for HIGH, LOW, RISING, and FALLING. .Only pins 2, 5, 7, 8, 10, 11, 12, 13 can be used for CHANGE interrupts.

Serial: The 101 has two hardware UARTs. Serial is attached directly to the USB port of the 101, not to any pins. GPIO pins 0 and 1 are Serial1

The ATN pin: Many shields and expansion modules use SPI communication, this always requires a chip select. On processors that have more than 28 pins there are usually extra unallocated pins that can be used. On the 101, this pin is available.

Arduino Adafruit Feather M0

Finally, here’s the pin diagram for the Adafruit Feather M0 Proto. It should be more or less the same for the other Feather M0 boards, but check the documentation for your board to be sure.

Pin diagram for the Adafruit Feather M0

Adafruit Feather M0 Pin Chart

A listing of the Adafruit Feather M0's pin functions.

Pin Label

Location

GPIO

ADC

Communication

PWM

Interrupt

Power

Other

Reset

1

Reset

+3.3V

2

+3.3V regulated voltage output

AREF

3

Analog Reference Voltage Input

GND

4

Ground

A0

5

14

0

Digital-to-Analog Converter 0

A1

6

15

1

A2

7

16

2

A3

8

17

3

18

A4

9

18

4

19

A5

10

19

5

SCK

11

24

SPI SCK

MISO

12

23

SPI MISO

MOSI

13

22

SPI MOSI

RX1

14

0

UART RX1

TX1

15

1

UART TX1

GND

16

Ground

SDA

17

21

I2C SDA

SCL

18

20

I2C SCL

D5

19

5

5

D6

20

6

D9

21

9

7

9

Attached to battery input connector, for monitoring battery level

D10

22

10

10

D11

23

11

D12

24

12

D13

25

13

Built-in LED

+5V

26

+5V (only active when powered from USB)

En

27

+3.3V regulator enable

VBat

28

Unregulated Voltage in

Notes on the Feather M0

Serial: The FEATHER M0 has two hardware UARTs. The first one, UART0 (aka Serial in your sketches) is attached directly to the USB port not to any pins. GPIO pins 0 and 1 are UART1, aka Serial1

Battery in: LiPo, 3.7V Recharging circuit on board.

Vin: 3.7-5V DC max. (USB), 4.2V Max.(Battery)

Interrupts: All pins can be interrupt pins.

Pin Functions Explained

In order to make sense of all of this, it helps to know the general functions of a microcontroller. There are a few common functions:

Power: Every microcontroller will have connections for power (often labeled Vcc, Vdd, or Vin) and ground. A bare microcontroller will have only those, but modules like the Arduino, the Raspberry Pi, and others also have voltage regulators and other components on board. On these, it’s common to see an unregulated voltage input (Vin) and a regulated voltage output (5V and 3.3V on the Uno, for example).

Clock: Every microcontroller needs a clock. The bare microcontroller chip usually has two pins for this. On a module, the clock is usually built onto the board, and the pins are not exposed.

General Purpose Input and Output (GPIO): Most pins on a microcontroller can operate as either a digital input or digital output.

Hardware Interrupts: Many microcontrollers have a subset of their GPIO pins attached to hardware interrupt circuits. A hardware interrupt can interrupt the flow of a program when a given pin changes its state, so you can read it immediately. Some higher level functions like asynchronous serial and PWM sometimes use these interrupts. They’re also good for very responsive reading of digital inputs.

Analog Input (ADC): Not all microcontrollers have an analog-to-digital converter (ADC), but those that do have a number of pins connected to it and act as inputs to the ADC. If there are analog inputs, include analog reference pin as well, that tells the microcontroller what the default high voltage of the ADC is.

Pulse Width Modulation (PWM): Few microcontrollers have a true analog voltage output (though the MKR1000 does), but most have a set of pins connected to an internal oscillator that can produce a pseudo-analog voltage using PWM. This is how the analogWrite() function in Arduino works.

Communications:

Universal Asynchronous Receiver/Transmitter (UART): Asynchronous serial communication is managed by a Universal Asynchronous Receiver/Transmitter, or UART, inside the processor. The UART pins are usually attached to internal hardware interrupts that can interrupt the program flow when new serial data arrives, so you never miss a byte. It’s possible to manage serial communication in software alone, but at high speeds, you’ll see more errors.

Synchronous Serial: SPI and I2C: Most microcontrollers also have dedicated modules in the processor to handle the two most common forms of synchronous serial communication.

Reset: All microcontrollers have a pin which resets the program. Usually you take this pin low to reset the controller.

IORef: this is the operating voltage of the board. The Uno and 101 have this pin so that shields can read this voltage to adjust their own output voltages as needed. Not all shields have this functionality.

Originally written on August 26, 2016 by Tom Igoe
Last modified on August 20, 2018 by Tom Igoe