Raspberry Pi GPIO Basics
GPIO (General Purpose Input/Output) pins let a Raspberry Pi read sensors and control electronic components, turning it into a bridge between code and the physical world.
What Is GPIO?
GPIO pins are programmable connections on the Raspberry Pi's header that software can configure as either an output or an input. As an output, a pin can be switched between roughly 0 volts and 3.3 volts to represent off and on, which is enough to light an LED directly or, through a driver circuit, switch something larger like a motor or relay. As an input, the same kind of pin can instead read whether an external voltage is present, which is how a button press, a switch, or a sensor's signal gets detected by your program.
3.3V Logic: Not 5V Tolerant
One of the most important facts to know before wiring anything up is that Raspberry Pi GPIO pins operate at 3.3-volt logic, and unlike some other hobbyist boards, they are not 5V tolerant. Feeding 5 volts into a GPIO pin configured as an input can damage that pin, and in some cases the board itself. Plenty of common sensors and modules are designed around 5V logic, so before connecting one, check its datasheet and use a level shifter or a simple voltage divider to bring the signal down to a safe 3.3V range.
Digital Input vs Output
- Output mode: your code drives a pin high or low to control something external, like turning an LED on or off
- Input mode: your code reads whether an external voltage is currently present on a pin, such as detecting a button press
- Pull-up and pull-down resistors hold an input pin at a known level when nothing is actively driving it, preventing unreliable "floating" readings
Physical Pin Numbers vs BCM/GPIO Numbers
There are two different numbering systems in play, and mixing them up is one of the most common beginner mistakes. Physical pin numbering simply counts position on the header, 1 through 40, left to right and top to bottom. BCM (Broadcom) numbering, often just called "GPIO numbers," refers to the actual channel number on the SoC, and those numbers don't run in the same order around the header at all. Most programming libraries let you pick which scheme you're using, but if code refers to "GPIO17" it means the BCM number, not physical pin 17.
Blinking an LED With gpiozero
from gpiozero import LED
from time import sleep
# 17 here is a BCM/GPIO number, which is physical pin 11 on the header
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)Exercise: Raspberry Pi GPIO Basics
What does GPIO stand for?