Raspberry Pi GPIO Pinout Explained: Every Pin, Bus and Module

The full 40-pin pinout, what every pin type does, I2C vs SPI vs UART, compatible modules, and the three rules that keep you from frying your Pi.

Sep 27, 2026 5 min read By Atomic Creations

Raspberry Pi 40-pin GPIO pinout, color coded by pin type

Those 40 little pins along the edge of a Raspberry Pi are how it talks to the physical world: buttons, lights, sensors, screens, radios and motors. They look intimidating, but there are only a handful of pin types, and once you know them you can wire up almost any module. Here is the full pinout, what each kind of pin does, and the three rules that keep you from frying your board.

The short answer

The 40-pin header has 28 GPIO pins (GPIO0 to GPIO27) plus 5V, 3.3V and ground pins. GPIO pins use 3.3V logic and are not 5V tolerant. Some GPIO pins double as communication buses: I2C (GPIO2 and 3), SPI (GPIO7 to 11), UART serial (GPIO14 and 15) and hardware PWM (GPIO12, 13, 18, 19). The layout is the same on the Pi 5, Pi 4, Pi 3 and Zero boards.

  1. The Raspberry Pi pinout
  2. Three rules that protect your Pi
  3. Pin types, explained
  4. I2C vs SPI vs UART
  5. Compatible modules and how they connect
  6. What changed on the Raspberry Pi 5
  7. Your first GPIO project

The Raspberry Pi pinout

1 3V3 2 5V 3 GPIO2 SDA 4 5V 5 GPIO3 SCL 6 GND 7 GPIO4 8 GPIO14 TXD 9 GND 10 GPIO15 RXD 11 GPIO17 12 GPIO18 PWM 13 GPIO27 14 GND 15 GPIO22 16 GPIO23 17 3V3 18 GPIO24 19 GPIO10 MOSI 20 GND 21 GPIO9 MISO 22 GPIO25 23 GPIO11 SCLK 24 GPIO8 CE0 25 GND 26 GPIO7 CE1 27 GPIO0 ID_SD 28 GPIO1 ID_SC 29 GPIO5 30 GND 31 GPIO6 32 GPIO12 PWM 33 GPIO13 PWM 34 GND 35 GPIO19 PWM 36 GPIO16 37 GPIO26 38 GPIO20 39 GND 40 GPIO21 pin 1 is the one with the square solder pad
5V power3.3V powerGroundGeneral GPIOI2CSPIUARTHardware PWMHAT ID (reserved)
The 40-pin header, viewed from above with the pins pointing at you. Two numbering systems exist: physical pin numbers (1 to 40, in the circles) and GPIO numbers (the labels). Code almost always uses GPIO numbers.

Two things trip up everyone at first. The GPIO numbers do not follow the physical order, so GPIO17 is on pin 11. And your code refers to GPIO numbers, while your wiring follows physical positions. Keep a pinout handy: on Raspberry Pi OS, typing pinout in a terminal prints one for your exact board.

Three rules that protect your Pi

  1. Never put 5V into a GPIO pin. The pins run at 3.3V and are not 5V tolerant. A 5V sensor output wired straight in can damage the Pi. Use a level shifter or a module that is already 3.3V-safe.
  2. Never power motors or relays from a GPIO pin. A single pin can safely supply around 16mA; a motor or relay coil wants far more. Drive them through a transistor, a relay board or a motor driver (H-bridge).
  3. Don't short 5V to anything. The 5V pins come straight from the power supply with no protection. Double-check wiring before powering up, and power off before rewiring.

Pin types, explained

  • 5V (pins 2, 4): power straight from the supply, for modules that need 5V power. Power only, never a signal into GPIO.
  • 3.3V (pins 1, 17): a regulated 3.3V supply for small sensors and modules.
  • Ground (8 pins): every circuit needs a return path. Always connect your module's GND to a Pi GND.
  • General GPIO: digital pins you switch on and off (outputs) or read (inputs), for LEDs, buttons, switches and simple signals.
  • Hardware PWM (GPIO12, 13, 18, 19): pulse-width modulation, a fast on-off signal used to dim LEDs, set servo angles or control fan speed smoothly. Software PWM works on any pin, less precisely.
  • HAT ID (GPIO0, 1): reserved for the small memory chip on official add-on boards (HATs) that tells the Pi what is attached. Leave these alone.

I2C vs SPI vs UART

Most modules talk to the Pi over one of three standard buses. Knowing which one a module uses tells you exactly which pins to wire.

