The EEPROM (Electrically Erasable Programmable Read-Only Memory) library in Arduino allows you to store data persistently even after power loss. EEPROM is useful for saving settings, calibration data, or logs.
1. Including the EEPROM Library
First, include the EEPROM library in your sketch:
2. Basic EEPROM Functions
A. EEPROM.write(address, value)
Writes a byte (0–255) to a specific EEPROM address.
Example:
B. EEPROM.read(address)
Reads a byte (0–255) from an EEPROM address.
Example:
C. EEPROM.update(address, value)
Only writes if the value differs from what’s already stored (reduces wear).
Example:
D. EEPROM.put(address, data)
Stores any data type (e.g., int, float, struct).
Example:
E. EEPROM.get(address, data)
Retrieves any data type stored with EEPROM.put().
Example:
3. Storing Strings (Char Arrays)
Since EEPROM works with bytes, strings must be written character by character.
Writing a String
Reading a String
Example Usage
4. EEPROM Size & Limitations
⚠️ Wear Leveling Warning:
5. Clearing EEPROM
To reset all EEPROM values to 0:
6. Full Example: Storing Sensor Data
Key Takeaways