Function: what a Raspberry Pi 4 Model B does in a circuit
A complete small computer on one board. It runs the Linux operating system, and your Python programs switch and read its 40 header pins.
- Runs your Python program on a full Linux computer
- Switches and reads 26 GPIO pins at 3.3 V
- Connects a project to a screen, a network and USB devices
- Handles jobs too big for a microcontroller, such as cameras and web servers
Raspberry Pi 4 Model B key facts
| Processor | Broadcom BCM2711, four ARM Cortex-A72 cores at 1.5 GHz (1.8 GHz on later boards) |
|---|---|
| Memory | 1, 2, 4 or 8 GB RAM; programs and files on a microSD card |
| GPIO voltage | 3.3 V (pins are not 5 V tolerant) |
| GPIO current | about 16 mA from one pin, about 50 mA from all pins together |
| Header | 40 pins: 26 GPIO, two 5 V, two 3.3 V, eight GND, two ID pins |
| Analog inputs | none (add an ADC chip such as the MCP3008) |
| Fixed pull-ups | 1.8 kΩ on GPIO 2 (SDA) and GPIO 3 (SCL) |
| Power | 5 V, 3 A through USB-C |
| Size | 85 mm × 56 mm |
- What the Raspberry Pi 4 Model B is
- What the Raspberry Pi 4 Model B is for
- How the Raspberry Pi 4 Model B runs your program and its pins
- How to use the Raspberry Pi 4 Model B in the simulator
- Worked example
- Common mistakes
- Key words
- What to learn first and next
What the Raspberry Pi 4 Model B is
The Raspberry Pi 4 Model B is a single-board computer: a complete computer built on one circuit board about the size of a bank card (85 mm × 56 mm). It has a processor with four cores, between 1 GB and 8 GB of memory, Wi-Fi, Bluetooth, an Ethernet socket, four USB sockets and two outputs for screens. It has no hard disk. Its operating system and all your files are kept on a small microSD card. You can plug in a screen, a keyboard and a mouse and use it like a desktop computer.
What makes it useful for electronics is the row of 40 metal pins along one edge, called the header. A program can switch 26 of these pins on and off, or read them, so the board can light LEDs, read buttons and sensors, and control motors through driver parts. This is different from a microcontroller board such as the Arduino Uno or the Raspberry Pi Pico. A microcontroller runs one program, starts in an instant and has no operating system. A Raspberry Pi computer runs many programs at once under an operating system, usually a version of Linux called Raspberry Pi OS, and is usually programmed in Python.
The Raspberry Pi 4 came out in 2019 and is the board that many school kits and lab activities are written for. Its header pins are run by the main processor, the BCM2711, and it is usually programmed with the RPi.GPIO library or with gpiozero. The newer Raspberry Pi 5 has the same header, but only gpiozero works on it.
What the Raspberry Pi 4 Model B is for
- Learning Python with real hardware. A few lines of Python make an LED blink or read a button, on a computer that can also show the result on a screen.
- Projects that need a full computer. A camera, a web server for a weather station, a media player or a home automation hub.
- Projects that need a network. Wi-Fi, Bluetooth and Ethernet are built in, so a reading can be saved to a file or sent to another computer.
- Laboratory work. Many course activities use the Pi 4 with an ultrasonic sensor, switches and LEDs.
- Not the best choice for a small battery-powered device or for reading analog sensors directly. A microcontroller such as the Raspberry Pi Pico does those jobs better.
How the Raspberry Pi 4 Model B runs your program and its pins
Starting up. When power is connected, the processor loads the operating system from the microSD card. This takes some seconds. After that you open a terminal, which is a window where you type commands, and start your program with python3 name.py. The program runs until it ends or until you press Ctrl+C. In the simulator, Run starts the program and Stop is Ctrl+C, so the lines after except KeyboardInterrupt: and finally: still run.
The header. The 40 pins are in two rows of 20. Every pin has a physical number from 1 to 40, counted by position: odd numbers are on the inner row and even numbers on the row at the edge. Twelve pins are for power: two give 5 V (pins 2 and 4), two give 3.3 V (pins 1 and 17) and eight are GND. Two pins (27 and 28) are kept for add-on boards. The other 26 are GPIO pins, and each of those also has a GPIO number. Physical pin 11, for example, is GPIO 17, and physical pin 16 is GPIO 23.
What a GPIO pin does. As an output, a pin is either HIGH (3.3 V) or LOW (0 V). As an input, a voltage near 0 V reads LOW and a voltage near 3.3 V reads HIGH. One pin can safely give about 16 mA, and all the pins together about 50 mA. The pins are not 5 V tolerant: 5 V on a GPIO pin damages the board. There is no analog input, so a sensor that gives a changing voltage is read through a converter chip such as the MCP3008.
Two ways to number pins in RPi.GPIO. The RPi.GPIO library makes you choose first. GPIO.setmode(GPIO.BOARD) means the numbers in your program are physical pin numbers. GPIO.setmode(GPIO.BCM) means they are GPIO numbers. Then GPIO.setup(11, GPIO.OUT) makes a pin an output and GPIO.output(11, GPIO.HIGH) switches it on. For an input, GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) switches on a pull-up resistor inside the board, and GPIO.input(15) reads the pin. GPIO.cleanup() at the end gives the pins back.
The gpiozero library. gpiozero is a second library that hides the setup. It always counts by GPIO number. led = LED(17) then led.on() does the same job as the three RPi.GPIO lines above, and Button(22) switches on the pull-up for you. Both libraries work on this board. Only gpiozero works on the newer Raspberry Pi 5.
How to use the Raspberry Pi 4 Model B in the simulator
- Open the Free build and choose Raspberry Pi 4 Model B (Python) under Board, or open the Studio and add the board from Components › Boards.
- Read the starter program in the Code panel. It blinks physical pin 11 with
RPi.GPIOin BOARD numbering. - Wire the circuit: physical pin 11 (GPIO 17) to a 330 Ω resistor, the resistor to the long leg of an LED, and the short leg to a GND pin such as pin 6. Point at a header pin to see its physical number and its GPIO number.
- Press Run. The LED blinks and the terminal panel shows what the program prints.
- Press Stop. It acts like Ctrl+C in a real terminal, and
GPIO.cleanup()runs. - Then open a guided project below, such as “Blink an LED in Python”, and press Check when your program works.
Worked example
Question. A red LED with a forward voltage of about 2.0 V is wired to physical pin 11 of a Raspberry Pi 4 Model B through a 330 Ω resistor. How much current does the pin give, and is that safe? What is the line of code that sets up the pin?
- A pin that is HIGH gives 3.3 V.
- The LED takes about 2.0 V, so the resistor gets 3.3 V − 2.0 V = 1.3 V.
- Current = voltage ÷ resistance = 1.3 V ÷ 330 Ω = 0.0039 A, which is 3.9 mA.
- Physical pin 11 is GPIO 17. With GPIO.setmode(GPIO.BOARD) the program uses the number 11.
- The line is
GPIO.setup(11, GPIO.OUT).
Answer. The pin gives about 3.9 mA, which is safe. The pin is set up with GPIO.setup(11, GPIO.OUT).
Common mistakes
- Leaving out GPIO.setmode().RPi.GPIO stops with “Please set pin numbering mode”. Write GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) before the first GPIO.setup().
- Mixing up physical pin numbers and GPIO numbers.Physical pin 11 is GPIO 17. In BOARD mode write 11; in BCM mode and in gpiozero write 17.
- Connecting a 5 V signal to a GPIO pin.The pins are 3.3 V only. A 5 V output, such as the Echo pin of an HC-SR04, needs a voltage divider: 1 kΩ and 2 kΩ turn 5 V into about 3.3 V.
- Wiring an LED with no resistor.The pin would try to give far more than 16 mA. Always put a resistor of about 330 Ω in series.
- Reading a button with no pull-up.The pin floats and reads random values. Add pull_up_down=GPIO.PUD_UP and wire the button to GND, or use a gpiozero Button.
- Writing time.sleep(500) for half a second.Python counts in seconds, not milliseconds. Half a second is time.sleep(0.5).
- Using the same program on a Raspberry Pi 5.RPi.GPIO does not work on the Pi 5. Write the program with gpiozero if it must run on both.
Key words
- Single-board computer
- A complete computer, with processor, memory and sockets, built on one circuit board.
- Operating system
- The main program of a computer, which starts other programs and shares the processor, memory and devices between them. Linux and Windows are examples.
- GPIO
- General-purpose input and output: a pin that a program can set HIGH or LOW, or read.
- Header (on a circuit board)
- A row of metal pins on a board for connecting wires or add-on boards.
- Physical pin number
- The position of a pin on the 40-pin header of a Raspberry Pi, counted from 1 to 40.
- GPIO number
- The number the Raspberry Pi gives to a GPIO pin, also called its BCM number. It is not the same as the position of the pin.
- Library (in programming)
- Code written by someone else that a program can import and use, such as gpiozero.
- gpiozero
- A Python library for the pins of a Raspberry Pi, with ready-made objects such as LED and Button.
- Pull-up resistor
- A resistor that joins an input pin to the supply voltage, so the pin reads HIGH when nothing else drives it.
- LED
- A light-emitting diode: a component that gives out light when current flows through it in one direction.
- Resistor
- A component made to have a fixed resistance.
- Forward voltage
- The voltage across an LED or diode when it is conducting.
- Voltage divider
- Two resistors in series that share a voltage, with the output taken from where they join. Also called a potential divider.
- Ground
- The point in a circuit taken as zero volts, from which other voltages are measured.
See every key word in the glossary
What to learn first and next
- Ohm’s law calculator: Voltage, current and resistance, which the worked example uses.
- LED resistor calculator: Work out the resistor that an LED needs on a 3.3 V pin.
- LED: The first part to connect to a pin.
- Blink an LED in Python: The first guided project for this board.
- Button and LED in Python: Read an input with a pull-up.
- MCP3008 analog-to-digital converter: Read a knob or an analog sensor.
- Raspberry Pi 5: The newer board, with gpiozero.
- Raspberry Pi course: Every Raspberry Pi lesson in teaching order.
How it works
A four-core 1.5 GHz ARM processor (the BCM2711) runs an operating system from a microSD card, so a program starts from a terminal with python3 name.py instead of being uploaded to a chip. 26 of the 40 header pins are GPIO pins (general-purpose input and output). They work at 3.3 V and give about 16 mA each. Every pin has two numbers: its physical position on the header, 1 to 40 (GPIO.BOARD), and its GPIO number on the processor (GPIO.BCM). Physical pin 16, for example, is GPIO 23. There is no analog input, so a sensor that gives a voltage needs a converter chip such as the MCP3008. In this simulator the board is programmed in Python with the RPi.GPIO library, the same as on a real one.
What it is made of
- Processor and memory: Silicon chips: the BCM2711 under a metal lid and a separate memory chip SiCuAl
- Circuit board: Six layers of glass-fibre and epoxy with copper tracks CuSiO
- Header and ports: Gold-plated brass pins, steel port shells CuZnAuFe
- Solder: Lead-free tin alloy SnAgCu
Where the materials come from: Silicon purified from quartz sand; copper from ores in Chile and Peru; tin from Indonesia and China; gold for the pin plating from many mining countries. The boards are assembled in Wales.
The chemistry
The processor holds billions of transistors made by adding tiny amounts of boron and phosphorus to pure silicon. Each transistor is a switch only a few nanometres across, and working at 3.3 V instead of 5 V keeps them from overheating.
Biology connection
The Pi does many jobs at once, sharing its processor between programs. Your nervous system also runs many jobs side by side, with signals travelling along separate nerve fibres at the same time. Nerve impulses →
Safety and the environment
Never connect 5 V to a GPIO pin: the pins are 3.3 V only and a higher voltage damages the processor for good. A 5 V sensor output such as the HC-SR04 Echo pin needs a voltage divider. Wire the circuit with the power off, and shut the Pi down before unplugging it so the microSD card is not corrupted. Recycle as e-waste.
Did you know? The first Raspberry Pi went on sale in 2012 to help students learn programming. More than 60 million boards have been sold since.
Raspberry Pi 5Raspberry Pi Zero 2 WRaspberry Pi PicoMCP3008 analog-to-digital converterFloat switchMicrocontroller simulatorOhm’s law calculator Elements inside: SiCuAlOZnAuFeSnAg
Try it in the simulator
Build and code a circuit with a Raspberry Pi 4 Model B in these practice projects:
Questions students ask
What does a Raspberry Pi 4 Model B do?
A complete small computer on one board. It runs the Linux operating system, and your Python programs switch and read its 40 header pins. Main functions: runs your Python program on a full Linux computer; switches and reads 26 GPIO pins at 3.3 V; connects a project to a screen, a network and USB devices; handles jobs too big for a microcontroller, such as cameras and web servers.
What is the difference between BOARD and BCM pin numbers on a Raspberry Pi?
On a Raspberry Pi, GPIO.setmode(GPIO.BOARD) uses the physical position of each pin on the 40-pin header, counted 1 to 40, while GPIO.setmode(GPIO.BCM) uses the GPIO number of the processor. They name the same pins in two ways: physical pin 16 is GPIO 23, and physical pin 18 is GPIO 24.
How does a Raspberry Pi 4 Model B work?
A four-core 1.5 GHz ARM processor (the BCM2711) runs an operating system from a microSD card, so a program starts from a terminal with python3 name.py instead of being uploaded to a chip. 26 of the 40 header pins are GPIO pins (general-purpose input and output). They work at 3.3 V and give about 16 mA each. Every pin has two numbers: its physical position on the header, 1 to 40 (GPIO.BOARD), and its GPIO number on the processor (GPIO.BCM). Physical pin 16, for example, is GPIO 23. There is no analog input, so a sensor that gives a voltage needs a converter chip such as the MCP3008. In this simulator the board is programmed in Python with the RPi.GPIO library, the same as on a real one.
What is a Raspberry Pi 4 Model B made of?
Processor and memory: Silicon chips: the BCM2711 under a metal lid and a separate memory chip. Circuit board: Six layers of glass-fibre and epoxy with copper tracks. Header and ports: Gold-plated brass pins, steel port shells. Solder: Lead-free tin alloy.
Is a Raspberry Pi 4 Model B safe? How should it be recycled?
Never connect 5 V to a GPIO pin: the pins are 3.3 V only and a higher voltage damages the processor for good. A 5 V sensor output such as the HC-SR04 Echo pin needs a voltage divider. Wire the circuit with the power off, and shut the Pi down before unplugging it so the microSD card is not corrupted. Recycle as e-waste.
More boards and wiring
Connected tools
The same idea from another angle, across the site.