Hardware Fundamentals

Microcontrollers and Single-Board Computers

Compare Arduino, ESP32, and Raspberry Pi — understand their specs, strengths, and when to use each platform in your IoT projects.

Microcontrollers and Single-Board Computers

Choosing the right hardware platform is the most important decision in any IoT project. The wrong choice costs you time, money, and headaches. This topic gives you a clear framework for making that decision.


Microcontrollers (MCUs) vs Single-Board Computers (SBCs)

FeatureMCU (e.g. ESP32)SBC (e.g. Raspberry Pi 4)
Operating SystemNone / RTOSFull Linux
Boot TimeMilliseconds15–30 seconds
Idle Power10 µA – 20 mA300 mA – 600 mA
RAMKilobytesGigabytes
StorageFlash (MB)SD Card / eMMC (GB)
GPIO PinsYesYes (but 3.3 V only)
ADCYes (built-in)No (needs external chip)
Analog OutputPWM onlyPWM only
Real-timeYesNot guaranteed
Cost$2 – $15$10 – $75

The ESP32 — IoT Workhorse

The ESP32 by Espressif is the most popular microcontroller for WiFi/BLE IoT projects. It is powerful enough for complex tasks yet cheap and low-power.

python
# MicroPython on ESP32 — system information
import machine
import esp32
import gc

print(f"CPU Frequency: {machine.freq() / 1_000_000} MHz")  # 240 MHz
print(f"Free RAM: {gc.mem_free()} bytes")
print(f"Hall Sensor: {esp32.hall_sensor()} µT")
print(f"Internal Temp: {esp32.raw_temperature()} (raw)")

# Unique chip ID (useful for device identification)
import ubinascii
uid = ubinascii.hexlify(machine.unique_id()).decode()
print(f"Device ID: {uid}")

ESP32 Key Specs

FeatureValue
CPUXtensa LX6 dual-core, 240 MHz
RAM520 KB SRAM
Flash4–16 MB
WiFi802.11 b/g/n (2.4 GHz)
BluetoothBT 4.2 + BLE
GPIO34 pins
ADC12-bit, 18 channels
DAC2 × 8-bit
HardwareSPI, I2C, I2S, UART, PWM, Touch
Deep Sleep~10 µA

ESP32 Variants

ESP32 Family
├── ESP32        — Original, dual-core, most libraries
├── ESP32-S2     — Single-core, no BT, more USB features
├── ESP32-S3     — Dual-core, AI accelerator, camera support
├── ESP32-C3     — Single-core RISC-V, very low cost
└── ESP32-C6     — WiFi 6, Zigbee, Thread support

The Arduino — Learning and Simplicity

Arduino is where most beginners start. It has the largest library ecosystem and community.

cpp
// Arduino Uno — Blink with timing measurement
const int LED_PIN = 13;  // Built-in LED
unsigned long previousMillis = 0;
const long INTERVAL = 1000;  // 1 second

void setup() {
    Serial.begin(9600);
    pinMode(LED_PIN, OUTPUT);
    Serial.println("Arduino Uno ready");
}

void loop() {
    unsigned long currentMillis = millis();

    if (currentMillis - previousMillis >= INTERVAL) {
        previousMillis = currentMillis;

        // Toggle LED without using delay()
        int state = digitalRead(LED_PIN);
        digitalWrite(LED_PIN, !state);

        Serial.print("LED: ");
        Serial.println(state ? "OFF" : "ON");
    }
}

Note: Avoid delay() in real IoT projects. It blocks the CPU and prevents other tasks from running. Use millis() for non-blocking timing instead.

Arduino Boards Comparison

BoardMCUClockFlashRAMVoltageBest For
Uno R3ATmega328P16 MHz32 KB2 KB5 VLearning, servo control
NanoATmega328P16 MHz32 KB2 KB5 VCompact projects
Mega 2560ATmega256016 MHz256 KB8 KB5 VMany sensors, I/O heavy
Nano 33 IoTSAMD21 + u-blox48 MHz256 KB32 KB3.3 VWiFi + BLE, maker IoT
MKR WiFi 1010SAMD21 + u-blox48 MHz256 KB32 KB3.3 VWiFi, cloud-ready

