What is Arduino EEPROM? How Is It Used?

ARDUINO EEPROM


What is Arduino EEPROM?

EEPROM is a storage unit that can store data we need and need to be preserved even when the board is powered off.
The data written to EEPROM can be erased and rewritten, and later can be read as we wish.
The biggest feature of EEPROM is that even if the power is cut off, the data written there is not erased, and when the board is powered again you can read the data there.
If you create a system with Arduino that keeps a record of money, you can ensure that the money is stored in the Arduino memory even if the power goes out, which is one of the simplest examples regarding usage areas.


How to Use Arduino EEPROM?

The first thing we need to know is that we need to include the EEPROM library in our project. "#include <EEPROM.h>" Afterwards, we can easily store data as we wish using the EEPROM commands.

With "EEPROM.read(address);" you can read from EEPROM and with "EEPROM.write(address, data);" you can write to EEPROM.

The address part above designates an address in EEPROM and with this address, we can write and erase data in EEPROM. By increasing the address count, the number of data entries in EEPROM can also be increased.

If we were to examine with a sample code;

#include <EEPROM.h> 


int recordAddress = 5; // We set our record address
int readMoney; // We will write the data read from EEPROM here
unsigned long money; // This will be our valid data.

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  readMoney = EEPROM.read(recordAddress); // We pulled the recorded data in the system
  delay(10);
  money = readMoney; // We added the pulled data to our value that will be changed continuously
  money++; // We increased the data
  EEPROM.write(recordAddress, money); // We wrote the new data to EEPROM
  delay(5000);
  
}

That's all for using EEPROM, friends. If there is anything you are curious about regarding EEPROM, you can write it in the comment section below.


A simple sample study related to EEPROM. 
The amount of money, which is 3, continues to be shown as 3 after the adapter plug is unplugged and plugged back in.