0
0
Raspberry Piprogramming~5 mins

GPIO pin numbering (BCM vs BOARD) in Raspberry Pi

Choose your learning style9 modes available
Introduction

GPIO pins on a Raspberry Pi can be numbered in two ways. Knowing the difference helps you connect and control devices correctly.

When you want to control LEDs or sensors connected to your Raspberry Pi.
When you follow a tutorial that uses a specific pin numbering system.
When you write code that needs to work with physical pin locations or chip pin numbers.
When you troubleshoot hardware connections on your Raspberry Pi.
Syntax
Raspberry Pi
import RPi.GPIO as GPIO

# Use BCM numbering
GPIO.setmode(GPIO.BCM)

# Use BOARD numbering
GPIO.setmode(GPIO.BOARD)

BCM means Broadcom chip pin numbers, which refer to the processor's pin numbers.

BOARD means the physical pin numbers on the Raspberry Pi's header.

Examples
This uses BCM numbering to turn on the pin connected to GPIO 18.
Raspberry Pi
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
This uses BOARD numbering to turn on the pin at physical pin 12.
Raspberry Pi
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
Sample Program

This program blinks an LED connected to GPIO pin 18 using BCM numbering. It turns the LED on and off three times with half-second pauses.

Raspberry Pi
import RPi.GPIO as GPIO
import time

# Choose BCM numbering
GPIO.setmode(GPIO.BCM)

# Set GPIO 18 as output
GPIO.setup(18, GPIO.OUT)

# Blink LED connected to GPIO 18 three times
for _ in range(3):
    GPIO.output(18, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(18, GPIO.LOW)
    time.sleep(0.5)

GPIO.cleanup()
OutputSuccess
Important Notes

Always call GPIO.cleanup() at the end to reset pins safely.

Using the wrong numbering system can cause your hardware not to work or even damage it.

Check your Raspberry Pi model's pinout diagram to match physical pins with BCM numbers.

Summary

GPIO pins can be numbered by BCM (chip) or BOARD (physical) systems.

Use GPIO.setmode(GPIO.BCM) or GPIO.setmode(GPIO.BOARD) to select the system.

Pick the numbering that matches your hardware setup or tutorial instructions.