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.
- The Raspberry Pi pinout
- Three rules that protect your Pi
- Pin types, explained
- I2C vs SPI vs UART
- Compatible modules and how they connect
- What changed on the Raspberry Pi 5
- Your first GPIO project
The Raspberry Pi pinout
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
- 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.
- 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).
- 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.
Useful? Pass it on
← Browse all guides


