Learn Arduino Tutorials Open the 3D lab

Intermediate · 5 min read

Arduino EEPROM — save data that survives power off

Variables forget everything when the power goes off. EEPROM is a tiny memory inside the Arduino that remembers. Use it for a high score, a calibration value or the last setting a user chose.

An Arduino UNO wired to a temperature sensor and a fan, a project whose chosen temperature setting could be saved in EEPROM
Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →

The short answer

EEPROM (electrically erasable programmable read-only memory) keeps its data with the power off. On an Arduino UNO there are 1,024 bytes of it, each holding a number from 0 to 255.

#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  EEPROM.update(0, 123);            // save 123 at address 0
  byte saved = EEPROM.read(0);      // read it back
  Serial.println(saved);            // 123, even after you unplug and replug
}

void loop() {}

Unplug the board, plug it in, and address 0 still holds 123.

Three kinds of memory on the UNO

MemorySizeKeeps data without power?Holds
Flash32 KByesyour program
SRAM2 KBnoyour variables while running
EEPROM1 KByesdata you choose to save

Your normal variables live in SRAM and vanish at power-off. EEPROM is the place on the UNO for data you want to keep, short of adding a memory card.

The functions

#include <EEPROM.h>

EEPROM.read(address);            // returns one byte (0–255)
EEPROM.write(address, value);    // writes one byte
EEPROM.update(address, value);   // writes only if the value is different
EEPROM.put(address, variable);   // saves any type: int, float, struct
EEPROM.get(address, variable);   // reads it back into the variable
EEPROM.length();                 // 1024 on an UNO

The address is a number from 0 to 1023. Prefer update() to write(). It checks first and skips the write when nothing changed, which protects the memory (see the wear section below).

Saving numbers bigger than a byte

One cell holds 0–255. A normal int needs 2 bytes, a long or float needs 4. put() and get() do the splitting for you:

#include <EEPROM.h>

int highScore;

void setup() {
  Serial.begin(9600);
  EEPROM.get(0, highScore);          // reads 2 bytes from address 0
  Serial.print("Saved high score: ");
  Serial.println(highScore);
}

void loop() {
  // when the player beats it:
  // highScore = newScore;
  // EEPROM.put(0, highScore);       // saved in addresses 0 and 1
}

An int starting at address 0 uses addresses 0 and 1. The next free address is 2. If you store several values, write down which address holds what, or they will overwrite each other. See variables and data types for sizes.

A counter that survives power-off

This counts how many times the board has started:

#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  int starts;
  EEPROM.get(0, starts);
  if (starts < 0 || starts > 10000) {   // a brand-new chip: nothing saved yet
    starts = 0;
  }
  starts++;
  EEPROM.put(0, starts);
  Serial.print("This board has started ");
  Serial.print(starts);
  Serial.println(" times");
}

void loop() {}

Open the Serial Monitor, press the board's reset button a few times, unplug it and plug it back in. The count keeps growing. Opening the monitor resets an UNO as well, so each open counts.

A thermostat is a good fit: it should remember the temperature the user chose
A thermostat is a good fit: it should remember the temperature the user chose · open it full screen

A new chip reads 255

A fresh, unused cell holds 255 (all bits set to 1). A new int therefore reads as -1 from address 0 (255 in both bytes). That is useful: you can detect that nothing was ever saved and write a sensible default, as the counter above does.

Wear: the limit that matters

Each EEPROM cell survives about 100,000 writes (the figure for the chip in the UNO). Reads are unlimited. A write takes about 3.3 ms, and the sketch pauses during it.

This is why you must never write EEPROM inside a fast loop:

void loop() {
  EEPROM.write(0, analogRead(A0) / 4);   // BAD: thousands of writes per minute
}

That loop could use up address 0 in a few hours. Instead, write only when something changes, and use update(). A good pattern is to save a setting when the user presses a button, not every time round loop().

HabitResult
EEPROM.write in loop()cell worn out in hours
EEPROM.update when a value changesdecades of normal use
save when a button is pressedtiny wear

Common mistakes

  • Forgetting #include <EEPROM.h>. The compiler says 'EEPROM' was not declared in this scope.
  • Writing in loop() with no condition. It wears the cell out quickly.
  • Overlapping addresses. An int at 0 and a float at 1 overwrite each other. Leave 2 bytes for an int and 4 for a float.
  • Assuming it starts at zero. A new cell reads 255, not 0.
  • Expecting to store a String. put() works with fixed-size types. Store a char array instead.
  • Expecting the data to vanish when you upload a new sketch. Normally the EEPROM keeps its data through an upload, so your saved value is still there.

Check yourself

  1. What happens to a normal variable when the power goes off?

  2. How many bytes does an int need in EEPROM?

  3. Why use EEPROM.update() instead of write()?

Questions people ask

Does EEPROM keep data after I upload a new sketch?

Usually yes. Uploading replaces the program in flash, and the EEPROM is a separate memory. It survives unless a fuse setting or a sketch erases it.

How do I clear the EEPROM?

Write 255 to every address with a loop: for (int i = 0; i < EEPROM.length(); i++) EEPROM.update(i, 255);. It takes a few seconds, and it counts as one write per cell that held something else.

Do other boards have more EEPROM?

It varies. The Mega 2560 has 4 KB. Some newer boards emulate EEPROM in flash, and the ESP32 uses a flash-based version with different rules, so check your board's page.

Can I check how much I have used?

The chip does not track it. Keep a small table in your notes, or reserve a fixed address for each setting.

What's next

Use EEPROM to remember the target temperature in the thermostat project, and set it by typing a number as in Serial input. Then continue with interrupts.

Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →
Next: Arduino interrupts explained — react instantly with attachInterrupt →

Your progress stays on this device — no account, nothing sent anywhere.

Last updated 2026-12-01

Read next