Source: https://mokxi.com/libraries/eeprom
Updated: 2026-11-02

Libraries / Core
Arduino library · Core

# The Arduino EEPROM library: memory that keeps its value

The ATmega chips on most Arduinos have a small EEPROM next to their flash: 1 KB on the Uno, Nano and Leonardo, 4 KB on the Mega, 512 bytes on an ATtiny85. Unlike RAM it keeps what was written when the power goes, so it is where a sketch keeps a high score, a calibration value or the last setting a user picked. EEPROM.h reads and writes it a byte at a time, or a whole variable at once.

Open the example in the editor See the calls

Built in on Mokxi: #include <EEPROM.h> and it builds, with nothing to install. Free, and no account needed.

## What EEPROM does

Each byte of EEPROM survives about 100,000 writes, which sounds like a lot until a sketch writes the same address in loop() a hundred times a second and wears it out in a quarter of an hour. That is why update() exists: it reads the byte first and only writes when the value changes. put() uses update() for every byte of the variable.

A fresh chip reads 255 (0xFF) at every address. ESP32 and ESP8266 boards have no real EEPROM; their cores emulate it in flash, and need EEPROM.begin(size) before use and EEPROM.commit() after writing. On the ESP32 the Preferences library is the better choice for new code.

Library Manager name | EEPROM

Author | Arduino

Include | #include <EEPROM.h>

Boards | every board Mokxi compiles for

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on every board Mokxi compiles for.

In Mokxi it is built in: #include <EEPROM.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board it comes with the board package (Arduino), so the Arduino IDE has it as soon as the board is installed: there is nothing to add from the Library Manager.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · ATtiny85 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### EEPROM.read(address)

Returns the byte at an address from 0 to EEPROM.length() - 1. An address never written returns 255.

### EEPROM.write(address, value)

Writes one byte, 0 to 255. It always writes, even when the value is already there, and takes about 3.3 ms on an AVR.

### EEPROM.update(address, value)

Writes the byte only if it differs from what is stored, which saves the chip’s limited write cycles.

### EEPROM.put(address, data)

Writes any variable or struct, byte by byte with update(). The next free address is address + sizeof(data).

### EEPROM.get(address, data)

Reads a variable or struct back into data, the same size put() wrote.

### EEPROM.length()

The size of the EEPROM in bytes, so a loop can clear or dump all of it.

### EEPROM.begin(512)

The ESP32 and ESP8266 call: sets aside that many bytes of emulated EEPROM in RAM. Other boards accept it and ignore it.

### EEPROM.commit()

On the ESP boards, copies the RAM buffer to flash. Without it, writes are lost at the next reset.

## Example: EEPROM: memory that survives a reset

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · EEPROM: memory that survives a reset: the project page

## Common errors and how to fix them

### The value comes back as 255, or as -1 from an int

Nothing has been written there yet: an erased EEPROM byte is 0xFF, and two of them read into an int is -1. Write a known value first, or keep a magic number at address 0 to tell a fresh chip from a saved one.

### Writes are lost after a reset on an ESP32 or ESP8266

On those boards EEPROM is a copy in RAM. Call EEPROM.begin(size) in setup() and EEPROM.commit() after writing, or move to the Preferences library on the ESP32.

### A float or long saved with write() reads back wrong

write() and read() handle one byte, so a multi-byte value is cut down to its lowest byte. Use put() and get(), which store and load every byte of the variable.

### The saved value stopped changing after weeks of use

That address has probably worn out from being written in loop(). Write only when the value really changes (update() or put() help), and if you must log often, move to a new address each time.

## Projects that use EEPROM

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Arcade button Simon game An arcade button Simon game: four lit buttons and a piezo, a sequence that grows one color a round, a note per color and the best round kept in EEPROM. Tetris on LED matrices Tetris on LED matrices with an Arduino Mega: two 8x8 MAX7219s make an 8 by 16 field, with four buttons, all seven pieces, line clears and a high score. Servo turnouts with a panel Two servo turnouts that glide across one degree at a time, a panel button and a pair of route lamps for each, and positions kept in EEPROM so nothing jumps at power-up. Robot arm record and playback Teach a four-servo arm a routine with four knobs, save each pose to EEPROM with a button, then press PLAY and it glides through them on its own. Electronic voting machine Electronic voting machine on an Arduino Nano: four buttons to vote, a result button for every count and the winner on an LCD, and the votes kept in EEPROM. Slot machine Pull a real arcade lever to spin three OLED reels that stop one by one.

## Keep going

### Learn

- Arduino EEPROM: Read, Write, put() and get()

### More core libraries

- Wire
- SPI
- FreeRTOS (Arduino_FreeRTOS)

Every built-in library · Open the editor

## Try EEPROM without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
