This project has moved. For the latest updates, please go here.
Executing availableMemory() returns the number of free memory (in bytes)


#include <AvailableMemory.h>

void setup() { 

void loop() {
  int iFreeMem=availableMemory();
  Serial.print(F("Free memory (bytes): "));


Execute availableMemory() to get the number of free bytes in memory.

Please note that memory requirements can change very fast in any sketch and even by executing this function the free memory is altered. Use the information as one indicator if your sketch goes haywire.

I have created sketches that reported 1100 free bytes in the main loop() function just to crash a second later because a different routine needed more memory than expected.


This function is based on get_free_memory() by "Paul" described in the following post:

An advanced version of this code is freeRam() found here:

The original code is also used inside the SdFat Library (SdFatUtil.h - FreeRam()) and documented in "Jonathan Oxer, Hugh Blemings: Practical Arduino: Cool Projects for Open Source Hardware", so I’m sticking with the original version.

The name "availableMemory" is taken from "flash_example.pde", an example for the Flash library created by Mikal Hart

Last edited Oct 19, 2012 at 11:46 AM by TeXHeX, version 8


No comments yet.