Skip to content
My Account

Guide

Raspberry Pi 4 Pinout

The complete 40-pin GPIO reference for the Raspberry Pi 4 Model B: 26 general-purpose pins, I2C, SPI, UART, PWM, and the exact pins you can safely reuse.

  • Raspberry Pi
  • Safety notes
  • 3 min read
No ratings yet, be the first.

Overview

The Raspberry Pi 4 is a full single-board computer, not a microcontroller: it boots Linux from an SD card or USB drive, rather than running a single compiled program. Its 40-pin GPIO header still works a lot like the boards elsewhere in these guides, 3.3V logic, I2C, SPI, UART and PWM are all here, just controlled from Python (or any language) running on top of a full OS instead of bare-metal firmware.

No analog input Unlike the microcontroller boards in these guides, the Pi 4 has no ADC at all, add an external one (like an MCP3008) over SPI to read analog sensors.
ID_SD/ID_SC are reserved Pins 27 and 28 are for HAT EEPROM auto-detection, don’t use them as general I2C.
True hardware PWM on 4 pins GPIO12, 13, 18 and 19 support hardware PWM, other pins need software PWM, which is less precise.

Getting started

Unlike the microcontroller boards in these guides, there’s no sketch to compile and upload, you flash an operating system image to an SD card once, then the Pi boots into it like a regular computer.

1. What you need A microSD card (8 GB or larger), a USB-C power supply (5V/3A), and a computer to write the SD card.
2. Flash an OS image Use the free Raspberry Pi Imager to write Raspberry Pi OS to the SD card, it can pre-configure Wi-Fi and SSH for you.
3. Boot and enable GPIO access Insert the card, power up, then install a GPIO library (gpiozero comes preinstalled on Raspberry Pi OS).

Hello World: blink an LED

The microcontroller equivalent of “Hello World”: GPIO17 toggles once a second. Wire an LED (with a resistor) to GPIO17 (physical pin 11), then run this directly on the Pi, no separate upload step needed.

from gpiozero import LED
from time import sleep

led = LED(17)  # GPIO17, physical pin 11
while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

Run with: python3 blink.py. gpiozero ships preinstalled on Raspberry Pi OS.

Specifications

Official specifications for the Raspberry Pi 4 Model B.

Compute

SoCBroadcom BCM2711
CPUQuad-core Cortex-A72, 1.5 GHz, 64-bit
RAM2, 4 or 8 GB LPDDR4

Connectivity

Wi-FiDual-band 802.11ac
Bluetooth5.0
EthernetTrue Gigabit
USB2 × USB 3.0, 2 × USB 2.0

Physical

GPIO logic level3.3V
Power inputUSB-C, 5V/3A
Video out2 × micro-HDMI, up to 4K60
Raspberry Pi 4 Model B dimensioned top view: standard 56 mm board width, 0.80 mm PCB thickness, USB-C power input (5V at 3A), 40-pin GPIO header at 2.54 mm pitch

Pinout diagram

The full 40-pin GPIO header.

Raspberry Pi 4 pinout diagram

GPIO quick reference

Physical pin numbers count around the header, BCM numbers are what Python libraries expect by default, the two don’t match.

Pin BCM Name Function Notes
1 — 3.3V Power Constant 3.3V output
2 — 5V Power Direct 5V from USB-C
3 2 SDA1 I2C Requires pull-up resistor
4 — 5V Power Direct 5V from USB-C
5 3 SCL1 I2C Requires pull-up resistor
6 — GND Ground —
7 4 GPIO4 GPIO General-purpose I/O
8 14 TXD0 UART TX Serial transmit
9 — GND Ground —
10 15 RXD0 UART RX Serial receive
11 17 GPIO17 GPIO —
12 18 GPIO18 GPIO, PWM Hardware PWM
13 27 GPIO27 GPIO —
14 — GND Ground —
15 22 GPIO22 GPIO —
16 23 GPIO23 GPIO —
17 — 3.3V Power Constant 3.3V output
18 24 GPIO24 GPIO —
19 10 MOSI SPI SPI Master Out
20 — GND Ground —
21 9 MISO SPI SPI Master In
22 25 GPIO25 GPIO —
23 11 SCLK SPI SPI Clock
24 8 CE0 SPI Chip select 0
25 — GND Ground —
26 7 CE1 SPI Chip select 1
27 0 ID_SD EEPROM I2C Reserved for HATs
28 1 ID_SC EEPROM I2C Reserved for HATs
29 5 GPIO5 GPIO —
30 — GND Ground —
31 6 GPIO6 GPIO —
32 12 GPIO12 GPIO, PWM Hardware PWM
33 13 GPIO13 GPIO, PWM Hardware PWM
34 — GND Ground —
35 19 GPIO19 GPIO, PWM, SPI Hardware PWM
36 16 GPIO16 GPIO —
37 26 GPIO26 GPIO —
38 20 GPIO20 GPIO —
39 — GND Ground —
40 21 GPIO21 GPIO —

Serial console (UART)

Useful for debugging headless boots, or talking to another serial device directly. Enable it in raspi-config first, it’s off by default.

Function Pin Description
TXD0GPIO14 (pin 8)Pi → external device (output)
RXD0GPIO15 (pin 10)External device → Pi (input)

Safety notes

Before you wire anything up

  • GPIOs are 3.3V logic and not 5V tolerant, connecting a 5V signal directly to any GPIO pin can permanently damage the Pi.
  • Pins 27 and 28 (ID_SD/ID_SC) are reserved for HAT EEPROM detection, leave them alone unless you know exactly what you’re doing.
  • Never hot-plug a HAT or wiring onto the GPIO header while the Pi is powered.
  • Use a real 5V/3A USB-C supply, undersized power adapters cause random reboots under load, especially with USB peripherals attached.
Advertisement
All guides

More guides

Keep building.

From ESP32 HomeKit accessories to Arduino and ATtiny reference guides, there’s more where this came from.

All guides