Raspberry Pi Pinout Guide: How to use the Raspberry Pi GPIOs?

The Raspberry Pi 4 Model B and most recent versions of the Raspberry Pi have a double row of 40 GPIOs (General Purpose Input/Output Pins) that allow you to connect electronic components like LEDs and sensors. Some pins have specific functions like providing power, I2C, SPI, and UART communication protocols or PWM. In this guide, we’ll take a look at the Raspberry Pi GPIOs and their functions.

Raspberry Pi Pinout Guide How to use the Raspberry Pi GPIOs

Table of Contents

You may like reading: Best Raspberry Pi Getting Started Kits.

Introducing the Raspberry Pi GPIOs

The Raspberry Pi 4 Model B board has a double row of 40 GPIO pins. This layout is the same for the Pi 3 Model B and B+, Pi 2 Model B and B+, and Pi 1 Model B+, but slightly different from the Pi 1 Model A and B, which only have the first 26 pins. 

Raspberry Pi Random Nerd Tutorials
Raspberry Pi Pinout (click on the image to see full-size)

There are several ways to refer to a GPIO pin: its name (which is known as GPIO numbering or Broadcom numbering) or its corresponding pin physical number (which corresponds to the pin’s physical location on the header). For example, GPIO 18 corresponds to pin 12.

Raspberry Pi Pinout Guide

The following table shows the Raspberry Pi pinout, it shows all GPIOs, their corresponding physical pin numbers, their Broadcom numbering, and corresponding features.

FunctionNamePin no.Pin no. NameFunction
DC power3.3 V125 VDC power
I2C (SDA)GPIO 2345 VDC power
GPIO 271314GND
GPIO 221516GPIO 23
DC power3.3 V1718GPIO 24
GPIO 63132GPIO 12 PWM0
PCM FS (I2S)GPIO 193536GPIO 16
GND3940GPIO 21PCM Dout (I2S)

Note: the Raspberry Pi 1 Model B Rev. 1 was the very first Raspberry Pi board released and has a slightly different pinout from all the other boards. This pinout doesn’t apply to that board.

Raspberry Pi Peripherals Interface

The Raspberry Pi GPIOs provide the following peripheral interface options:

  • 3.3V (on 2 pins)
  • 5V (on 2 pins)
  • Ground (on 8 pins)
  • General purpose input and output
  • PWM (pulse width modulation)
  • I2C
  • PCM
  • SPI
  • Serial (UART)

The Raspberry Pi doesn’t have an analog-to-digital converter (ADC) interface to read analog sensors. However, you can use an external analog-to-digital converter like the MCP3008 to read analog signals with the Raspberry Pi.

Important: The Raspberry Pi GPIOs support voltages only up to 3.3V. If you attach a higher voltage, you may permanently damage your Raspberry Pi.

Raspberry Pi Power Pins

The Raspberry Pi comes with two 3.3V pins (pins number 1 and 17) and two 5V pins (pins 2 and 4).

Additionally, there are eight GND pins (pins number: 6, 9, 14, 20, 25, 30, 34, and 39).

Raspberry Pi Digital Inputs and Outputs

Out of the 40 Raspberry Pi GPIOs, 11 are power or GND pins. Besides that, there are two reserved pins (pins 27 and 28) for I2C communication with an EEPROM (learn more about this). So, this left us with 16 GPIOs that you can use to connect peripherals. These GPIOs can be used either as inputs or outputs. Additionally, some of them support specific communication protocols.

Learn more about digital inputs and outputs with the Raspberry Pi:

Raspberry Pi I2C Pins

I²C means Inter-Integrated Circuit, and it is a synchronous, multi-master, multi-slave communication protocol. It allows you to establish communication with other microcontroller devices, sensors, or displays, for example. You can connect multiple I2C devices to the same pins as long they have a unique I2C address.

The Raspberry Pi I2C pins are GPIO 2 and GPIO 3:

  • SDA: GPIO 2
  • SCL: GPIO 3

If you want to use I2C, you need to enable the I2C communication interface first.

Raspberry Pi SPI Pins

SPI stands for Serial Peripheral Interface, and it is a synchronous serial data protocol used by microcontrollers to communicate with one or more peripherals. This communication protocol allows you to connect multiple peripherals to the same bus interface, as long as each is connected to a different chip select pin.

For example, your Raspberry Pi board can communicate with a sensor that supports SPI, another Raspberry Pi, or a different microcontroller board. These are the Raspberry Pi SPI pins:

  • MOSI: GPIO 10
  • MISO: GPIO 9
  • CLOCK: GPIO 11
  • CE0 (chip select): GPIO 8
  • CE1 (chip select): GPIO 7

Raspberry Pi Serial (UART) Pins

The UART pins can be used for Serial communication. The Raspberry Pi Serial (UART) pins are:

  • TX: GPIO 14
  • RX: GPIO 15

Raspberry Pi PWM Pins

PWM stands for Pulse Width Modulation and it is used to control motors, define varying levels of LED brightness, define the color of RGB LEDs, and much more.

The Raspberry Pi has 4 hardware PWM pins: GPIO 12, GPIO 13, GPIO 18, GPIO 19.

You can have software PWM on all pins.

Learn how to generate PWM signals with the Raspberry Pi:

Raspberry Pi ADC Pins

The Raspberry Pi doesn’t have any ADC pins—it doesn’t include an analog-to-digital converter. So, you need to convert the analog signal to a digital signal using an analog-to-digital-converter like the MCP3008 chip.

Being able to read analog signals is useful to read varying voltage levels from a potentiometer or sensors, for example.

Learn how to read analog signals with the Raspberry Pi with the following tutorial:

Raspberry Pi One-Wire Pins

The Raspberry Pi supports one-wire on all GPIOs, but the default is GPIO4.

Raspberry Pi PCM Pins

The Raspberry Pi comes with PCM (pulse-code Modulation) pins for digital audio output. These are the PCM pins:

  • Din: GPIO 20
  • Dout: GPIO 21
  • FS: GPIO 19
  • CLK: GPIO 18


Pins 27 and 28 (GPIO 0 and GPIO 1) are reserved for connecting a HAT ID EEPROM. Do not use these pins unless you’re using an I2C ID EEPROM. Leave unconnected if you’re not using an I2C EEPROM.

Wrapping Up

We hope you’ve found this guide about the Raspberry Pi GPIOs useful.

One of the easiest ways to control the Raspberry Pi GPIOs is using Python and the gpiozero library. We’ll create some tutorials about how to use the GPIOs soon. So, stay tuned.

You may also like:

You can check all our Raspberry Pi projects on the following link:

We have other guides about the ESP32, ESP8266 and ESP32-CAM GPIOs:

Thanks for reading.

Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…

Enjoyed this project? Stay updated by subscribing our newsletter!

4 thoughts on “Raspberry Pi Pinout Guide: How to use the Raspberry Pi GPIOs?”

  1. I’m not sure which library is better for Raspberry Pi 5, gpiozero or lgpio. I tried both and decided to go with LGPIO, whatever. In my opinion, it would be good if the Phyton GPIO library queries whether it is a BM2711 or RP1 and addresses the libraries in the OS accordingly. I’m currently working on creating board classes for the Raspberry versions where the GPIO chip can be set.
    Thank you for your inspiring contributions.



Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.