Skip to main content

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 pinFunction
1, 173.3V power
2, 45V power (straight from the power supply)
6, 9, 14, 20, 25, 30, 34, 39GND (ground)
3GPIO2, I2C SDA
5GPIO3, I2C SCL
7GPIO4, default 1-Wire pin (DS18B20)
8GPIO14, UART TX
10GPIO15, UART RX
11GPIO17
12GPIO18 (hardware PWM)
13GPIO27
15GPIO22
16GPIO23
18GPIO24
19, 21, 23, 24SPI: 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​

BusPinsUsed forTurn on with
I2CSDA (pin 3), SCL (pin 5)Many sensors and displays on 2 wires; each device has an addressraspi-config → Interface Options → I2C
SPIpins 19, 21, 23, 24Fast devices, ADC chips (MCP3008)raspi-config → Interface Options → SPI
UART (serial)TX (pin 8), RX (pin 10)Serial devices, GPS modulesraspi-config → Interface Options → Serial Port
1-WireGPIO4 (pin 7)DS18B20 temperature sensorraspi-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.