A Raspberry Pi GPIO pin diagram is a visual map of the 40-pin header that identifies which physical pins provide power, ground, or programmable digital signals for interfacing with external electronics. Understanding this diagram changes a blind hardware connection into a safe, functional circuit by dictating exactly how you route sensors, actuators, and communication buses without accidentally feeding 5V into a 3.3V logic pin and destroying the system-on-chip (SoC). The most common point of failure for beginners is confusing the physical pin layout (numbered 1 through 40) with the Broadcom (BCM) channel numbers used in Python and C++ libraries.
The Anatomy of the 40-Pin Header
Since the Raspberry Pi Model B+ (and continuing through the Pi 4 Model B and the Pi 5), the standard GPIO header has remained a 2x20 pin array. While the physical footprint is identical, the underlying silicon routing changed significantly with the Pi 5's RP1 southbridge chip. However, the power and ground pin assignments remain strictly standardized to maintain backward compatibility with existing HATs (Hardware Attached on Top).
Here is the breakdown of the pin types you will find on the header:
| Pin Type | Quantity | Voltage / Function | Notes |
|---|---|---|---|
| 3.3V Power | 2 | 3.3V DC | Sourced from the onboard regulator. Max draw is typically ~50mA total across both pins. |
| 5V Power | 2 | 5V DC | Directly tied to the USB-C power input (Pi 4) or the dedicated power header (Pi 5). |
| Ground (GND) | 8 | 0V Reference | Distributed across the header to minimize ground loops and provide local return paths. |
| GPIO (Programmable) | 26 | 3.3V Logic | Can be configured as digital I/O, or muxed to hardware peripherals (I2C, SPI, UART, PWM). |
| EEPROM ID | 2 | I2C0 (Reserved) | Pins 27 and 28. Reserved for HAT identification; do not use for general I/O. |
Physical vs. BCM vs. WiringPi: The Numbering Trap
When you look at an RPi GPIO pin diagram, you will see multiple numbering schemes overlapping the same physical pins. This is the root cause of 90% of 'my sensor isn't working' forum posts. You must align your physical wiring with the software addressing scheme your code expects.
- Physical (Board) Numbering: Simply counts the pins from 1 to 40, starting at the top left (closest to the USB-C port) and zig-zagging down. Pin 1 is the 3.3V rail. This is purely a mechanical reference.
- BCM (Broadcom) Numbering: References the internal GPIO channel numbers of the Broadcom SoC (BCM2711 on Pi 4, BCM2712/RP1 on Pi 5). For example, Physical Pin 3 is BCM 2. The
gpiozeroandRPi.GPIOPython libraries default to this scheme. - WiringPi Numbering: An older, deprecated numbering scheme created to mimic the Arduino's 0-15 digital pin layout. It maps Physical Pin 3 to WiringPi Pin 8. Avoid this in new projects, as the WiringPi library was officially deprecated in 2019 and does not fully support the Pi 4 or Pi 5 architecture.
Rule of Thumb: Always write your Python code using BCM numbering (GPIO.setmode(GPIO.BCM)), but keep a physical pin diagram on your desk to verify where the wires actually plug in.
Worked Example: Sizing a Resistor for a GPIO LED
Let's apply the pin diagram to a real circuit. You want to wire a standard 5mm red LED to a GPIO pin to act as a status indicator. You look at your diagram and choose Physical Pin 11, which corresponds to BCM 17.
The Parameters:
- GPIO Logic High Voltage ($V_{CC}$): 3.3V
- LED Forward Voltage ($V_f$): 2.0V (typical for standard red)
- Target Current ($I$): 8mA
The Calculation:
Using Ohm's Law ($R = \frac{V}{I}$), we first find the voltage drop required across the resistor:
$V_R = V_{CC} - V_f = 3.3V - 2.0V = 1.3V$
Now, calculate the resistance for our 8mA (0.008A) target:
$R = \frac{1.3V}{0.008A} = 162.5\Omega$
Since 162.5Ω is not a standard resistor value, we look at the E12 series and round up to the next available value to ensure we stay under our current target. The closest standard value is 180Ω.
Verification Step: Before connecting the LED to the Pi, wire the 180Ω resistor and LED to a bench power supply set to 3.3V. Use a multimeter in series to verify the current draw reads between 7.0mA and 7.5mA. Once verified, connect the anode (via the resistor) to BCM 17 (Physical 11) and the cathode to GND (Physical 9).
Where You Meet This in Practice
The most common real-world application of the RPi GPIO pin diagram is wiring I2C sensors, like the BME280 temperature/humidity/pressure breakout board. I2C requires two specific lines: Serial Data (SDA) and Serial Clock (SCL).
If you look at the pinout, the primary I2C bus (I2C1) is hardcoded to BCM 2 (SDA) and BCM 3 (SCL). Physically, these are Pins 3 and 5. The Raspberry Pi includes onboard 1.8kΩ pull-up resistors tied to the 3.3V rail for these specific pins.
Wiring the BME280:
- Connect BME280
VINto Pi Physical Pin 1 (3.3V). - Connect BME280
GNDto Pi Physical Pin 6 (GND). - Connect BME280
SDAto Pi Physical Pin 3 (BCM 2). - Connect BME280
SCLto Pi Physical Pin 5 (BCM 3).
If your code initializes the I2C bus but returns a 'No device found' error, 99% of the time the physical wires are swapped (SDA to SCL), or you are accidentally polling the secondary I2C0 bus (used for EEPROM ID on pins 27/28) in your software configuration. Always cross-reference the physical pin numbers on your diagram with the physical silkscreen on your sensor breakout board.
Frequently Asked Questions
How do I print the Raspberry Pi GPIO pin diagram in the terminal?
You don't need to memorize the pinout or keep a browser tab open. If you are using a modern Raspberry Pi OS (Bookworm or later) with Python 3 installed, the gpiozero library includes a built-in CLI tool. Simply open your terminal and type:
pinout
This will render a clean, color-coded ASCII art diagram of the 40-pin header directly in your terminal, showing both Physical and BCM numbering, along with the board revision and SoC details. You can read more about this in the GPIO Zero CLI documentation.
Which Raspberry Pi GPIO pins are safe to use for hardware PWM?
While you can generate software PWM on any GPIO pin using libraries like gpiozero, software PWM suffers from jitter because the Linux kernel is not a real-time operating system. For precise motor control or LED dimming, you need hardware PWM. On the BCM2711 (Pi 4) and the RP1 (Pi 5), true hardware PWM is available on BCM 12, 13, 18, and 19. Note that BCM 18 (Physical Pin 12) is the most commonly used, as it is the only hardware PWM pin that was also supported on the older Pi 1 and Pi 2 models, making it the standard choice for legacy audio and fan control scripts.
What happens if I connect a 5V sensor to the Raspberry Pi GPIO?
The 3.3V logic threshold for a 'HIGH' read on the Raspberry Pi is roughly 1.3V (anything above ~1.3V registers as a 1). However, the absolute maximum voltage tolerance for the I/O pads is 3.6V. If you connect a 5V Arduino output or a 5V ultrasonic sensor (like the HC-SR04) directly to a Pi GPIO pin, the excess voltage forward-biases the internal ESD protection diodes. This dumps current directly into the 3.3V rail, causing 'latch-up'—a parasitic thyristor effect that creates a dead short inside the silicon. The Pi will likely freeze, the SoC will become physically hot to the touch, and the GPIO pin (or the entire chip) will be permanently destroyed. Always use a bidirectional logic level shifter (like the Texas Instruments TXS0108E) or a simple 2-resistor voltage divider (e.g., 1kΩ and 2kΩ) to drop the 5V signal down to a safe ~3.3V.






