12 Min Read • Updated June 2026

How Raspberry Pi GPIO Works: 40-Pin Pinout, PWM, I2C, SPI & Python Control Explained

The Raspberry Pi's 40-pin GPIO header connects your Linux computer to the physical world — sensors, motors, displays, and custom electronics. Understanding the 3.3V logic, current limits, and dual-function pin capabilities is essential before wiring anything.

Close-up of Raspberry Pi 4 40-pin GPIO header with colorful jumper wires connected and GPIO pinout diagram showing power ground digital PWM I2C SPI UART pins
GPIO Pins

26 usable GPIO (40-pin header)

Logic Level

3.3 V (NOT 5V tolerant)

Max GPIO Current

16 mA per pin, 50 mA total

PWM Channels

2 hardware PWM (GPIO12, GPIO13)

I2C Buses

I2C1 on GPIO2 (SDA), GPIO3 (SCL)

SPI Buses

SPI0: GPIO10 (MOSI), GPIO9 (MISO), GPIO11 (SCLK)

GPIO Fundamentals: 3.3V Logic, Current Limits & Critical Rules

Definition: GPIO (General Purpose Input/Output) pins on a Raspberry Pi are software-configurable digital pins that can read external signals (input) or drive external circuits (output) at 3.3V logic, individually current-limited to 16 mA.
  • [Raspberry Pi GPIO] [operates at] [3.3V — not 5V tolerant like Arduino]
  • [Each GPIO pin] [sources or sinks] [maximum 16 mA safely]
  • [5V input on GPIO pin] [permanently destroys] [the BCM2711 SoC]
⚠️ CRITICAL: GPIO pins are 3.3V only. Connecting 5V directly to any GPIO input will permanently destroy the pin and possibly the entire Raspberry Pi. Always use a voltage divider or 74LVC2T45 level shifter when interfacing with 5V devices.

Special-Function GPIO Pins: I2C, SPI, UART & Hardware PWM

Most GPIO pins are general-purpose digital I/O, but these have dedicated hardware peripherals mapped to them:

GPIO (BCM)Alt FunctionPhysical PinNotes
GPIO2 (SDA)I2C SDAPin 3I2C data line — has built-in 1.8kΩ pull-up
GPIO3 (SCL)I2C SCLPin 5I2C clock line — has built-in 1.8kΩ pull-up
GPIO14 (TXD)UART TXPin 8Serial transmit — disable console for use
GPIO15 (RXD)UART RXPin 10Serial receive — disable console for use
GPIO12Hardware PWM0Pin 32True hardware PWM — precise frequency
GPIO13Hardware PWM1Pin 33True hardware PWM channel 2
GPIO10 (MOSI)SPI0 MOSIPin 19SPI Master Out Slave In
GPIO9 (MISO)SPI0 MISOPin 21SPI Master In Slave Out
GPIO11 (SCLK)SPI0 ClockPin 23SPI clock line

Python GPIO Control: RPi.GPIO vs gpiozero

RPi.GPIO (Low-Level)

import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.HIGH) # Always cleanup! GPIO.cleanup()

gpiozero (Recommended)

from gpiozero import LED, Button led = LED(17) # BCM pin btn = Button(2) btn.when_pressed = led.on btn.when_released = led.off pause() # Keep running
Recommendation: Use gpiozero for new projects — it is the officially recommended library by the Raspberry Pi Foundation, handles cleanup automatically, and provides high-level abstractions for LEDs, buttons, motors, servos, and sensors.

Frequently Asked Questions

What voltage do Raspberry Pi GPIO pins use?

3.3V logic — NOT 5V tolerant. HIGH = 3.3V, LOW = 0V. Connecting 5V to GPIO input permanently destroys the pin. Use a voltage divider (1kΩ + 2kΩ) or level shifter for all 5V device interfaces.

What is the difference between BCM and BOARD GPIO numbering?

BCM uses Broadcom SoC GPIO numbers (GPIO17, GPIO27 etc.) — used in most tutorials and libraries. BOARD uses physical pin numbers 1–40. In RPi.GPIO: GPIO.setmode(GPIO.BCM) or GPIO.setmode(GPIO.BOARD). BCM is recommended for portability.

How many GPIO pins does a Raspberry Pi have?

The 40-pin header (Pi 2/3/4/5) has 26 usable GPIO pins. Remaining pins: 5V×2, 3.3V×2, GND×8, ID_SD/ID_SC (HAT EEPROM). Pi 1 had only 17 GPIO on a 26-pin header.

How do I control GPIO in Python on Raspberry Pi?

gpiozero (recommended): from gpiozero import LED, Button. RPi.GPIO (low-level): import RPi.GPIO as GPIO; GPIO.setmode(GPIO.BCM); GPIO.setup(17, GPIO.OUT); GPIO.output(17, True); GPIO.cleanup(). Always call cleanup() with RPi.GPIO to reset pins.

Can Raspberry Pi GPIO pins be damaged by over-current or over-voltage?

Yes. Max 16mA per pin, 50mA total. Always use a resistor with LEDs (220–470Ω). Input voltage above 3.3V destroys GPIO. For motors/relays, use a MOSFET or transistor buffer — never connect directly to GPIO.

Conclusion

The Raspberry Pi GPIO transforms a $35 computer into a physical computing platform capable of interfacing with virtually any electronic component — from a simple LED to a full robotics system. The critical rules: respect the 3.3V logic level, stay within 16mA per pin, and always use gpiozero's high-level abstractions for clean, safe Python code.

📚 References & Sources

Was this article helpful?

Tap a star to rate — no account needed

Related Resources