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)
| Feature | MCU (e.g. ESP32) | SBC (e.g. Raspberry Pi 4) |
|---|---|---|
| Operating System | None / RTOS | Full Linux |
| Boot Time | Milliseconds | 15–30 seconds |
| Idle Power | 10 µA – 20 mA | 300 mA – 600 mA |
| RAM | Kilobytes | Gigabytes |
| Storage | Flash (MB) | SD Card / eMMC (GB) |
| GPIO Pins | Yes | Yes (but 3.3 V only) |
| ADC | Yes (built-in) | No (needs external chip) |
| Analog Output | PWM only | PWM only |
| Real-time | Yes | Not 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.
# 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
| Feature | Value |
|---|---|
| CPU | Xtensa LX6 dual-core, 240 MHz |
| RAM | 520 KB SRAM |
| Flash | 4–16 MB |
| WiFi | 802.11 b/g/n (2.4 GHz) |
| Bluetooth | BT 4.2 + BLE |
| GPIO | 34 pins |
| ADC | 12-bit, 18 channels |
| DAC | 2 × 8-bit |
| Hardware | SPI, 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 supportThe Arduino — Learning and Simplicity
Arduino is where most beginners start. It has the largest library ecosystem and community.
// 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
| Board | MCU | Clock | Flash | RAM | Voltage | Best For |
|---|---|---|---|---|---|---|
| Uno R3 | ATmega328P | 16 MHz | 32 KB | 2 KB | 5 V | Learning, servo control |
| Nano | ATmega328P | 16 MHz | 32 KB | 2 KB | 5 V | Compact projects |
| Mega 2560 | ATmega2560 | 16 MHz | 256 KB | 8 KB | 5 V | Many sensors, I/O heavy |
| Nano 33 IoT | SAMD21 + u-blox | 48 MHz | 256 KB | 32 KB | 3.3 V | WiFi + BLE, maker IoT |
| MKR WiFi 1010 | SAMD21 + u-blox | 48 MHz | 256 KB | 32 KB | 3.3 V | WiFi, 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 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)
| Model | CPU | RAM | USB | Storage | Price |
|---|---|---|---|---|---|
| Pi Zero 2 W | Cortex-A53 quad 1GHz | 512 MB | 1× micro | microSD | $15 |
| Pi 3B+ | Cortex-A53 quad 1.4GHz | 1 GB | 4× USB 2 | microSD | $35 |
| Pi 4B | Cortex-A72 quad 1.8GHz | 1/2/4/8 GB | 2× USB 3 | microSD | $35–$75 |
| Pi 5 | Cortex-A76 quad 2.4GHz | 4/8 GB | 2× USB 3 | microSD/NVMe | $60–$80 |
| Pi Pico W | RP2040 (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
# 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.