Rasp Pi GPIO refers to the 40 physical pins on the board's header that can be programmatically configured to read digital inputs or drive digital outputs at 3.3V logic levels. By exposing these pins, the Pi transforms from a standalone headless Linux computer into a physical computing hub capable of reading real-world sensors, toggling relays, and driving actuators. The most common mistake makers make when transitioning from microcontrollers is confusing the physical pin number (e.g., Pin 12) with the Broadcom (BCM) GPIO number (e.g., GPIO18), or fatally assuming the pins are 5V tolerant like an Arduino Uno.

The 40-Pin Header: Power, Ground, and Logic

Before wiring anything, you need to understand the physical layout and the strict electrical boundaries of the header. The 40-pin header is identical across the Raspberry Pi 3, 4, and 5, as well as the Pi Zero 2 W. Below is a functional breakdown of the header. For a complete interactive map, the community-standard Pinout.xyz is an indispensable bench reference.

Function Category Pin Count Specific Pins / BCM Numbers Electrical Notes & Limits
Power (3.3V) 2 Physical Pins 1, 17 Max 50mA total draw. Do not use for high-current loads; use the 5V rail with a buck converter instead.
Power (5V) 2 Physical Pins 2, 4 Tied directly to the USB-C input. Capable of supplying remaining current after the Pi's own draw (typically 1A-2A headroom on a 3A supply).
Ground (GND) 8 Pins 6, 9, 14, 20, 25, 30, 34, 39 All grounds are common. Always bond external circuit ground to one of these before sending logic signals.
Standard GPIO 26 BCM 2-27 (excluding reserved) 3.3V logic. Max 16mA per pin, 50mA combined total across all active GPIOs.
I2C / SPI / UART 10 BCM 0,1 (I2C), 7-11 (SPI), 14,15 (UART) Multiplexed with standard GPIOs. I2C pins (3, 5) have onboard 1.8kΩ pull-up resistors to 3.3V.
EEPROM ID 2 BCM 0, 1 (Physical 27, 28) Reserved for HAT identification. Do not use for general I/O unless no HAT is attached.

Electrical Limits and a Worked Numeric Example

The Raspberry Pi's Broadcom SoC operates at 3.3V. This dictates two hard rules: a logic HIGH is 3.3V, and the absolute maximum voltage you can feed into a GPIO pin is 3.3V. Pushing 5V into a GPIO pin will back-feed the SoC's internal protection diodes, overheat the silicon, and permanently brick the board.

⚠️ The 5V Tolerance Trap: Unlike the ATmega328P on an Arduino Uno, Rasp Pi GPIO pins are not 5V tolerant. If you need to read a 5V sensor output, you must use a voltage divider, an optocoupler, or a dedicated logic level shifter (like the Texas Instruments TXB0108 or a cheap BSS138 MOSFET module).

Furthermore, current sourcing is strictly limited. According to the official Raspberry Pi documentation, while a single pin can safely source up to 16mA, the combined total current sourced by all GPIO pins simultaneously must not exceed 50mA.

Worked Example: Sizing an LED Array

Let’s say you want to wire a status indicator using 6 standard red LEDs directly to 6 different GPIO pins.

Given: GPIO output = 3.3V | Red LED forward voltage ($V_f$) = 2.0V | Target LED current = 8mA (plenty bright for an indicator).
  1. Calculate the resistor for one LED: Using Ohm’s Law ($R = V / I$), the voltage drop across the resistor is $3.3V - 2.0V = 1.3V$.
    $R = 1.3V / 0.008A = 162.5\Omega$. The nearest standard E12 resistor value is 180Ω.
  2. Verify actual current per pin: $I = 1.3V / 180\Omega = 7.2mA$. This is safely under the 16mA per-pin limit.
  3. Check the bank limit: If all 6 LEDs turn on at the exact same time, the total current draw is $6 \times 7.2mA = \mathbf{43.2mA}$.

Because 43.2mA is under the 50mA combined limit, this circuit is safe. However, if you decided to add two more LEDs to the same setup (8 total), the draw would be 57.6mA, violating the 50mA combined limit and risking voltage sag or SoC damage. To fix an 8-LED array, you would either increase the resistor value to drop the per-LED current to 5mA (total 40mA), or use a ULN2803 Darlington transistor array to sink the current from the 5V rail instead of sourcing it from the GPIOs.

