The Raspberry Pi 3 (specifically the Model B and B+ variants) features a 40-pin GPIO header. Pin 1 supplies 3.3V, Pin 2 supplies 5V, Pin 6 is Ground, and the remaining pins offer 26 usable GPIO channels alongside dedicated hardware I2C (Pins 3 and 5), SPI, and UART interfaces. All GPIO pins operate at 3.3V logic levels; feeding 5V into any GPIO pin will permanently destroy the BCM2837 SoC. This guide maps the exact Raspberry Pi 3 pin layout, provides a tested Python build, and details the exact debugging steps for common GPIO failures.

Raspberry Pi 3 Model B+ Spec Sheet & Parts List

While the Raspberry Pi 4 and 5 dominate new deployments in 2026, the Pi 3 Model B+ remains a staple in industrial IoT, legacy kiosks, and budget-conscious maker projects due to its identical 40-pin footprint and lower secondary-market cost ($35–$45 USD refurbished). The code and wiring in this guide specifically target the Raspberry Pi 3 Model B+ (1GB RAM, BCM2837B0 SoC) running Raspberry Pi OS (Bookworm or Bullseye).

Difficulty Rating: Beginner-Intermediate (2/5)
Estimated Time: 20 minutes for wiring, 10 minutes for software setup.

Required Parts & Exact Variants

ComponentExact Variant / SpecificationEstimated 2026 Cost
MicrocontrollerRaspberry Pi 3 Model B+ (Element14 or RS Components OEM)$35 - $45 (Refurb)
Breakout BoardAdafruit Pi Cobbler+ (PID: 2028) or official GPIO Ribbon Cable$12.50
Jumper WiresMale-to-Female and Male-to-Male Dupont (24 AWG, 20cm)$6.00 / pack
LEDStandard 5mm Through-Hole (Red or Green, 2.0V forward voltage)$0.10
Resistor330Ω Carbon Film (1/4W, 5% tolerance)$0.02
Switch6x6mm Tactile Pushbutton (4-pin, normally open)$0.15

The 40-Pin Header: Complete Pin Mapping Table

Understanding the Raspberry Pi 3 pin layout requires distinguishing between physical pin numbers and Broadcom (BCM) GPIO channel numbers. The physical layout is identical across the Pi 3B, 3B+, 4, and 5. Below is the functional mapping. Always orient the board with the USB ports facing you and the GPIO header on the top left; Pin 1 is the top-left pin (closest to the SD card slot).

FunctionPhysical Pin(s)BCM GPIONotes & Constraints
3.3V Power1, 17N/AMax total draw across all 3.3V pins: 50mA.
5V Power2, 4N/ADirect from USB input. Do not backfeed >5.25V.
Ground6, 9, 14, 20, 25, 30, 34, 39N/ACommon ground for all circuits.
Hardware I2C3 (SDA), 5 (SCL)GPIO 2, GPIO 3Includes onboard 1.8kΩ pull-up resistors to 3.3V.
Hardware SPI19 (MOSI), 21 (MISO), 23 (SCLK), 24 (CE0)GPIO 10, 9, 11, 8SPI0 interface. High-speed peripheral comms.
Hardware UART8 (TXD), 10 (RXD)GPIO 14, GPIO 15Default console serial. Must disable serial console in raspi-config for general use.
General GPIO7, 11, 12, 13, 15, 16, 18, 22, 26, 27, 28, 29, 31, 32, 33, 35, 36, 37, 38, 40Various (e.g., Pin 11 = GPIO 17)Configurable as input/output. Max 16mA per pin.
Safety Warning: The Raspberry Pi 3 GPIO pins tolerate exactly 3.3V. Connecting a 5V Arduino output directly to a Pi 3 GPIO pin will overvoltage the BCM2837 silicon, causing immediate thermal failure of the SoC. Always use a logic level shifter (like the BSS138 bidirectional converter) when bridging 5V and 3.3V systems.

Hands-On Build: Button-Triggered LED Circuit

This build demonstrates correct wiring using the BCM numbering scheme, which is the modern standard for Raspberry Pi OS. We will wire a tactile button to GPIO 27 and an LED to GPIO 17.

