GPIO pins on a Raspberry Pi can be numbered in two ways. Knowing the difference helps you connect and control devices correctly.
GPIO pin numbering (BCM vs BOARD) in 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.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.HIGH)
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) GPIO.output(12, GPIO.HIGH)
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.
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()
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.
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.
Practice
Solution
Step 1: Understand GPIO numbering modes
GPIO pins can be numbered by their physical location (BOARD) or by the Broadcom chip numbering (BCM).Step 2: Identify physical pin numbering
BOARD mode refers to the physical pin numbers on the Raspberry Pi header.Final Answer:
BOARD numbering mode -> Option AQuick Check:
Physical pins = BOARD [OK]
- Confusing BCM with physical pin numbers
- Thinking BCM is the physical numbering
- Assuming WIRING or PIN modes exist
Solution
Step 1: Recall the correct function to set GPIO mode
The function to set numbering mode is GPIO.setmode().Step 2: Use the correct constant for BCM mode
GPIO.BCM is the constant for BCM numbering mode.Final Answer:
GPIO.setmode(GPIO.BCM) -> Option DQuick Check:
Use setmode with BCM constant [OK]
- Using GPIO.mode instead of GPIO.setmode
- Using BOARD instead of BCM constant
- Calling GPIO.setupmode which doesn't exist
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.output(7, GPIO.HIGH)
Which physical pin is set HIGH?
Solution
Step 1: Identify the numbering mode used
The code uses GPIO.setmode(GPIO.BOARD), so pin numbers refer to physical header pins.Step 2: Check which pin is set HIGH
GPIO.setup(7, GPIO.OUT) and GPIO.output(7, GPIO.HIGH) set physical pin 7 HIGH.Final Answer:
Pin 7 on the physical header -> Option CQuick Check:
BOARD mode pin 7 = physical pin 7 [OK]
- Confusing BOARD pin 7 with BCM GPIO 7
- Assuming pin 7 means BCM numbering
- Mixing physical pin numbers with BCM numbers
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(10, GPIO.OUT) GPIO.output(10, GPIO.HIGH)
Assuming the LED is wired to physical pin 10 on the header.
Solution
Step 1: Understand numbering mismatch
GPIO.setmode(GPIO.BCM) means pin numbers refer to Broadcom chip pins, not physical pins.Step 2: Check wiring vs numbering
Physical pin 10 corresponds to BCM GPIO 15. The code uses BCM pin 10 (physical pin 19), so it does not control the wired physical pin 10.Final Answer:
Pin 10 in BCM does not match physical pin 10 wiring -> Option AQuick Check:
BCM 10 controls physical 19 ≠ pin 10 [OK]
- Assuming physical pin numbers work with BCM mode
- Using string instead of int for pin number
- Thinking GPIO.setup can't use BCM numbering
Solution
Step 1: Identify physical pin 12's BCM number
Physical pin 12 corresponds to BCM GPIO 18 on Raspberry Pi.Step 2: Use BCM numbering mode and correct pin
Set mode to GPIO.BCM and use pin 18 in setup and output.Final Answer:
GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.HIGH) -> Option BQuick Check:
Physical pin 12 = BCM 18, use BCM mode [OK]
- Using physical pin number with BCM mode
- Using BCM pin number with BOARD mode
- Mixing pin numbers without conversion
Ready to prove it?
Pass the test and this pattern moves unknown
