GPIO pins
The 40-pin header lets the Pi read buttons and sensors and switch LEDs, buzzers and relays directly, without an Arduino. GPIO means General Purpose Input/Output. The labs use the Arduino for sensors, so this page is extra: for projects and for understanding what the Arduino does for you.
Two ways to number pins
- Physical (board) numbers: 1 to 40, counted along the header. Pin 1 is the corner pin nearest the SD card side, marked with a square pad.
- BCM / GPIO numbers: the chip's names, like GPIO17. Python libraries such as gpiozero use these.
Always check which numbering your code uses. GPIO17 is physical pin 11, not pin 17.
Run pinout in the Pi terminal to print a map of your board's header.
Common pins
| Physical pin | Function |
|---|---|
| 1, 17 | 3.3V power |
| 2, 4 | 5V power (straight from the power supply) |
| 6, 9, 14, 20, 25, 30, 34, 39 | GND (ground) |
| 3 | GPIO2, I2C SDA |
| 5 | GPIO3, I2C SCL |
| 7 | GPIO4, default 1-Wire pin (DS18B20) |
| 8 | GPIO14, UART TX |
| 10 | GPIO15, UART RX |
| 11 | GPIO17 |
| 12 | GPIO18 (hardware PWM) |
| 13 | GPIO27 |
| 15 | GPIO22 |
| 16 | GPIO23 |
| 18 | GPIO24 |
| 19, 21, 23, 24 | SPI: MOSI, MISO, SCLK, CE0 |
Rules to protect the Pi
- GPIO pins are 3.3V. Putting 5V on an input pin can destroy the Pi. Sensors that output 5V (like the HC-SR04 echo pin) need a voltage divider or a level shifter. See Sensors on the Raspberry Pi.
- A GPIO pin can only supply a small current (keep it under about 16 mA). Always use a resistor with an LED (220 to 330 ohm). Use a transistor or relay module for motors and other big loads.
- The Pi has no analog inputs. To read an analog sensor (potentiometer, light sensor, Grove analog sensor) you need an ADC chip such as the MCP3008 (SPI) or ADS1115 (I2C), or let an Arduino read it and send the value to the Pi (see Arduino to Raspberry Pi).
Buses: I2C, SPI, UART, 1-Wire
| Bus | Pins | Used for | Turn on with |
|---|---|---|---|
| I2C | SDA (pin 3), SCL (pin 5) | Many sensors and displays on 2 wires; each device has an address | raspi-config → Interface Options → I2C |
| SPI | pins 19, 21, 23, 24 | Fast devices, ADC chips (MCP3008) | raspi-config → Interface Options → SPI |
| UART (serial) | TX (pin 8), RX (pin 10) | Serial devices, GPS modules | raspi-config → Interface Options → Serial Port |
| 1-Wire | GPIO4 (pin 7) | DS18B20 temperature sensor | raspi-config → Interface Options → 1-Wire |
Reboot after turning one on.
Checking I2C devices
sudo apt install -y i2c-tools
i2cdetect -y 1
The table shows the address of each device found, for example 3e and 62 for a Grove LCD RGB backlight display. An empty table means wiring or power is wrong, or I2C is off.