Learning   Examples | Foundations | Hacking | Links

Examples > EEPROM Library


The microcontroller on the Arduino board has 512 bytes of EEPROM: memory whose values are kept when the board is turned off (like a tiny hard drive). This example illustrates how to set of all of those bytes to 0, initializing them to hold new information, using the EEPROM.write() function.

Hardware Required

  • Arduino Board


There is no circuit for this example.

image developed using Fritzing. For more circuit examples, see the Fritzing project page


The code below uses a for() loop in cycling through all 512 bytes of EEPROM memory, and in setting them each to 0. Because this needs to happen only once, the bulk of this code takes place in the setup() function when the sketch starts.

 * EEPROM Clear
 * Sets all of the bytes of the EEPROM to 0.
 * This example code is in the public domain.


#include <EEPROM.h>

void setup()
  // write a 0 to all 512 bytes of the EEPROM
  for (int i = 0; i < 512; i++)
    EEPROM.write(i, 0);
  // turn the LED on when we're done
  digitalWrite(13, HIGH);

void loop()

See also