Arduino RAM Overflow

heavy coding and with just another variable or after some seconds serial transmitting nothing works as used? surprised

Could happen that you ran out of RAM, more special the SRAM as its called on the ATmega´s.

Lets digg into it and look how to get it sorted!



So something is totaly strange since your last compile? But the compiler gives no error?

You can already have overflow´s in the SRAM, or lets call it RAM from now on.


The Arduino uses the ATmega168 / ATmega328 / ATmega1280 / ATmega 2560, they all have different RAM Sizes:

also the ATtiny85 and ATmega32u4 is used by some Arduion Variants

AVR Chip: SRAM Size:
ATmega168 1 KB
ATmega328 2 KB
ATmega1280 8 KB
ATmega2560 8 KB
ATtiny85 512 Bytes
ATmega32u4 2,5 KB


But how much is already used?

First, we need to find the folder with the compiled files, in Arduino 20 and higher you have to open your temp folder.

in Arduino 1.8 and up its now in the "AppData\Local\Temp" Folder, you can open it directly with [WIN]+[R]: %appdata%

The compiled files are there in a folder named AppData\Local\Temp\arduino_build_315182  where the last number changes.

If you hit compile on your Arduino IDE, the content in the right folder gets updated!

so now we have that, we need to open the command line on that folder

and type: "avr-size ***.elf" where the *** stands for your programm name

If avr-size is not found, that is in the arduino avr bin folder: C:\Program Files (x86)\Arduino\hardware\tools\avr\bin

text is the actual code.

Now we summ the BSS and DATA, in this case its 2068.

If its higher it means you will overflow, no warning will be given by the compiler but it will go crazy...


Here we have now a ATmega328, the programm does fit the EEPROM, but not the RAM!


To reduce your RAM Footprint, take a look at all your variables, can they be "const" ? or do you have large strings what are not in PROGMEM?

To find that out in detail, type: "avr-objdump -t -j .bss xxx.elf > C:\dump.txt" this will give you a list of all variables, as the output is quite large the last part from the command will print the output to C:\dump.txt, you could change this to whatever you like!

That will give you a list of al variables and functions and theyr sizes. There you can find the bad boys what are to big!

Hope it helped you a bit, check out Forums for more about Arduino!

have fun, Steff














Comments powered by CComment