Home Learning About EEPROM Write and Arduino

About EEPROM Write and Arduino

by shedboy71

In this example we will write to the EEPROM which is on the micro controller of the Arduino

The supported micro-controllers on the various Arduino and Genuino boards have different amounts of EEPROM: 1024 bytes on the ATmega328P, 512 bytes on the ATmega168 and ATmega8, 4 KB (4096 bytes) on the ATmega1280 and ATmega2560. The Arduino and Genuino 101 boards have an emulated EEPROM space of 1024 bytes.

This example illustrates how to store values read from analog input 0 into the EEPROM using the EEPROM.write() function. A little about EEPROM first

EEPROM (also E2PROM) stands for Electrically Erasable Programmable Read-Only Memory and is a type of non-volatile memory used in computers, integrated in microcontrollers for smart cards and remote keyless system, and other electronic devices to store relatively small amounts of data but allowing individual bytes to be erased and reprogrammed.

EEPROMs are organized as arrays of floating-gate transistors. EEPROMs can be programmed and erased in-circuit, by applying special programming signals. Originally, EEPROMs were limited to single byte operations which made them slower, but modern EEPROMs allow multi-byte page operations. It also has a limited life for erasing and reprogramming, now reaching a million operations in modern EEPROMs. In an EEPROM that is frequently reprogrammed while the computer is in use, the life of the EEPROM is an important design consideration.

Flash memory is a type of EEPROM designed for high speed and high density, at the expense of large erase blocks (typically 512 bytes or larger) and limited number of write cycles (often 10,000). There is no clear boundary dividing the two, but the term “EEPROM” is generally used to describe non-volatile memory with small erase blocks (as small as one byte) and a long lifetime (typically 1,000,000 cycles). Many microcontrollers include both: flash memory for the firmware, and a small EEPROM for parameters and history. – https://en.wikipedia.org/wiki/EEPROM



[codesyntax lang=”cpp”]

 * EEPROM Write

#include <EEPROM.h>

/** the current address in the EEPROM **/
int addr = 0;

void setup()

void loop() 
    Need to divide by 4 because analog inputs range from
    0 to 1023 and each byte of the EEPROM can only hold a value from 0 to 255.
  int val = analogRead(0) / 4;
    Write the value to fthe EEPROM.
  EEPROM.write(addr, val);

    Advance to the next address, when at the end restart at the beginning.
  addr = addr + 1;
  if (addr == EEPROM.length()) {
    addr = 0;




You may also like

Leave a Comment