The Raspberry Pi is a credit-card-sized single-board computer (SBC) built around an ARM-based system-on-chip (SoC). It runs a full Linux operating system, exposes GPIO pins for hardware control, and costs a fraction of a desktop PC. That mix makes it the default bridge between software and electronics. It also has hard limits: no built-in analog inputs, no real-time guarantees, and a storage medium that wears out. This guide covers the architecture, pinout, working code, honest limitations, and the situations where you should pick a microcontroller instead.
Quick Takeaways
- What it is: A full Linux computer on one board with 40-pin GPIO, USB, HDMI, Ethernet, and Wi-Fi.
- Best at: Network services, vision, media, home automation hubs, and prototyping with Python.
- Weak at: Hard real-time control, analog sensing, ultra-low-power battery designs, and heavy desktop workloads.
- Rule of thumb: If your project needs an operating system, a network stack, or a camera, use a Pi. If it needs microsecond timing or a coin cell, use a microcontroller.
| Feature | Raspberry Pi (SBC) | Arduino / Pico (MCU) |
|---|---|---|
| Processor | Multi-core ARM Cortex-A | Single/dual-core Cortex-M or AVR |
| Clock speed | 1.5-2.4GHz class | 16-133MHz class |
| Operating system | Linux (Raspberry Pi OS) | None / RTOS / bare metal |
| RAM | 1GB-16GB (model dependent) | 2KB-264KB |
| Idle power | ~1-3W | ~10-100mW |
| Real-time timing | Poor (OS jitter) | Excellent |
| ADC (analog in) | None built in | Built in |
What Is a Raspberry Pi?
The Raspberry Pi Foundation designed the board to teach computing cheaply. The hardware escaped the classroom. Engineers now use it as a gateway, a test bench controller, a kiosk, and an edge AI node.
A Pi has three layers:
- SoC (Broadcom): CPU cores, GPU, memory controller, and peripheral blocks on one die.
- Board I/O: USB, HDMI/micro-HDMI, Gigabit Ethernet, CSI camera and DSI display connectors, and the GPIO header.
- Software stack: Raspberry Pi OS (Debian-based) plus the full Linux driver ecosystem.
Storage is a microSD card (or NVMe/USB SSD on supported models). The board boots from it directly. There is no onboard flash for the OS on most models, which matters for reliability, covered below.
Raspberry Pi Model Families
| Model | Typical Use | Key Trait | Relative Cost |
|---|---|---|---|
| Pi 5 | Desktop, AI, servers | Fastest CPU, PCIe, RTC support | Highest |
| Pi 4 Model B | General purpose | Balanced, wide software support | Mid |
| Pi Zero 2 W | Compact, low-power builds | Quad-core, small, Wi-Fi/BT | Low |
| Pi Pico / Pico 2 | Embedded control | Actually an MCU (RP2040/RP2350) | Lowest |
| Pi 400/500 | Keyboard-integrated PC | All-in-one desktop | Mid |
Check current availability and pricing on the official Raspberry Pi site before buying, since stock and prices shift.
Important distinction: The Pico line is a microcontroller, not a Linux computer. Many beginners confuse the two. The rest of this guide focuses on the Linux-based boards.
Pinout Configuration: The 40-Pin GPIO Header
The GPIO header is where the Pi becomes an electronics platform. All logic runs at 3.3V. The pins are not 5V tolerant. Feeding 5V into a GPIO pin can destroy the SoC.
| Pin Group | Pins | Notes |
|---|---|---|
| 3.3V power | 1, 17 | Max combined draw roughly 50mA guideline |
| 5V power | 2, 4 | Passes through from the USB supply |
| GND | 6, 9, 14, 20, 25, 30, 34, 39 | Common ground |
| I2C1 | GPIO2 (SDA), GPIO3 (SCL) | Onboard 1.8kΩ pull-ups |
| SPI0 | GPIO10 (MOSI), GPIO9 (MISO), GPIO11 (SCLK), GPIO8 (CE0) | Up to tens of MHz |
| UART0 | GPIO14 (TXD), GPIO15 (RXD) | Serial console / modules |
| PWM | GPIO12, GPIO13, GPIO18, GPIO19 | Hardware PWM channels |
Electrical Limits to Respect
- Per-pin current: Keep it under about 16mA. Treat 8mA as the safe default.
- Total GPIO current: Stay within roughly 50mA across all pins.
- Logic level: Use a level shifter (for example a BSS138-based module) for any 5V device.
- Inductive loads: Never drive a relay coil or motor directly. Use a transistor or MOSFET plus a flyback diode.
Circuit Diagram Breakdown: Driving an LED Safely
A GPIO pin outputs 3.3V. A red LED has a forward voltage near 2.0V and wants about 10mA. Solve for the series resistor:
R = (3.3V – 2.0V) / 0.010A = 130Ω
Use a 220Ω resistor as the nearest safe standard value. That yields about 6mA, bright enough and well within limits.
Wiring: GPIO17 (pin 11) → 220Ω resistor → LED anode → LED cathode → GND (pin 9).
Firmware and Code: Python on GPIO
Raspberry Pi OS ships with gpiozero, a clean wrapper over the lower-level libraries. This example blinks an LED and reads a button.
# blink_and_button.py
# Hardware: LED + 220-ohm resistor on GPIO17, momentary button on GPIO27 to GND
from gpiozero import LED, Button
from signal import pause
led = LED(17) # Output pin, drives the LED through the 220-ohm resistor
button = Button(27) # Input pin; gpiozero enables the internal pull-up by default
# Toggle the LED each time the button is pressed (falling edge, active low)
button.when_pressed = led.toggle
# Run a background blink pattern: 0.5s on, 0.5s off
# Comment this line out if you only want button control
# led.blink(on_time=0.5, off_time=0.5)
pause() # Keep the script alive and wait for events
Run it with:
python3 blink_and_button.py
Reading an I2C Sensor
This example reads a BME280 temperature, humidity, and pressure sensor on I2C address 0x76. Enable I2C first with sudo raspi-config under Interface Options.
# Install the library inside a virtual environment
python3 -m venv ~/env && source ~/env/bin/activate
pip install adafruit-circuitpython-bme280 adafruit-blinka
# bme280_read.py
import time
import board # Maps Pi pins to named buses
import adafruit_bme280.basic as adafruit_bme280
i2c = board.I2C() # Uses GPIO2 (SDA) and GPIO3 (SCL)
sensor = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
while True:
# Values are returned as floats in degrees C, percent RH, and hPa
print(f"Temp: {sensor.temperature:.1f} C | "
f"Humidity: {sensor.relative_humidity:.1f} % | "
f"Pressure: {sensor.pressure:.1f} hPa")
time.sleep(2) # Sample every 2 seconds
Verify the sensor is detected before running the script:
i2cdetect -y 1 # Expect "76" in the grid
What a Raspberry Pi Can Do
1. Run a Full Linux Server
The Pi handles lightweight server workloads well. Typical roles:
- Network-wide ad blocking with Pi-hole
- Home automation hub running Home Assistant
- VPN endpoint with WireGuard
- Media server and network storage
- Git, MQTT, or InfluxDB instances for IoT data
2. Process Camera and Vision Data
The CSI connector accepts official camera modules. Combined with OpenCV or on-device inference, the Pi runs motion detection, object counting, and time-lapse capture. Newer models and the optional AI accelerator add-ons improve inference speed.
3. Act as an IoT Gateway
Sensor nodes (often ESP32 boards) publish over MQTT to a Pi. The Pi stores, visualizes, and forwards data. This split keeps battery nodes cheap and the gateway powerful.
4. Control Hardware Through GPIO
The Pi drives LEDs, relays, displays, stepper drivers, and sensors over I2C, SPI, UART, and PWM. Python makes the iteration cycle fast.
5. Serve as a Compact Desktop
Newer boards browse the web, edit documents, and play 1080p video. Treat it as a light desktop, not a workstation.
What a Raspberry Pi Can’t Do (Or Does Poorly)
| Limitation | Why It Happens | Better Alternative |
|---|---|---|
| No analog inputs | No onboard ADC | Add an ADS1115 (I2C) or MCP3008 (SPI) |
| No hard real-time | Linux scheduler adds jitter (often tens to hundreds of µs) | Pico, STM32, Arduino |
| Weak battery life | Idle draw in watts, slow boot | ESP32 deep sleep (~10µA) |
| SD card wear | Repeated writes degrade flash | SSD boot, read-only root, or log to RAM |
| No safe 5V I/O | 3.3V-only pins | Level shifter |
| Thermal throttling | High-clock SoC in small board | Heatsink, fan, or case airflow |
| Heavy compute | Limited cores and memory | x86 mini PC or GPU workstation |
| Sudden power loss | Filesystem corruption risk | Proper shutdown, UPS HAT, journaling |
The Real-Time Problem
Bit-banging a precise waveform from Python on Linux fails. The kernel can preempt your process at any moment. For WS2812 LED strips, servo jitter, or fast quadrature encoders, offload timing to hardware: use hardware PWM, DMA-driven libraries, or a companion microcontroller over UART or I2C.
The SD Card Reliability Problem
Cheap microSD cards fail under constant writes. Reduce risk with these steps:
- Use a quality card rated A1/A2 from a reputable brand.
- Boot from a USB or NVMe SSD where supported.
- Move logs to RAM with
log2ram. - Always run
sudo shutdown -h nowbefore removing power.
Raspberry Pi vs. Alternatives
| Board | Type | Best For | Power Draw | Learning Curve |
|---|---|---|---|---|
| Raspberry Pi 4/5 | SBC (Linux) | Servers, vision, gateways | Medium-High | Moderate |
| Raspberry Pi Pico | MCU | Timing-critical control | Very low | Easy |
| Arduino Uno | MCU (AVR) | Beginner circuits, shields | Low | Easiest |
| ESP32 | MCU + Wi-Fi/BT | Battery IoT nodes | Low (deep sleep) | Moderate |
| Jetson Nano class | SBC + GPU | Edge AI inference | High | Steep |
Decision shortcut: Need Linux, a network stack, or a camera? Choose a Pi. Need deterministic timing or months on a battery? Choose an MCU.
Real-World Project: Pi-Based IoT Weather Station
This build combines everything above: sensing, networking, and data display.
Parts List
- Raspberry Pi 4 or Zero 2 W
- BME280 sensor (I2C)
- microSD card (A1 rated) and a 5V/3A supply
- Four jumper wires
Wiring
| BME280 Pin | Raspberry Pi Pin |
|---|---|
| VIN | 3.3V (pin 1) |
| GND | GND (pin 6) |
| SDA | GPIO2 (pin 3) |
| SCL | GPIO3 (pin 5) |
Publish Readings Over MQTT
# weather_mqtt.py
import time, json
import board
import adafruit_bme280.basic as adafruit_bme280
import paho.mqtt.client as mqtt
i2c = board.I2C()
sensor = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
client = mqtt.Client() # Use mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) on paho 2.x
client.connect("localhost", 1883, 60) # Broker running on the same Pi (Mosquitto)
client.loop_start()
while True:
payload = json.dumps({
"temp_c": round(sensor.temperature, 1),
"humidity": round(sensor.relative_humidity, 1),
"pressure_hpa": round(sensor.pressure, 1),
})
client.publish("home/weather", payload) # Topic subscribers can graph this data
time.sleep(30) # One reading every 30 seconds
Install and enable the broker:
sudo apt install mosquitto mosquitto-clients
sudo systemctl enable --now mosquitto
mosquitto_sub -t home/weather # Watch live readings
From here, point Grafana or Home Assistant at the MQTT topic to chart temperature trends.
Protecting the Pi from Voltage Spikes
When switching a relay or motor from the Pi, isolate the load:
- Use an optocoupler (for example PC817) between the GPIO and the driver stage.
- Add a flyback diode (1N4007) across every relay coil.
- Place a 100nF decoupling capacitor near sensors to suppress noise.
- Power inductive loads from a separate supply with a shared ground.
Troubleshooting Quick Diagnostics
| Symptom | Likely Cause | Fix |
|---|---|---|
| Lightning bolt icon | Supply below 4.63V | Use a 5V/3A official-grade supply |
| No boot, green LED blinks | Bad SD image or corrupt card | Reflash with Raspberry Pi Imager |
i2cdetect shows nothing |
I2C disabled or miswired | Enable in raspi-config; check SDA/SCL |
| GPIO reads float randomly | No pull resistor | Enable internal pull-up or add 10kΩ |
| Random freezes | Overheating or weak power | Add heatsink; check voltage |
Frequently Asked Questions
Is a Raspberry Pi a computer or a microcontroller?
A Raspberry Pi (Model 3, 4, 5, Zero) is a full computer running Linux on an ARM processor. The Raspberry Pi Pico is the exception: it is a microcontroller with no operating system.
Can a Raspberry Pi replace a desktop PC?
For web browsing, office work, and media playback, yes. For video editing, gaming, or compiling large codebases, no. The CPU, memory, and storage speed fall short of a standard desktop.
Can a Raspberry Pi read analog sensors?
Not directly. The board has no ADC. Add an external converter such as the ADS1115 over I2C or the MCP3008 over SPI to read analog voltages.
Is a Raspberry Pi good for beginners?
Yes. Python, a huge tutorial library, and a visual desktop make it approachable. Beginners who only want to blink LEDs or read sensors can also start with an Arduino or Pico, which cost less and tolerate wiring mistakes better.