Wiring Steps

  1. Power Down: Disconnect the Pi 3 from its 5V micro-USB power supply. Never wire GPIO pins while the board is energized.
  2. LED Circuit: Connect a jumper wire from Physical Pin 11 (BCM GPIO 17) to the anode (long leg) of the 5mm LED. Connect the cathode (short leg) to one leg of the 330Ω resistor. Connect the other leg of the resistor to Physical Pin 6 (Ground).
  3. Button Circuit: Place the tactile switch across the breadboard center trench. Connect Physical Pin 13 (BCM GPIO 27) to one side of the switch. Connect Physical Pin 39 (Ground) to the opposite side of the switch. (The Pi's internal pull-up resistor will handle the high state; no external resistor is needed).
  4. Verify: Double-check that no 5V pins (Physical 2 or 4) are touching your GPIO jumper wires.

Complete Python Code (gpiozero)

The following code targets the Pi 3 Model B+ using the gpiozero library, which abstracts the sysfs/lgpio backend in modern Raspberry Pi OS. It includes explicit pin definitions and error handling to catch hardware faults.

#!/usr/bin/env python3
import sys
import logging
from gpiozero import LED, Button
from signal import pause

# Explicit Pin Definitions (BCM Numbering)
LED_PIN = 17
BUTTON_PIN = 27

logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def main():
    try:
        logging.info(f'Initializing LED on BCM {LED_PIN} and Button on BCM {BUTTON_PIN}')
        
        # Initialize hardware with internal pull-up and software debouncing
        led = LED(LED_PIN)
        button = Button(BUTTON_PIN, pull_up=True, bounce_time=0.05)
        
        # Map events to functions
        button.when_pressed = led.on
        button.when_released = led.off
        
        logging.info('Hardware initialized successfully. Press Ctrl+C to exit.')
        pause() # Keep the script running
        
    except RuntimeError as e:
        logging.error(f'GPIO Access Error: {e}')
        logging.error('Ensure you are running on a Raspberry Pi and have lgpio/gpiozero installed.')
        sys.exit(1)
    except KeyboardInterrupt:
        logging.info('Script terminated by user. Cleaning up GPIO states.')
        sys.exit(0)
    except Exception as e:
        logging.critical(f'Unexpected hardware failure: {e}')
        sys.exit(2)

if __name__ == '__main__':
    main()

Debugging GPIO Failures: First Three Things to Check

When your circuit fails to respond, avoid rewriting code immediately. Hardware and permission faults account for 90% of Pi 3 GPIO issues. Here are the first three things to check, along with the exact error strings they produce.

1. Permissions and Backend Access

The Symptom: Your script crashes immediately upon initializing a pin.
Exact Error String: RuntimeError: No access to /dev/mem. Try running as root! or gpiozero.exc.BadPinFactory: Unable to load any default pin factory!
The Fix: In older Pi OS releases, RPi.GPIO required sudo. Modern gpiozero uses the lgpio backend which respects user groups. Ensure your user is in the gpio and dialout groups by running sudo usermod -aG gpio,dialout $USER, then reboot. If using a headless lite image, install the backend: sudo apt install python3-lgpio.

2. Pin Numbering Scheme Mismatch (BCM vs BOARD)

The Symptom: The code runs without errors, but the physical LED does not light up.
The Cause: You are mixing up Physical Pin numbers with BCM GPIO numbers. If you set LED_PIN = 11 thinking of the physical header, the Pi actually activates BCM GPIO 11 (which is Physical Pin 23, the SPI SCLK pin).
The Fix: Always verify your numbering scheme. gpiozero defaults strictly to BCM. If you must use physical pin numbers with legacy RPi.GPIO, you must explicitly declare GPIO.setmode(GPIO.BOARD). We strongly recommend standardizing on BCM across all projects.

3. Pin State Lock / Zombie Processes

The Symptom: You stopped a previous script with Ctrl+Z or it crashed, and now the new script throws warnings.
Exact Error String: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
The Fix: A background process is still holding the GPIO file descriptor. Run ps aux | grep python to find zombie scripts and kill them with kill -9 [PID]. The gpiozero library handles cleanup automatically on exit, which is why it is preferred over RPi.GPIO for new builds.

Extending and Simplifying Your Build

Once you have mastered the basic Raspberry Pi 3 pin layout, you will quickly outgrow direct breadboard wiring. Here is how to scale your project.

How to Simplify: Use a Breakout Board

Directly plugging female Dupont wires into the Pi 3 header is fragile; a single misaligned pin can short 5V to Ground and fry the board's polyfuse or SoC. Simplify your physical build by using the Adafruit Pi Cobbler+. It connects via a 40-pin ribbon cable, breaks the pins out onto a standard solderless breadboard, and silkscreens the BCM GPIO numbers directly onto the PCB, eliminating the need to count pins from the edge of the board.

How to Extend: Add I2C Sensor Networks

The Pi 3's hardware I2C bus (Physical Pins 3 and 5) allows you to daisy-chain up to 127 devices without consuming extra GPIO pins. To extend this build, wire a Bosch BME280 environmental sensor to Pin 1 (3.3V), Pin 6 (GND), Pin 3 (SDA), and Pin 5 (SCL). Enable the I2C interface via sudo raspi-config (Interface Options > I2C), then use the adafruit-circuitpython-bme280 library to read temperature and humidity alongside your button inputs.

Frequently Asked Questions

What is the difference between the Raspberry Pi 3 and Pi 4 pin layout?

Electrically and physically, the 40-pin header layout is identical between the Pi 3B, 3B+, 4B, and 5. Pin 1 is always 3.3V, Pin 2 is 5V, and the BCM GPIO mappings for standard pins remain the same. However, the Pi 4 and 5 feature upgraded power delivery circuits and support PCIe (on the Pi 5 via a separate connector). Code written for the Pi 3 using gpiozero will run natively on a Pi 4 without modification, provided you are using the same BCM pin definitions.

Can I power the Raspberry Pi 3 through the GPIO pins?

Yes, but it bypasses the board's onboard polyfuse and voltage regulation protection. To power the Pi 3 via the header, inject exactly 5.1V DC into Physical Pin 2 or 4 (5V), and connect your ground to Physical Pin 6. The Pi 3 requires a stable 5.1V to compensate for voltage drop across the PCB traces under load. Do not exceed 5.25V, and ensure your power supply can deliver at least 2.5A. If you exceed 5.25V, you will instantly destroy the SoC.

Which Raspberry Pi 3 pins are safe for 5V inputs?

None of the GPIO data pins are safe for 5V inputs. All 26 GPIO channels (e.g., GPIO 17, GPIO 27, GPIO 22) operate strictly at 3.3V logic and are not 5V tolerant. The only pins on the entire 40-pin header that handle 5V are the dedicated 5V Power pins (Physical Pins 2 and 4). If you need to read a 5V signal (like from an Arduino or a 12V automotive relay), you must use an optocoupler or a voltage divider to step the logic level down to 3.3V before it reaches the Pi 3 header.