Where You Meet Rasp Pi GPIO in Practice

Theory is clean; the workbench is messy. Here is how GPIO actually behaves when interfacing with common hardware.

Driving Mechanical Relays

You cannot drive a standard 5V mechanical relay coil directly from a GPIO pin. A typical relay coil draws 70mA to 100mA, which instantly exceeds the 16mA pin limit and will fry the BCM chip. In practice, you use the GPIO pin to drive the base of an NPN transistor (like a 2N2222 or a logic-level MOSFET like the IRLZ44N). The GPIO supplies less than 2mA to the transistor base, and the transistor switches the high-current 5V relay coil. You must also place a flyback diode (e.g., 1N4007) in reverse parallel across the relay coil to suppress the inductive voltage spike when the coil de-energizes.

Reading Pushbuttons and Switches

A GPIO pin configured as an input has high impedance—it floats. If you wire a button between a GPIO pin and Ground, pressing the button pulls the pin LOW, but releasing it leaves the pin floating, susceptible to electromagnetic noise, causing phantom triggers. In practice, you must enable the internal pull-up resistor in your software (setting the pin to read HIGH by default), or wire an external 10kΩ pull-up resistor to the 3.3V rail.

I2C Sensor Buses

When wiring I2C devices (like a BME280 temperature sensor or an OLED display) to physical pins 3 and 5 (BCM 2 and 3), remember that the Raspberry Pi already includes 1.8kΩ pull-up resistors on these specific pins. If your sensor breakout board also has onboard pull-ups (common on Adafruit and SparkFun boards), the parallel resistance drops. Two 1.8kΩ resistors in parallel yield 900Ω, which pulls the I2C lines up to 3.3V very aggressively. While usually fine for short runs at 100kHz, this can cause signal reflection and data corruption at 400kHz over long wires.

BCM vs. Board Pin Numbering: The Software Disconnect

The physical header has 40 pins, numbered 1 through 40, starting from the top-left (Pin 1, 3.3V) and zig-zagging down. However, the Broadcom SoC inside the Pi has its own internal numbering scheme (BCM). Physical Pin 12 is BCM GPIO 18. Physical Pin 7 is BCM GPIO 4.

When writing Python scripts using the RPi.GPIO or gpiozero libraries, you must explicitly declare which numbering system you are using. If you don't, your code will toggle the wrong physical pin, potentially sending 3.3V into a ground loop or a sensor's data line.

import RPi.GPIO as GPIO

# ALWAYS set the mode at the start of your script
GPIO.setmode(GPIO.BCM)  # Use Broadcom SoC pin numbers (Recommended)
# GPIO.setmode(GPIO.BOARD) # Use physical header pin numbers

GPIO.setup(18, GPIO.OUT) # Toggles Physical Pin 12

Best Practice: Always use GPIO.BCM. It aligns with the official schematics, makes reading the BCM2711 datasheet easier, and ensures your code remains portable if you move from a Pi 4 to a Pi Zero, where the physical layout is smaller but the BCM numbers remain identical.

Frequently Asked Questions

Can I power the Raspberry Pi through the 5V GPIO pins?

Yes, you can back-power the Pi by supplying 5.1V to physical Pin 2 or 4, and Ground to Pin 6. This bypasses the USB-C input's polyfuse and power management IC. Only do this if you are using a high-quality, regulated 5.1V power supply with its own over-current protection, as you are directly feeding the board's 5V rail.

Why does my GPIO pin read HIGH when I haven't set it?

Floating inputs act as antennas, picking up ambient 50/60Hz mains hum and RF noise. If a pin is configured as an input without a pull-up or pull-down resistor, its state is undefined. Always use GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) in your code to stabilize the idle state.

What is the maximum switching frequency of a Rasp Pi GPIO pin?

Using standard Python libraries, you can reliably toggle a pin at about 1 MHz to 5 MHz depending on CPU load and OS jitter. For higher frequencies (up to 20+ MHz), you must use C/C++ with direct memory access to the GPIO registers, or offload the task to the Pi's hardware PWM or DMA-backed SPI peripherals.