The Raspberry Pi GPIO pinout is your interface between software and the physical world — 40 pins that connect to sensors, LEDs, motors, displays, and communication buses. This complete reference guide covers every pin’s function, voltage levels, and safe usage practices across all Raspberry Pi models with the 40-pin header.
Table of Contents
- GPIO Header Overview
- Complete Pinout Map
- Power Pins: 3.3V, 5V, and Ground
- Digital I/O: Input and Output
- I2C Interface
- SPI Interface
- UART (Serial) Interface
- PWM (Pulse Width Modulation)
- Safety Rules and Common Mistakes
- Frequently Asked Questions
- Conclusion
GPIO Header Overview
Every Raspberry Pi from the Model B+ onwards (including Pi 2, 3, 4, 5, Zero, and Zero 2) uses the same 40-pin GPIO header. The pinout is identical across all these models, making hardware designs and HATs universally compatible.
The 40-pin header provides:
- 26 GPIO pins — configurable as digital input or output
- 2x 5V power pins — connected directly to the Pi’s power rail
- 2x 3.3V power pins — regulated 3.3V output (up to ~50mA per pin total)
- 8x Ground pins — common ground reference
- 2x ID EEPROM pins — reserved for HAT identification (GPIO 0 and GPIO 1)
All GPIO pins operate at 3.3V logic. This is critical: connecting a 5V signal directly to a GPIO pin can permanently damage the Pi’s processor. More on this in the safety section.
Complete Pinout Map
The 40-pin header has two numbering systems: physical pin numbers (1-40, as printed on the board) and BCM GPIO numbers (the numbers used in software). Always use BCM GPIO numbers in your code.
| Pin | Function | | | Function | Pin |
|---|---|---|---|---|
| 1 (3.3V) | 3.3V Power | | | 5V Power | 2 (5V) |
| 3 (GPIO 2) | I2C1 SDA | | | 5V Power | 4 (5V) |
| 5 (GPIO 3) | I2C1 SCL | | | Ground | 6 (GND) |
| 7 (GPIO 4) | GPCLK0 | | | UART TX | 8 (GPIO 14) |
| 9 (GND) | Ground | | | UART RX | 10 (GPIO 15) |
| 11 (GPIO 17) | GPIO | | | GPIO (PWM0) | 12 (GPIO 18) |
| 13 (GPIO 27) | GPIO | | | Ground | 14 (GND) |
| 15 (GPIO 22) | GPIO | | | GPIO | 16 (GPIO 23) |
| 17 (3.3V) | 3.3V Power | | | GPIO | 18 (GPIO 24) |
| 19 (GPIO 10) | SPI0 MOSI | | | Ground | 20 (GND) |
| 21 (GPIO 9) | SPI0 MISO | | | GPIO | 22 (GPIO 25) |
| 23 (GPIO 11) | SPI0 SCLK | | | SPI0 CE0 | 24 (GPIO 8) |
| 25 (GND) | Ground | | | SPI0 CE1 | 26 (GPIO 7) |
| 27 (GPIO 0) | ID EEPROM SDA | | | ID EEPROM SCL | 28 (GPIO 1) |
| 29 (GPIO 5) | GPIO | | | Ground | 30 (GND) |
| 31 (GPIO 6) | GPIO | | | GPIO (PWM0) | 32 (GPIO 12) |
| 33 (GPIO 13) | PWM1 | | | Ground | 34 (GND) |
| 35 (GPIO 19) | SPI1 MISO/PWM1 | | | GPIO | 36 (GPIO 16) |
| 37 (GPIO 26) | GPIO | | | SPI1 MOSI | 38 (GPIO 20) |
| 39 (GND) | Ground | | | SPI1 SCLK | 40 (GPIO 21) |
Power Pins: 3.3V, 5V, and Ground
5V pins (Physical 2, 4): Connected directly to the USB power input. Provides the full input voltage (nominally 5V) at up to 1.5A (combined, after accounting for the Pi’s own consumption). Use these to power 5V peripherals like sensors and small displays.
3.3V pins (Physical 1, 17): Regulated 3.3V output from the Pi’s onboard regulator. Maximum combined current draw from these pins is approximately 50mA on Pi 4/5, though most of this is already consumed by the Pi’s internal circuits. Suitable for powering low-power sensors (BME280, MCP3008) but not motors or high-power devices.
Ground pins (Physical 6, 9, 14, 20, 25, 30, 34, 39): Eight ground pins, all connected internally. Use the ground pin nearest to your signal pins to minimise noise. Every circuit connected to the Pi must share a common ground.
Digital I/O: Input and Output
Any GPIO pin can be configured as a digital input (read HIGH/LOW) or digital output (write HIGH/LOW).
Output: HIGH = 3.3V, LOW = 0V. Maximum current per pin: approximately 16mA. This is enough for LEDs (with appropriate resistor) but not for motors or relays — use a transistor or MOSFET for higher-current loads.
Input: Reads 3.3V as HIGH, 0V as LOW. Internal pull-up and pull-down resistors are available (configurable in software). Always use a pull-up or pull-down resistor on input pins to prevent floating state.
Python example with gpiozero (recommended):
from gpiozero import LED, Button
from time import sleep
led = LED(17) # GPIO 17 as output
button = Button(27) # GPIO 27 as input with pull-up
while True:
if button.is_pressed:
led.on()
else:
led.off()
sleep(0.1)
I2C Interface
I2C (Inter-Integrated Circuit) is a two-wire protocol for connecting multiple sensors and devices on a shared bus.
- I2C1: GPIO 2 (SDA) and GPIO 3 (SCL) — the primary I2C bus
- Speed: Default 100 kHz, configurable up to 400 kHz (fast mode)
- Devices: Up to 127 devices on one bus (each needs a unique address)
Common I2C devices: BME280 (weather), SSD1306 (OLED display), MPU6050 (IMU), ADS1115 (ADC), PCA9685 (servo driver)
Enable I2C: sudo raspi-config > Interface Options > I2C > Enable
Scan for devices: i2cdetect -y 1
SPI Interface
SPI (Serial Peripheral Interface) is faster than I2C and used for devices requiring high throughput.
- SPI0: MOSI (GPIO 10), MISO (GPIO 9), SCLK (GPIO 11), CE0 (GPIO 8), CE1 (GPIO 7)
- SPI1: MOSI (GPIO 20), MISO (GPIO 19), SCLK (GPIO 21), CE0-CE2 available
- Speed: Up to 125 MHz (practical maximum depends on wiring)
Common SPI devices: MCP3008 (ADC), MAX31855 (thermocouple), TFT displays, LoRa modules, NRF24L01 radio
UART (Serial) Interface
UART provides basic serial communication — commonly used for GPS modules, Bluetooth modules, and debugging.
- TX: GPIO 14 (transmit)
- RX: GPIO 15 (receive)
- Baud rate: Configurable (9600, 115200, etc.)
Important: By default, the Pi uses the UART for a serial console (login terminal). Disable this in raspi-config > Interface Options > Serial Port if you want to use UART for your own devices. Disable login shell over serial but keep the serial port hardware enabled.
PWM (Pulse Width Modulation)
PWM controls the average power delivered to a component by rapidly switching the pin on and off. Used for LED brightness, servo motor position, and motor speed control.
- Hardware PWM: GPIO 12, 13 (PWM0), GPIO 18, 19 (PWM1) — precise, low CPU usage
- Software PWM: Any GPIO pin via gpiozero or pigpio — less precise, uses CPU
For servo motors, use hardware PWM pins for jitter-free control. For LED dimming, software PWM is adequate.
Safety Rules and Common Mistakes
Rule 1: 3.3V logic ONLY. GPIO pins are 3.3V. Connecting a 5V sensor output directly to a GPIO pin damages the Pi’s processor permanently. Use a voltage divider (two resistors) or a logic level converter when interfacing with 5V devices.
Rule 2: Maximum 16mA per pin. Drawing more than 16mA from a GPIO pin can damage it. LEDs need a current-limiting resistor (330-1K ohm for typical LEDs). Never connect motors, solenoids, or relays directly to GPIO — use a transistor or driver board.
Rule 3: Never short 5V to 3.3V. Connecting the 5V rail to the 3.3V rail or any GPIO pin will likely destroy the Pi’s voltage regulator.
Rule 4: Use pull-up/pull-down resistors on inputs. Floating input pins read random values. Always pull inputs to a known state with a 10K resistor or use the internal pull-up/pull-down in software.
Rule 5: Power off before wiring. Always shut down and disconnect power before making or changing wiring connections. Hot-swapping jumper wires risks accidental shorts.
Common mistakes:
- Using physical pin numbers instead of BCM GPIO numbers in code
- Forgetting a current-limiting resistor for LEDs (results in dim/damaged LEDs and excessive pin current)
- Connecting 5V sensors to 3.3V GPIO inputs without level shifting
- Not sharing a common ground between the Pi and external circuits
- Powering the Pi via GPIO 5V pins without adequate protection (no fuse, no reverse polarity protection)
Frequently Asked Questions
Is the GPIO pinout the same on Pi 4 and Pi 5?
Yes. The 40-pin header pinout is identical on Pi 2, 3, 4, 5, Zero, and Zero 2. Software libraries (gpiozero, RPi.GPIO) work the same way. The Pi 5 uses the RP1 chip for GPIO management, which may affect very low-level direct register access, but standard Python libraries handle this transparently.
Can I use GPIO pins while a HAT is connected?
It depends on which pins the HAT uses. Many HATs only use specific pins (I2C, SPI, or a few GPIO), leaving others available. Check the HAT’s documentation for which pins it requires. Use a GPIO stacking header if you need to access pins underneath a HAT.
Why does the Pi not have analogue input pins?
The Broadcom SoC does not include an ADC (analogue-to-digital converter). For analogue readings, add an external ADC like the MCP3008 (8-channel, 10-bit, SPI) or ADS1115 (4-channel, 16-bit, I2C). These cost ₹150-400 and connect via SPI or I2C.
What is the maximum wire length for GPIO connections?
For basic digital I/O, wires up to 20-30cm work without issues. For I2C, keep wires under 1 metre (shorter is better). SPI is sensitive to wire length — keep connections under 20cm. For longer distances, use appropriate bus drivers or switch to serial (UART) or CAN bus protocols.
Can I damage the Pi by incorrect wiring?
Yes. Connecting 5V to a GPIO pin, shorting pins together, or drawing excessive current can permanently damage the processor. Always double-check wiring before powering on. A ₹100 mistake in wiring can destroy a ₹7,000 Pi. Use a multimeter to verify connections when in doubt.
Conclusion
The 40-pin GPIO header is what makes the Raspberry Pi more than just a tiny computer — it is the bridge between digital software and physical electronics. Whether you are blinking an LED for the first time or building an industrial data logger with I2C sensors and SPI displays, understanding the GPIO pinout is fundamental.
Bookmark this reference guide, start with simple digital I/O projects, and progressively explore I2C sensors, SPI devices, and PWM control. The possibilities expand dramatically once you are comfortable with the GPIO interface.
Find Raspberry Pi boards, GPIO accessories, and breakout boards at Zbotic — India’s largest electronics component store.
Add comment