Raspberry Pi GPIO (General Purpose Input/Output) pins are software-configurable digital interfaces on the Broadcom SoC that allow the Pi to read binary logic states from sensors or output 3.3V control signals to external circuits. In a real installation, this changes your architecture by eliminating the need for USB-to-serial intermediaries when toggling raw hardware states or reading bare sensors. The most fatal confusion makers encounter is assuming these pins tolerate the 5V logic of an Arduino Uno; they do not, and feeding 5V into a Pi GPIO will permanently destroy the silicon.
BCM vs. Board Numbering: The Pinout Trap
When you look at the 40-pin header on a Raspberry Pi 4 or 5, you are looking at a mix of power rails, grounds, and 28 usable GPIO pins. The confusion starts when you write your first Python or C++ script. There are two numbering schemes, and mixing them up is the leading cause of 'my pin isn't working' support tickets.
- BOARD Numbering: Refers to the physical pin number on the header (1 through 40). Pin 1 is always the 3.3V power pin, and Pin 2 is 5V. Pin 7 is the first usable GPIO (GPIO4).
- BCM Numbering: Refers to the Broadcom SoC internal channel numbers. The physical Pin 7 on the header maps to BCM GPIO 4.
For modern development, always default to BCM numbering. The Pinout.xyz interactive map is the industry-standard reference for mapping physical headers to BCM channels. If you are using the RPi.GPIO or gpiozero Python libraries, set your mode to BCM immediately after importing the library to align your code with the silicon datasheets.
Sourcing and Sinking: A Worked Numeric Example
Let’s move from theory to the bench. You want to drive a standard 5mm red LED directly from a Pi GPIO pin. You cannot just wire the LED to the pin; you must calculate a current-limiting resistor to protect the Broadcom chip.
The Calculation
First, identify your known values:
- Source Voltage (Vcc): 3.3V (The Pi GPIO HIGH state)
- LED Forward Voltage (Vf): 2.0V (Typical for a standard red LED)
- Target Current (I): 10mA (0.010A). While the pin can source 16mA, 10mA is bright enough for indication and keeps us safely under the 50mA total bank limit if we add more LEDs later.
Using Ohm’s Law (R = V / I), we calculate the voltage drop required across the resistor:
V_resistor = Vcc - Vf = 3.3V - 2.0V = 1.3V
R = 1.3V / 0.010A = 130 Ω
The nearest standard E12 series resistor value above 130Ω is 150Ω. Using a 150Ω resistor yields a safe current of roughly 8.6mA. For power dissipation, P = I²R = (0.0086)² × 150 = 0.011W. A standard 1/4W (0.25W) through-hole resistor will run completely cool.
Where You Meet Pi GPIO in Practice
You will rarely use GPIO pins just to toggle LEDs. In practical embedded systems, Pi GPIO acts as the control layer for three primary tasks:
1. Reading Mechanical Switches (Pull-up Resistors)
When wiring a pushbutton to a GPIO pin, the pin must never be left 'floating' when the button is open, or it will read random electromagnetic noise as button presses. You need a pull-up resistor to hold the pin at 3.3V until the button pulls it to Ground. The official Raspberry Pi documentation notes that the BCM2711 (Pi 4) has internal pull-ups of roughly 50kΩ. While you can enable these in software, in electrically noisy environments (like near AC motors), you should solder an external 10kΩ pull-up resistor between the 3.3V rail and the GPIO pin for a stiffer, noise-immune logic high.
2. I2C and SPI Communication
Pins 3 (SDA) and 5 (SCL) are hardcoded for the I2C bus. Unlike digital outputs, I2C is an open-drain protocol. The Pi's internal pull-ups are too weak (50kΩ) to pull the bus high fast enough at 400kHz speeds. In practice, you must add external 4.7kΩ pull-up resistors to both SDA and SCL lines when interfacing sensors like the BME280 or MPU6050.
3. PWM (Pulse Width Modulation)
Hardware PWM on the Pi is limited. While you can generate software PWM on any pin using libraries like pigpio, it suffers from jitter under heavy CPU load. For precise motor control or audio generation, route your signals to GPIO 12, 13, 18, or 19, which map to the dedicated hardware PWM channels.
Decision Tree: Interfacing External Hardware Safely
Choosing the right interface component prevents fried boards. Use this decision matrix to select the exact part number for your next build.
| Scenario / Load | Hazard / Risk | Concrete Solution (Part Number) |
|---|---|---|
| Switching a 12V 500mA solenoid or DC motor | Inductive flyback voltage spikes will exceed 3.3V and destroy the GPIO pin upon turn-off. | ULN2803A Darlington transistor array. It includes built-in clamp diodes to safely dissipate flyback energy. |
| Reading a 5V HC-SR04 Ultrasonic Sensor ECHO pin | The 5V logic HIGH from the sensor will overvoltage the 3.3V Pi GPIO input. | BSS138 Bidirectional Logic Level Converter. Wire the 5V side to the sensor, 3.3V side to the Pi. |
| Switching 120V/240V AC Mains loads | Lethal shock risk; ground loops; AC noise coupling back into the Pi's DC ground. | PC817 Optoisolator. Use the GPIO to light the internal LED, and let the phototransistor switch a mechanical relay module. |
| Driving a 5V 500mA Servo Motor (e.g., MG996R) | Servo stall current can exceed 1A, causing severe voltage sag on the Pi's 5V rail and rebooting the board. | External 5V UBEC (Universal Battery Elimination Circuit) to power the servo directly from the battery, using the Pi GPIO only for the PWM signal wire. |
Frequently Asked Questions
Does the Raspberry Pi 5 handle GPIO differently than the Pi 4?
Yes. The Raspberry Pi 4 uses the BCM2711 SoC, which handles GPIO directly. The Raspberry Pi 5 uses the BCM2712, but offloads all peripheral and GPIO management to a separate RP1 southbridge chip. While your Python code remains largely identical, the underlying memory addresses for the GPIO registers have changed. If you are writing bare-metal C or using custom device tree overlays, you must target the RP1 architecture, not the main Broadcom CPU.
Can I power a Raspberry Pi by feeding 5V into the 5V GPIO pins?
You can, but it bypasses the board's primary polyfuse and power management IC (PMIC) protections. If your external 5V supply spikes to 6V, you will instantly kill the board. The safest method for custom power integration is to feed 5V into the dedicated 5V and Ground pins on the header (Pins 2 and 6), but ensure your power supply is highly regulated and fused.
Why does my I2C sensor fail when I connect multiple devices?
Every device you add to the I2C bus adds parasitic capacitance. If you connect more than three or four sensors, the 4.7kΩ pull-up resistors can no longer charge the bus capacitance fast enough to register a logic HIGH within the I2C clock cycle. The fix is to either lower the pull-up resistor value to 2.2kΩ, or reduce the I2C bus speed from 400kHz to 100kHz in your config.txt file.
When designing your next embedded project, default to BCM numbering in your code, always use a BSS138 level shifter when talking to 5V logic, and never draw more than 16mA from a single pin. Treat the 3.3V logic limit as an absolute physical boundary, and your Raspberry Pi will survive years of bench testing without a bricked SoC.






