0
0
AutocadHow-ToBeginner · 3 min read

How to Read Data from EEPROM in Arduino: Simple Guide

To read data from EEPROM in Arduino, use the EEPROM.read(address) function where address is the memory location you want to read from. This function returns the byte stored at that address, allowing you to retrieve saved data easily.
📐

Syntax

The basic syntax to read a byte from EEPROM is:

  • EEPROM.read(address): Reads a byte from the EEPROM at the specified address.
  • address: An integer representing the EEPROM memory location (0 to EEPROM size - 1).
  • The function returns a byte value stored at that address.
arduino
byte value = EEPROM.read(address);
💻

Example

This example shows how to read a byte from EEPROM address 0 and print it to the Serial Monitor.

arduino
#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) { }

  // Read byte from EEPROM address 0
  byte storedValue = EEPROM.read(0);

  Serial.print("Value read from EEPROM address 0: ");
  Serial.println(storedValue);
}

void loop() {
  // Nothing here
}
Output
Value read from EEPROM address 0: 0
⚠️

Common Pitfalls

  • Reading wrong address: Make sure the address is within EEPROM size (usually 0 to 1023 on Arduino Uno).
  • Data type mismatch: EEPROM.read() reads one byte; for larger data types, read multiple bytes and reconstruct the value.
  • Uninitialized EEPROM: EEPROM may contain random data if not written before reading.
autocad
/* Wrong way: reading outside EEPROM size */
// byte val = EEPROM.read(1024); // Invalid address on Arduino Uno

/* Right way: check address before reading */
int address = 0;
if (address >= 0 && address < EEPROM.length()) {
  byte val = EEPROM.read(address);
}
📊

Quick Reference

  • EEPROM.read(address): Read one byte from EEPROM.
  • EEPROM.write(address, value): Write one byte to EEPROM.
  • EEPROM size varies by board (e.g., 1024 bytes on Arduino Uno).
  • Use EEPROM.length() to get EEPROM size.

Key Takeaways

Use EEPROM.read(address) to get a byte stored at a specific EEPROM address.
Always ensure the address is within the valid EEPROM range before reading.
EEPROM stores bytes; read multiple bytes to reconstruct larger data types.
Initialize EEPROM data before reading to avoid unexpected values.
Use Serial Monitor to verify EEPROM read results during development.