Memory

There are three pools of memory in the microcontrollers used on Arduino boards (e.g. the ATmega168):

  • Flash memory (program space), is where the Arduino sketch is stored.
  • SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.
  • EEPROM is memory space that programmers can use to store long-term information.

Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). SRAM is volatile and will be lost when the power is cycled.

Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change the values in the flash after the program has started running.

The amounts of memory for various microcontrollers used on Arduino boards are as follows:

 ATMega168ATMega328PATmega1280ATmega2560
Flash
(1 Kbyte used
for bootloader)
16 KBytes32 KBytes128 KBytes256 KBytes
SRAM1024 bytes2048 bytes8 KBytes8 KBytes
EEPROM512 bytes1024 bytes4 KBytes4 KBytes

One thing you will notice in the chart above is that there is a lot more Flash (program) memory than SRAM available. When you create variables with the Arduino language such as:

char message[] = "I support the Cape Wind project.";

You are copying 33 bytes (1 char = 1 byte, plus terminating null) from program memory into SRAM before using it. 33 bytes isn't a lot of memory in a pool of 1024 bytes, but if the sketch requires some large unchanging data structures - such as a large amount of text to send to a display, or a large lookup table, for example - using flash memory (program memory) directly for storage may be the only option. To do this, use the PROGMEM keyword.

Version 1.0 of the Arduino IDE introduced the F() syntax for storing strings in flash memory rather than RAM. e.g.

Serial.println(F("This string will be stored in flash memory"));

To use the EEPROM, see the EEPROM library or the extended EEPROM library EEPROMex library

Share