Sub topic 14
Memory sizes on other boards
This chapter assumes you can compile and upload a sketch, read the Serial Monitor, and understand variables, arrays, and functions. The examples use an Arduino Uno as the reference board.
Memory is not the same on every Arduino
An Arduino board usually has three relevant memory areas:
- Flash stores the program and constants. It keeps its contents when power is removed.
- SRAM stores global variables, local variables, the stack, and dynamically allocated data while the program runs.
- EEPROM, or an EEPROM-like area, stores small values across power cycles.
The exact size depends on the microcontroller on the board. A board with more flash can hold a larger program, but that does not automatically give the sketch more SRAM. A program can fit in flash and still fail because it runs out of SRAM.
| Board | Flash | SRAM | EEPROM or data memory |
|---|---|---|---|
| Uno R3 or classic Nano | 32 KB | 2 KB | 1 KB EEPROM |
| Mega 2560 | 256 KB | 8 KB | 4 KB EEPROM |
| Leonardo or Micro | 32 KB | 2.5 KB | 1 KB EEPROM |
| Nano Every | 48 KB | 6 KB | 256 bytes EEPROM |
| Uno R4 Minima | 256 KB | 32 KB | 8 KB data memory |
These values use decimal-style labels from board documentation. Some tools report a small amount less because the bootloader occupies part of flash, or because a runtime reserves memory.
Compare the memory roles
The Mega 2560 has eight times as much SRAM as the Uno R3, so it tolerates larger buffers and more complex data structures. It does not make an Uno sketch automatically portable, though. Code may depend on a board-specific pin, serial port, timer, or library.
The Uno R4 has much more SRAM than the classic Uno and uses a different processor family. AVR-specific techniques such as PROGMEM, pgm_read_word(), and direct AVR register access may need changes. Always check whether a memory technique is specific to the processor architecture.
Read the build output for the selected board
The Arduino IDE reports memory usage after compilation. A typical report might say:
- Sketch uses 4,120 bytes of program storage space.
- Global variables use 420 bytes of dynamic memory.
- Local variables leave 1,628 bytes for local variables.
The first value concerns flash. The second concerns statically allocated SRAM. The last value is an estimate of the SRAM remaining for the stack and other run-time use.
Change the selected board in the IDE before compiling. The same sketch can produce different numbers because each board has a different linker configuration and runtime.
Treat the report as a starting point, not a guarantee. A large local array, a deep call chain, or heap allocation can consume the remaining SRAM after the report is printed.
Choose a board from the real memory need
Estimate the largest objects your sketch needs:
- Add global arrays, buffers, and library allocations.
- Reserve space for the stack and temporary work.
- Leave a safety margin for future changes.
- Compile for the actual target board and inspect the report.
- Test the sketch while all features are active.
For a small Uno project, a design that leaves only a few dozen bytes of SRAM is risky. Moving constant text to flash, using fixed-size buffers, or selecting a board with more SRAM can solve the problem. Selecting a larger board is often simpler than forcing a constrained design, but the board must still meet voltage, pin, timing, and library requirements.
Exercise
A sketch uses 28 KB of flash and 1.7 KB of SRAM. Will it run safely on a classic Uno R3, and what should you check next?
Show answer
It fits within the Uno's 32 KB flash and 2 KB SRAM, but the SRAM margin is only about 300 bytes before stack and run-time use. Compile for the Uno, inspect the actual build report, measure free SRAM while the sketch runs, and reduce memory use or choose a board with more SRAM if the margin is too small.