What a Microcontroller Is and How to Choose a Board
Understand the computer inside every device: CPU, flash, SRAM and EEPROM on one chip, peripherals such as GPIO, ADC, timers, UART, I2C and SPI, how a microcontroller differs from a microprocessor or a single-board computer, clock speed and cycles, and how to choose between boards such as the Arduino Uno, ESP32 and Raspberry Pi Pico.
1. A computer on one chip
A microcontroller (MCU) is a small computer on a single chip. Inside the package are:
| Block | What it does |
|---|---|
| CPU core | Executes your program one instruction at a time |
| Flash memory | Stores the program. It keeps its contents with no power, and can only be rewritten a limited number of times (about 10,000 writes on an ATmega328P) |
| SRAM | Working memory for variables and the stack. Fast, but erased when power is removed |
| EEPROM (on some chips) | A small non-volatile store for settings, with a higher write endurance (about 100,000 writes on the ATmega328P) |
| Peripherals | Hardware blocks that work alongside the CPU: general-purpose I/O pins (GPIO), analogue-to-digital converters (ADC), timers and PWM, serial ports (UART, I2C, SPI), interrupt controller, watchdog |
| Clock | An oscillator that sets the speed, for example 16 MHz |
A microprocessor (such as the chip in a laptop) is mostly just the CPU: it needs external RAM, storage and I/O chips, and usually runs an operating system. A single-board computer (such as a Raspberry Pi) is a microprocessor board that runs Linux. A microcontroller runs one dedicated program, starts instantly, uses milliwatts, and talks directly to the real world through its pins. That makes it the natural brain of a sensor node, a controller, a toy or an appliance.
2. Boards you will meet
| Chip and board | Architecture and clock | Memory | Logic level | Notes |
|---|---|---|---|---|
| ATmega328P (Arduino Uno R3) | 8-bit AVR, 16 MHz | 32 KB flash, 2 KB SRAM, 1 KB EEPROM | 5 V | The classic teaching board; 14 digital pins, 6 analogue inputs |
| ESP32 (many dev boards) | 32-bit Xtensa, up to 240 MHz, dual core | 520 KB SRAM, flash on a separate chip (4 MB is common) | 3.3 V | Built-in Wi-Fi and Bluetooth, 12-bit ADC, touch pins |
| RP2040 (Raspberry Pi Pico) | Dual Cortex-M0+, 133 MHz | 264 KB SRAM, 2 MB flash on the Pico board | 3.3 V | Low cost, programmable I/O blocks, MicroPython or C/C++ |
| STM32 family | ARM Cortex-M, from tens to hundreds of MHz | From a few KB to several MB | Usually 3.3 V | Very wide range, used in industry |
Exact numbers vary by board variant, so confirm them in the datasheet. Always check the logic level: connecting a 5 V output to a 3.3 V-only pin can damage it (see the digital logic lesson of the electronics course).
3. Clock speed and cycles
The clock sets how fast the CPU steps through instructions. One cycle lasts 1 / frequency:
cycle time = 1 / f_clock
16 MHz → 62.5 ns 133 MHz → 7.5 ns 240 MHz → 4.2 ns
On an AVR, most instructions take one or two cycles. At 16 MHz that is about 8 to 16 million simple instructions per second. A 32-bit multiply or a floating-point operation takes far longer on an 8-bit chip with no floating-point hardware, so do arithmetic with integers where you can.
Faster is not always better. A higher clock uses more power, and many jobs (reading a button, blinking an LED) are limited by the real world, not by the CPU.
4. Memory budget
You will run out of SRAM before flash on small chips. A 2 KB SRAM has to hold all your variables, buffers, the call stack and library data. Build the habit of checking memory:
- The Arduino IDE prints, after compiling, how much flash and SRAM the sketch uses (for example “Sketch uses 4,500 bytes (13 percent) of program storage space. Global variables use 1,100 bytes (53 percent) of dynamic memory, leaving 948 bytes for local variables”).
- Keep a margin: do not plan to use more than about 70 to 80 percent of SRAM for globals, because the stack grows into the remaining space at run time.
- Store constant text in flash (
F("text")on AVR) rather than SRAM.
5. Choosing a board
Choose from the requirements, not from the name:
- I/O needed: how many digital pins, analogue inputs, PWM outputs, serial buses.
- Memory: flash for the program and libraries, SRAM for buffers (a display or Wi-Fi library needs far more than a blinking LED).
- Speed: usually modest; check only for audio, motor control or fast signals.
- Connectivity: Wi-Fi, Bluetooth, USB, CAN, Ethernet.
- Voltage and power: 5 V or 3.3 V logic, sleep current if battery powered.
- Cost and availability, community libraries and tools, and the form factor.
- Skills: a beginner-friendly board with good documentation is worth a few dollars.
A sensible plan: start on an Arduino Uno (or a compatible 5 V board) for learning, and move to an ESP32 or Pico when you need Wi-Fi, more memory or lower cost.
6. On your bench
- Look up the datasheet of the chip on your board. Write down the clock speed, flash, SRAM, number of GPIO pins, logic level and the maximum current per pin.
- Identify the parts on the board: the microcontroller, the USB-serial chip, the voltage regulator, the reset button, the crystal or resonator, and the LED on pin 13 (or the board’s built-in LED).
- Calculate the cycle time at your board’s clock speed and the number of instructions per second.
- Compare two boards for a Wi-Fi temperature logger and justify your choice in three sentences.
7. Hands-on lab: clock, memory and board choice
8. Common mistakes
| Mistake | Better |
|---|---|
| Choosing a board by popularity alone | Write the requirements first and check them in the datasheet |
| Ignoring the logic level | Match 3.3 V and 5 V parts, or level-shift |
| Using up all the SRAM | Keep at least 20 to 30 percent free; watch the compiler report |
| Driving motors or relays straight from a pin | Use a transistor or driver |
| Writing flash or EEPROM in a tight loop | Both wear out; write rarely |
| Assuming a faster clock fixes a slow design | Look for the real bottleneck first |
9. Key takeaways
- A microcontroller puts the CPU, flash, SRAM, optional EEPROM and peripherals on one chip and runs one dedicated program.
- It differs from a microprocessor (needs external parts) and a single-board computer (runs Linux).
- Cycle time = 1 / clock; 16 MHz is 62.5 ns. Integer maths is quick on small chips.
- SRAM is usually the first limit; keep a margin and check the compiler’s memory report.
- Choose a board from I/O, memory, connectivity, logic level, power and cost, and respect pin current limits.
Your sketch reports 1,800 bytes of SRAM used out of 2,048 on an Uno. Is that a problem?
Yes. Only 248 bytes remain for the stack, which holds local variables and function calls at run time, so the program may crash in strange ways. Reduce buffers, store text in flash with the F() macro, use smaller types, or move to a board with more RAM.
Can You Explain It?
Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.
- Explain how a microcontroller differs from a microprocessor and a single-board computer.
- Describe what flash, SRAM and EEPROM are each used for.
- Explain how you would choose between an Arduino Uno, an ESP32 and a Raspberry Pi Pico for a project.
🧪 Want to practise this on your own computer? See how to set up your lab →