Raspberry Pi — The IoT Gateway

Raspberry Pi runs full Linux, making it ideal for data aggregation, computer vision, and as an edge gateway that connects sensor nodes to the cloud.

python
# Python 3 on Raspberry Pi — system info
import subprocess
import os

def get_pi_info():
    # CPU temperature
    temp = subprocess.check_output(['vcgencmd', 'measure_temp']).decode()

    # Free memory
    mem = os.popen('free -m').read().split('\n')[1].split()

    # CPU usage
    cpu = subprocess.check_output(['top', '-bn1']).decode()
    cpu_line = [l for l in cpu.split('\n') if 'Cpu(s)' in l][0]

    return {
        'temperature': temp.strip(),
        'total_mem_mb': mem[1],
        'free_mem_mb': mem[3],
    }

info = get_pi_info()
print(info)
# {'temperature': 'temp=45.1\'C', 'total_mem_mb': '3792', 'free_mem_mb': '2891'}

Raspberry Pi Models (2024)

ModelCPURAMUSBStoragePrice
Pi Zero 2 WCortex-A53 quad 1GHz512 MB1× micromicroSD$15
Pi 3B+Cortex-A53 quad 1.4GHz1 GB4× USB 2microSD$35
Pi 4BCortex-A72 quad 1.8GHz1/2/4/8 GB2× USB 3microSD$35–$75
Pi 5Cortex-A76 quad 2.4GHz4/8 GB2× USB 3microSD/NVMe$60–$80
Pi Pico WRP2040 (MCU!)264 KB—2 MB Flash$6

GPIO Pin Comparison

ESP32 DevKit (38-pin)          Raspberry Pi 4 (40-pin)
┌─────────────────┐            ┌─────────────────┐
│ 3V3  GND        │            │ 3V3  5V         │
│ EN   GPIO 36    │            │ GPIO2 5V        │
│ GPIO 34-39 (IN) │            │ GPIO3 GND       │
│ GPIO 32-33      │            │ GPIO4 GPIO14    │
│ GPIO 25-27      │            │ ...             │
│ GPIO 14-15      │            │ GPIO17-27 ...   │
│ GPIO 12-13      │            │ ADC: NONE       │
│ ADC: 18 channels│            └─────────────────┘
└─────────────────┘

Key difference: Raspberry Pi has NO built-in ADC.
To read analog sensors on Pi, add MCP3008 (SPI) or ADS1115 (I2C).

Decision Guide

python
# Answer these questions to choose your platform

questions = {
    "need_wifi_or_ble": True,
    "need_full_os": False,
    "battery_powered": True,
    "need_camera": False,
    "need_machine_learning": False,
    "beginner": False,
}

def recommend_platform(q):
    if q["need_full_os"] or q["need_camera"] or q["need_machine_learning"]:
        if q["need_machine_learning"]:
            return "NVIDIA Jetson Nano (for AI) or Raspberry Pi 4"
        return "Raspberry Pi 4"

    if q["battery_powered"] and q["need_wifi_or_ble"]:
        return "ESP32 (with deep sleep for long battery life)"

    if q["need_wifi_or_ble"]:
        return "ESP32 (mains powered)"

    if q["beginner"]:
        return "Arduino Uno (no WiFi needed) or ESP32"

    return "Arduino Nano / Uno"

print(recommend_platform(questions))  # ESP32 (with deep sleep)

Summary

  • MCUs (ESP32, Arduino) are low-power, real-time, and cheap — ideal for sensor nodes
  • SBCs (Raspberry Pi) run Linux and are ideal for gateways, cameras, and complex processing
  • ESP32 is the best all-rounder: dual-core, WiFi, BLE, deep sleep, MicroPython support
  • Arduino Uno is the best starting point for absolute beginners and hardware experimentation
  • Raspberry Pi 4/5 is your platform when you need a full OS, camera, or edge AI
  • Raspberry Pi has no built-in ADC — use an external chip (ADS1115) for analog sensors

Next, we'll explore the sensors and actuators that give IoT devices their ability to perceive and interact with the physical world.