The Raspberry Pi 4 Model B features a 40-pin GPIO (General Purpose Input/Output) header arranged in a 2x20 layout. Unlike standard microcontrollers, the Pi operates at strictly 3.3V logic and maps its pins using two distinct numbering systems: Broadcom (BCM) channel numbers and physical board pin numbers. Feeding 5V into any GPIO pin will permanently destroy the SoC. Below is the direct, data-dense reference you need to wire sensors, relays, and HATs safely without bricking your board.
The Complete Raspberry Pi 4 Pinout Diagram & Reference Table
The table below details the power rails, communication buses, and special-function pins on the Pi 4 header. While all 26 available GPIOs can be used for basic digital I/O, these specific pins have hardware-level constraints or dedicated alternate functions you must account for in your circuit design.
| Physical Pin | BCM GPIO | Primary Function | Hardware Notes & Constraints |
|---|---|---|---|
| 1 | - | 3.3V Power | Max draw ~50mA. Do not use for high-current relays. |
| 2 | - | 5V Power | Direct from USB-C input. Use for servo/relay power rails. |
| 3 | 2 | I2C1 SDA | Has a hard 1.8kΩ pull-up to 3.3V on the board. |
| 5 | 3 | I2C1 SCL | Has a hard 1.8kΩ pull-up to 3.3V on the board. |
| 8 | 14 | UART0 TXD | Defaults to serial console; disable in raspi-config for GPIO use. |
| 10 | 15 | UART0 RXD | Defaults to serial console; disable in raspi-config for GPIO use. |
| 19 | 10 | SPI0 MOSI | Standard SPI data out. Shared with PWM1. |
| 21 | 9 | SPI0 MISO | Standard SPI data in. |
| 23 | 11 | SPI0 SCLK | Standard SPI clock. |
| 24 | 8 | SPI0 CE0 | SPI Chip Select 0 (Active Low). |
| 27 | 0 | I2C0 SDA (ID) | Reserved for HAT ID EEPROM. Do not use for general I2C. |
| 28 | 1 | I2C0 SCL (ID) | Reserved for HAT ID EEPROM. Do not use for general I2C. |
| 6, 9, 14, 20, 25, 30, 34, 39 | - | Ground (GND) | Common ground for all 3.3V and 5V circuits. |
Source: Raspberry Pi Official Hardware Documentation
Rows and Pins People Get Wrong (And How to Avoid Bricking Your Pi)
When cross-referencing a raspberry pi 4 pinout diagram with Python scripts or physical wiring, mismatches between software expectations and physical reality cause the most failures. Here are the specific traps to avoid.
The Raspberry Pi 4 GPIO bank is strictly 3.3V. It is not 5V tolerant. Connecting a 5V sensor output (like an HC-SR04 ultrasonic sensor or an Arduino Uno output) directly to any BCM GPIO pin will push current backward through the SoC's protection diodes, eventually melting the internal traces and permanently killing the Pi. Always use a logic level shifter or a simple 2-resistor voltage divider (e.g., 1kΩ and 2kΩ) to drop 5V signals down to 3.3V.
1. Physical Pin 1 vs. Pin 2 (The Power Rail Swap)
Physical Pin 1 outputs 3.3V. Physical Pin 2 outputs 5V. If you are wiring a sensor that requires 5V (like a standard 5V relay module or an active buzzer) and you accidentally connect its VCC to Pin 1, the sensor will fail to trigger. Worse, if you wire a 5V module's ground to Pin 1, you will short the 3.3V regulator to ground, causing an immediate thermal shutdown or regulator failure.
2. BCM vs. BOARD Numbering in Python
The RPi.GPIO library requires you to declare your numbering scheme before setting pin modes.
GPIO.setmode(GPIO.BCM): Uses the Broadcom SOC channel numbers (e.g., Physical Pin 3 is BCM 2).GPIO.setmode(GPIO.BOARD): Uses the physical pin numbers on the header (e.g., Physical Pin 3 is 3).
3. The I2C Pull-Up Trap (BCM 2 and BCM 3)
Physical pins 3 and 5 (BCM 2 and 3) are the default I2C1 bus. The Pi 4 includes hard 1.8kΩ pull-up resistors to 3.3V on these lines. If you connect an external sensor module that also has 4.7kΩ pull-up resistors to 5V, you create a voltage divider that can pull the Pi's 3.3V rail out of spec, or worse, back-feed 5V into the Pi's I2C controller. Always check your sensor module's schematic and cut the pull-up jumper traces on the sensor if they are tied to 5V.
4. The HAT ID Pins (Physical 27 and 28)
GPIO 0 and GPIO 1 (Physical 27 and 28) are reserved for the Raspberry Pi HAT (Hardware Attached on Top) specification. The Pi uses these to read an EEPROM on official HATs to auto-configure GPIO states at boot. Do not use these pins for general-purpose I2C sensors or manual switches, as the boot process will poll them and cause bus collisions.
Wiring Color Codes and Regional Standards for GPIO
While the Pi 4 header itself is universal, the wires you use to connect it to external terminal blocks, relay modules, or remote sensors must follow logical color conventions to prevent catastrophic miswiring—especially when bridging low-voltage DC logic with AC mains environments.
Low-Voltage DC Sensor Wiring (Hobbyist & Industry Standard)
For Dupont cables and standard sensor pigtails (I2C, SPI, UART), the industry convention is:
- Red: VCC (3.3V or 5V, depending on the sensor)
- Black: Ground (GND)
- Yellow / White / Blue: Signal / Data lines (SDA, SCL, TX, RX)
Regional AC Mains Standards (When Wiring Pi Relays to Mains)
If your Pi project involves switching AC mains via a relay board, the AC side of your relay must follow your regional electrical code. Never use standard DC hobby wires (Red/Black) for AC mains connections.
| Standard / Region | Line (Hot) | Neutral | Earth Ground | Application Context |
|---|---|---|---|---|
| IEC 60446 (EU / UK / AU / Global) | Brown | Blue | Green/Yellow Stripe | Modern standard for all AC appliance wiring and fixed installations. |
| NEC (US / Canada) | Black (or Red for L2) | White (or Grey) | Bare Copper or Green | North American residential and commercial branch circuits. |
| Old UK (Pre-2004) | Red | Black | Green/Yellow | Found in older UK homes. Highly confusing for Pi builders because Red/Black mimics DC VCC/GND. |
The Repurposed Cable Trap: Makers frequently repurpose old multi-core thermostat wire or vintage telecom cable for long I2C or 1-Wire runs across a house. These cables often use Red, White, Yellow, and Green. Because these colors violate both IEC and standard DC conventions, you must explicitly label both ends of the cable with heat-shrink tubing or marker tape indicating the exact Pi pin mapping (e.g., "White = GND, Yellow = SDA"). Never assume Red is VCC in a repurposed wall cable.
Safe Interpretation When Silkscreen Markings Are Faded or Missing
On older Pi 4 boards, or boards that have been subjected to high heat and flux cleaning, the white silkscreen text indicating pin numbers and functions can rub off entirely. Guessing pin orientation will result in a dead board. Use these three physical verification methods to safely identify your pinout without relying on faded ink.
1. The Square Pad Rule (Bottom of Board)
Flip the Raspberry Pi over and inspect the solder joints of the 40-pin header. Pin 1 is always the square solder pad. All other pins (2 through 40) will have perfectly round solder pads. This is a universal IPC manufacturing standard for polarized headers and will never be rubbed off by handling.
2. Component Proximity Orientation
If the board is mounted in a case and you cannot see the bottom, orient the board so the USB-C power port and the micro-HDMI ports are facing away from you (or at the bottom edge). The GPIO header will be at the top. In this orientation, Pin 1 is the top-left pin, closest to the micro-HDMI port and the SD card slot. Pin 2 is immediately to its right.
3. Multimeter Continuity Verification
Before connecting a sensitive I2C sensor or SPI display to an unmarked header, power the Pi on and use a digital multimeter (DMM) to verify the power rails.
- Set your DMM to DC Voltage.
- Place the black probe on the metal shielding of the USB-A ports (which is tied to system ground).
- Probe the suspected Pin 2 with the red probe. It should read between 4.9V and 5.1V.
- Probe the suspected Pin 1. It should read exactly 3.3V.
- Probe the suspected Pin 6. It should read 0.0V (continuity to the USB shield).
Maker's Tip: If you frequently swap sensors on a headless Pi 4 mounted in a DIN rail or enclosed box, print a mirrored pinout diagram on adhesive vinyl and stick it to the inside of your enclosure lid. Relying on memory or a phone screen in tight, poorly lit enclosures is the leading cause of accidental 5V-to-GPIO shorts.