I2C SPI UART (serial)
Wires 2 (SDA data, SCL clock) plus power 4 (MOSI, MISO, SCLK, CE) plus power 2 (TX, RX) plus power
Pi pins GPIO2, GPIO3 GPIO10, 9, 11, 8 (CE0) or 7 (CE1) GPIO14 (TX), GPIO15 (RX)
Many devices? Yes, each has an address Yes, one chip-select line each Usually one device
Speed Moderate (standard modes 100 or 400 kHz) Fastest Usually slowest (often 9600 to 115200 baud)
Typical use Sensors, small OLED screens Color screens, radios, SD cards GPS modules, other microcontrollers

Rule of thumb: I2C when you want lots of simple devices on two wires, SPI when you need speed (screens, radios), UART when a device just streams text at you (GPS). Remember TX goes to the other device's RX, and RX to its TX.

Compatible modules and how they connect

Module What it does Bus Notes
BME280 Temperature, humidity, pressure I2C or SPI Runs on 3.3V; a classic first sensor
SSD1306 OLED Small 128x64 monochrome screen I2C (or SPI) I2C address 0x3C or 0x3D
ST7789 TFT Small color screen SPI Great for status displays in a build
NEO-6M GPS Location and time UART Streams NMEA text at 9600 baud by default
SX1262 LoRa Long-range radio (e.g. Meshtastic) SPI Always attach the antenna first
Relay board Switch bigger loads like lamps, fans or pumps GPIO + driver Use a board with a transistor driver built in
Official Touch Display 2 5", 7" or 10" touchscreen DSI ribbon Not GPIO, but powered from the header's 5V

Buying a module? Check two things on the listing: its logic voltage (3.3V is safe; 5V needs a level shifter) and its bus (I2C, SPI or UART). That tells you whether it will work and which pins it goes to.

What changed on the Raspberry Pi 5

The header looks identical, and the pinout above is the same. Under the hood, though, the Pi 5 routes the GPIO through Raspberry Pi's own RP1 input/output chip instead of the main processor. Practically that means:

  • Old code may break. The long-standing RPi.GPIO Python library does not work on the Pi 5. Use gpiozero (the recommended library, which uses lgpio on the Pi 5) or the drop-in rpi-lgpio package to run older RPi.GPIO code.
  • Hardcoded chip numbers break. Early Pi 5 software called the header "gpiochip4"; current kernels call it "gpiochip0". Code that hardcoded the old name needs updating.

Your first GPIO project

Wire an LED (with a 330 ohm resistor in series) from GPIO17 (pin 11) to ground (pin 9), then run this in Python:

from gpiozero import LED
from time import sleep

led = LED(17)
while True:
    led.toggle()
    sleep(0.5)

Blinking an LED is the "hello world" of electronics, and every bigger build, from a weather station to a cyberdeck with status lights and toggle switches, grows out of it.

Beyond the Pi: microcontrollers

Not every project needs a full Linux computer. Microcontrollers like the ESP32 have GPIO too, boot instantly and run for days on a battery. The Cardputer ADV that our pocket synth GLIDE runs on is built around an ESP32-S3, with its own expansion header for modules. Our guide to ESP32 vs Raspberry Pi helps you pick the right brain for a build.

Next batch · Batch 4

Join the GLIDE waitlist

Batch 4 opens next week. The list gets the email 24 hours before it goes public. One message, nothing more.

One email, no newsletter, unsubscribe any time.

Useful? Pass it on

Reddit X
← Browse all guides

Try it in your browser

This is GLIDE. Press anything.

A sketch of the Cardputer synth running right here. The four rows are tuned like strings: hold one key and tap another on the same row and the note slides. Tap a chord on the bottom row, then play over it.

A MINOR PENT ·clashes 0

Press any key. Then try Start a beat.

Keyboard works too: 1 to 0, q to p, a to ; are the strings, z to / is the jam row. Same letters as the real thing.

Scale lock is on, so every key fits. Flip it off to hear a regular keyboard. On the device you also get ten sounds, a looper, tilt control, the speaker and a headphone jack.

Small batches, tested one by one

Get GLIDE ready to play. Tested one by one.

Set up, tested and charged one by one, with a sound library loaded. Switch it on and play, and tap Randomize for a sound nobody else has.

  • HardwareM5Stack Cardputer ADV
  • Keys56, four string rows
  • Auto KeyHears key, mode and tempo
  • OutputSpeaker + 3.5 mm headphone
  • PowerUSB-C, 7 to 10 h a charge
  • UpdatesFree, forever
GLIDE pocket synth with a white face and green trim, on a glossy black surface lit with green lines
Actual size: 84 × 54 mm, about a credit card

Next batch · Batch 4

Join the GLIDE waitlist

Batch 4 opens next week. The list gets the email 24 hours before it goes public. One message, nothing more.

One email, no newsletter, unsubscribe any time.

Questions first? Ask the maker on Discord →