Notifications
Clear all

What is EEPROM in Arduino and how to use it?

2 Posts
3 Users
2 Reactions
3,020 Views
1
Topic starter

Hi everyone,

I’m new to Arduino and would like to understand how EEPROM works. Can someone explain what EEPROM is and how it differs from other types of memory on the Arduino?

I’d appreciate some guidance on how to store and retrieve data using EEPROM, especially to ensure the data remains after powering off the board.

I’ve also read that EEPROM can only be programmed a limited number of times. Is that true? If so, could you explain a bit more about it?

Thank you

 


2 Answers
1

EEPROM (Electrically Erasable Programmable Read-Only Memory) allows you to store data even after the board is powered off. It's non-volatile. This makes it useful for storing things like settings, calibration values, or any data you want to retain.

Let's understand the different memory types in Arduino:

  1. SRAM: Works as temporary storage while the program is running. Data in SRAM is lost when the power is turned off.
  2. Flash Memory: The Arduino stores your program code here. Like EEPROM, flash memory is non-volatile, but you can't store or retrieve any data dynamically(when the program is running) there.
  3. EEPROM: Used for storing small amounts of data that need to be retained after a power off.

EEPROM Addresses:
EEPROM is organized like an array where each memory location has a unique address. The address tells you where a specific piece of data is stored. Each address stores one byte of data.

For example, if you write a value to address 0, that value will be stored at the first position in EEPROM memory.
If you write another value to address 1, it will be stored at the next position, and so on.

The total number of addresses available in EEPROM depends on the Arduino board. For example, on an Arduino Uno, there are 1,024 addresses, so you can store 1,024 bytes of data (0 to 1,023). And now you know why! because the EEPROM size is 1kB.

You can store and retrieve data from specific addresses using functions like EEPROM.write(address, value) and EEPROM.read(address).

Storing Data in EEPROM:

#include <EEPROM.h>

void setup() {
  int dataToStore = 123;
  EEPROM.write(0, dataToStore); // Store the value 123 at address 0
}

void loop() {
  // Do nothing
}

Retrieving Data:

#include <EEPROM.h>

void setup() {
  int storedData = EEPROM.read(0); // Retrieve the value from address 0
  Serial.begin(9600);
  Serial.println(storedData);
}

void loop() {
  // Do nothing
}

And yes, EEPROM has a limited number of write cycles—around 100,000 per address on most Arduino boards. This means that if you constantly write data to the same location, you could wear it out over time. 


0

It’s more like ROM—the kind of memory you use when you need the data to stick around, even if power is lost. Think of it like writing something on your hand before going to sleep so you don’t forget it in the morning.

On an Arduino, EEPROM is perfect for saving things like strings, integers, or configuration values that you want to recall the next time the board powers up.

Unlike SRAM (which gets cleared when the board resets) or Flash (which mainly holds your program), EEPROM gives you a small but persistent space for your own data.


Share: