• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Arduino Projects / Introduction to EEPROM in Arduino

Introduction to EEPROM in Arduino

Last Updated on December 5, 2024 by Swagatam 16 Comments

In this post I have explained what EEPROM is, how data is stored on built in EEPROM on Arduino board’s Microcontroller and also practically test how to write and read data on EEPROM by a couple of examples.

Introduction to EEPROM in Arduino

 

Why EEPROM?

Before we ask what EEPROM is? It is very important to know why EEPROM is used for storage in first place. So that, we get clear idea on EEPROMs .

There are lot of storage devices available these days, ranging from magnetic storage devices like computer hard disks, old school cassette tape recorders, optical storage medium like CDs, DVDs, Blu-ray disks and solid state memory like SSD (Solid State Drive) for computers and Memory cards etc.

These are mass storage device which can store data such as music, videos, documents etc. from as low as few Kilobytes to multi-Terabytes. These are non-volatile memory which means, the data can be retained even after the power is cut-off to the storage medium.

The device which delivers ear soothing music or eye popping videos; such as computer or smartphone; stores some critical data such as configuration data, boot data, passwords, bio-metric data, login data etc.

These mentioned data cannot be stored in mass storage devices for security reasons and also these data could be modified by users unintentionally which could lead to malfunction of the device.

These data takes only few bytes to few Megabytes, connecting a conventional storage device like magnetic or optical medium to processor chips are not economically and physically feasible.

So, these critical data are stored in the processing chips itself.

The Arduino is no different from computer or smartphones. There are several circumstances where we need to store some critical data which must not get erased even after the power is cut-off, for example sensor data.

By now, you would have got an idea why do we need EEPROM on microprocessors and microcontrollers chips.

What is EEPROM?

EEPROM stands for Electrically Erasable Programmable Read Only Memory.  It is also a non-volatile memory which can be read and write byte wise.

Reading and writing byte-level makes it different from other semiconductor memories. For example flash memory: reading, writing and erasing data in block-wise manner.

A block can be few hundreds to thousands of bits, which is feasible for mass storage, but not for “Read Only Memory” operations in microprocessors and microcontrollers, which need to access byte by byte data.

On Arduino Uno board (ATmega328P) it has on board 1KB or 1024 bytes of EEPROM. Each byte can be accessed individually; each byte has address ranging from 0 to 1023 (that’s total of 1024).

Address (0-1023) is a memory location where our data will be stored.

On each address you can store 8-bit data, numeric digits from 0 to 255. Our data is stored in binary form, so if we write number 255 into EEPROM it will store the digit as 11111111 in an address and if we store zero, it will store as 00000000.

You can also store text, special characters, alphanumeric characters etc. by writing appropriate program.

The construction details and working are not discussed here which might make this article lengthy and we may make you sleepy. Head towards YouTube or Google, there are interesting article/videos regarding constructional and working of EEPORM.

Do not confuse EEPROM with EPROM:

In a nutshell EPROM is an Electrically Programmable Read Only Memory meaning it can be programmed (store memory) electrically, but can’t be erased electrically.

It utilizes bright shine of Ultraviolet light above storage chip which erases the stored data. EEPROM came as replacement for EPROM and now hardly used in any electronic devices.

Do not confuse Flash Memory for EEPROM:

A flash memory is a semiconductor and non-volatile memory which is also electrically erasable and electrically programmable, in fact flash memory is derived from EEPROM. But the block-wise memory access or in other words, the way of memory is accessed and its construction makes different from EEPROM.

Arduino Uno (ATmega328P Microcontroller) also sport 32KB of flash memory for program storage.

Lifespan of EEPROM:

Like any other electronic storage medium, EEPROM also has finite read, write, erase cycles. But the problem is; it has one of the least lifespan compare to any other kind of semiconductor memory.

On Arduino’s EEPROM, Atmel claimed about 100000 (one lakh) write cycle per cell. If your room temperature is lower the greater the lifespan of EEPROM.

Please note that reading data from EEPROM does not affect the lifespan significantly.

There are external EEPROM ICs which can be interfaced Arduino with ease with memory capacity ranging from 8 KB, 128KB, 256 KB etc. with life span of about 1 million write cycles per cell.

That’s concludes the EEPROM, now you would have gained enough theoretical knowledge about EEPROMs.

In the following section I have explained how to test the EEPROM on arduino practically. 

How to Test EEPROM in Arduino         

To implement this, all you need is a USB cable and Arduino Uno board, you are ready to go.

From the above explanations we understood  that EEPROMs have Address where we store our data. We can store 0 to 1023 locations in Arduino Uno. Each location can accommodate 8-bits or one byte.

In this example we are going to store data in an address. To reduce complexity of the program and to keep the program short as possible, we are going to store single digit integer (0 to 9) on an address from 0 to 9.

Program Code#1

Now, upload the code to Arduino:
//------------------Program Developed by R.GIRISH-------------------//
#include<EEPROM.h>
int inputAddress = 0;
int inputValue = 0;
int ReadData = 0;
boolean Readadd = true;
boolean Readval = true;
void setup()
{
Serial.begin(9600);
Serial.println("Enter the address (0 to 9)");
Serial.println("");
while(Readadd)
{
inputAddress = Serial.read();
if(inputAddress > 0)
{
inputAddress = inputAddress - 48;
Readadd = false;
}
}
Serial.print("You have selected Address: ");
Serial.println(inputAddress);
Serial.println("");
delay(2000);
Serial.println("Enter the value to be stored (0 to 9)");
Serial.println("");
while(Readval)
{
inputValue = Serial.read();
if(inputValue > 0)
{
inputValue = inputValue - 48;
Readval = false;
}
}
Serial.print("The value you entered is: ");
Serial.println(inputValue);
Serial.println("");
delay(2000);
Serial.print("It will be stored in Address: ");
Serial.println(inputAddress);
Serial.println("");
delay(2000);
Serial.println("Writing on EEPROM.....");
Serial.println("");
EEPROM.write(inputAddress, inputValue);
delay(2000);
Serial.println("Value stored successfully!!!");
Serial.println("");
delay(2000);
Serial.println("Reading from EEPROM....");
delay(2000);
ReadData = EEPROM.read(inputAddress);
Serial.println("");
Serial.print("The value read from Address ");
Serial.print(inputAddress);
Serial.print(" is: ");
Serial.println(ReadData);
Serial.println("");
delay(1000);
Serial.println("Done!!!");
}
void loop()
{
// DO nothing here.
}
//------------------Program Developed by R.GIRISH-------------------//

OUTPUT:

res

Once the code is uploaded, open the serial monitor.

It will ask you enter address ranging from 0 to 9. From the above output, I have entered address 3. So, I will be storing an integer value in the location (address) 3.

Now, it will prompt you to enter a single digit integer value ranging from 0 to 9. From the above output, I have entered value 5.

So, now the value 5 will be stored in the address location 3.

Once you enter the value, it will write the value on EEPROM.

It will show a success message, which means the value is stored.

After a couple of seconds it will read the value which is stored on the commented address and it will show the value on the serial monitor.

In conclusion, we have wrote and read the values from EEPROM of Arduino’s microcontroller.

Now, we are going to use the EEPROM for storing password.

We will be entering a 6 digit number (no less or no more) password, it will be stored in 6 different address (each address for each digit) and one additional address for storing “1” or “0”.

Once you enter the password, the additional address will store the value “1” indicating that password is set and the program will ask you to enter the password to turn ON the LED.

If the additional address stored value is “0” or any other value is present, it will ask you to create new 6 digit password.

By the above method, the program can identify whether you have already set a password or need to create a new password.

If the entered password is correct the build in LED at pin # 13 glows, if the entered password is incorrect, LED won’t glow and serial monitor will prompt that your password is wrong.

Program  Code#2

Now upload the code:
//------------------Program Developed by R.GIRISH---------------//
#include<EEPROM.h>
int passExistAdd = 200;
const int LED = 13;
int inputAddress = 0;
int word1 = 0;
int word2 = 0;
int word3 = 0;
int word4 = 0;
int word5 = 0;
int word6 = 0;
int wordAddress1 = 0;
int wordAddress2 = 1;
int wordAddress3 = 2;
int wordAddress4 = 3;
int wordAddress5 = 4;
int wordAddress6 = 5;
int passwordExist = 0;
boolean ReadVal1 = true;
boolean ReadVal2 = true;
boolean ReadVal3 = true;
boolean ReadVal4 = true;
boolean ReadVal5 = true;
boolean ReadVal6 = true;
int checkWord1 = 0;
int checkWord2 = 0;
int checkWord3 = 0;
int checkWord4 = 0;
int checkWord5 = 0;
int checkWord6 = 0;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
passwordExist = EEPROM.read(passExistAdd);
if(passwordExist != 1)
{
Serial.println("Enter a new 6 number password:");
while(ReadVal1)
{
word1 = Serial.read();
if(word1 > 0)
{
word1 = word1 - 48;
ReadVal1 = false;
}
}
while(ReadVal2)
{
word2 = Serial.read();
if(word2 > 0)
{
word2 = word2 - 48;
ReadVal2 = false;
}
}
while(ReadVal3)
{
word3 = Serial.read();
if(word3 > 0)
{
word3 = word3 - 48;
ReadVal3 = false;
}
}
while(ReadVal4)
{
word4 = Serial.read();
if(word4 > 0)
{
word4 = word4 - 48;
ReadVal4 = false;
}
}
while(ReadVal5)
{
word5 = Serial.read();
if(word5 > 0)
{
word5 = word5 - 48;
ReadVal5 = false;
}
}
while(ReadVal6)
{
word6 = Serial.read();
if(word6 > 0)
{
word6 = word6 - 48;
ReadVal6 = false;
}
}
Serial.println("");
Serial.print(word1);
Serial.print(word2);
Serial.print(word3);
Serial.print(word4);
Serial.print(word5);
Serial.print(word6);
EEPROM.write(wordAddress1, word1);
EEPROM.write(wordAddress2, word2);
EEPROM.write(wordAddress3, word3);
EEPROM.write(wordAddress4, word4);
EEPROM.write(wordAddress5, word5);
EEPROM.write(wordAddress6, word6);
EEPROM.write(passExistAdd,1);
Serial.println(" Password saved Sucessfully!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
if(passwordExist == 1)
{
Serial.println("");
Serial.println("Please enter the 6 digit number password:");
while(ReadVal1)
{
word1 = Serial.read();
if(word1 > 0)
{
word1 = word1 - 48;
ReadVal1 = false;
}
}
while(ReadVal2)
{
word2 = Serial.read();
if(word2 > 0)
{
word2 = word2 - 48;
ReadVal2 = false;
}
}
while(ReadVal3)
{
word3 = Serial.read();
if(word3 > 0)
{
word3 = word3 - 48;
ReadVal3 = false;
}
}
while(ReadVal4)
{
word4 = Serial.read();
if(word4 > 0)
{
word4 = word4 - 48;
ReadVal4 = false;
}
}
while(ReadVal5)
{
word5 = Serial.read();
if(word5 > 0)
{
word5 = word5 - 48;
ReadVal5 = false;
}
}
while(ReadVal6)
{
word6 = Serial.read();
if(word6 > 0)
{
word6 = word6 - 48;
ReadVal6 = false;
}
}
checkWord1 = EEPROM.read(wordAddress1);
if(checkWord1 != word1)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
checkWord2 = EEPROM.read(wordAddress2);
if(checkWord2 != word2)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
checkWord3 = EEPROM.read(wordAddress3);
if(checkWord3 != word3)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
checkWord4 = EEPROM.read(wordAddress4);
if(checkWord4 != word4)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
checkWord5 = EEPROM.read(wordAddress5);
if(checkWord5 != word5)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
checkWord6 = EEPROM.read(wordAddress6);
if(checkWord6 != word6)
{
Serial.println("");
Serial.println("Wrong Password!!!");
Serial.println("");
Serial.println("Press Reset Button.");
while(true){}
}
digitalWrite(LED, HIGH);
Serial.println("");
Serial.println("LED is ON");
Serial.println("");
Serial.println("Press Reset Button.");
}
}
void loop()
{
}
//------------------Program Developed by R.GIRISH---------------//

OUTPUT:

result

Open the serial monitor; it will prompt you to create a 6 digit number password.

Enter any 6 digit password and note it down and press enter. Now the password has been stored.

You may either press the reset button or disconnect the USB cable from PC, which make the supply to Arduino board interrupted.

Now, reconnect the USB cable, open serial monitor, which will prompt you to enter the saved 6 digit password.

Enter the correct password the LED will glow.

If you want to change the password change the digit from the code:

int passExistAdd = 200;

The above line is the additional address which I have explained before. Change anywhere from 6 to 1023. 0 to 5 addresses is reserved for storing 6 digit password.

Changing this additional address will fool the program that password is not created yet and prompt you to create a new 6 digit password.

If you have any questions regarding this EEPROM in Arduino tutorial, please express in the comments, you may receive a quick reply.

You'll also like:

  • 1.  High Current Motor Control Circuit using Arduino
  • 2.  Interface Accelerometer ADXL335 with LED and Arduino (Circuit Diagram)
  • 3.  How to Make a RFID based Attendance System
  • 4.  Incubator Using Arduino with Automatic Temperature and Humidity control
  • 5.  Car Reverse Parking Sensor Circuit with Alarm
  • 6.  Monitoring State of a Switch (Digital Read Serial) – Arduino Basics

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « Over Current Cut-off Power Supply Using Arduino
Next Post: Mobile Phone Controlled Robot Car Using DTMF Module »

Reader Interactions

Comments

  1. sinu says

    February 17, 2018 at 1:11 pm

    Hello sir, h r u.. very interesting topic. .. I have doubt-
    U might have seen many led display in roads and shops- different patterns of led, scrolling word and sentence etc. How to do this?whether they are using eeprom?
    U have any circuit for this?

    Reply
    • Swagatam says

      February 18, 2018 at 11:55 am

      Hi Sinu, the complex ones which show many many patterns surely are based on microcontrollers, presently I do not have the required codes for this type of project

      Reply
      • sinu says

        February 18, 2018 at 6:58 pm

        I dont want code sir . I only want the circuit or theory. means how they are doing. If you have any idea..

        Reply
        • Swagatam says

          February 19, 2018 at 11:03 am

          Sinu, I’ll try to get it, if I happen to find it will update it for you…

          Reply
          • sinu says

            February 19, 2018 at 8:02 pm

            Thankyou sir…hope to listen from you soon

            Reply
  2. ABBA says

    December 21, 2017 at 1:04 pm

    hi Swagatam
    Nice article and easy to understand. according to my understanding is that if you want to build a project that will be used permanently like in home electronics etc. then you have to write your programs in the EEPROM. AM I RIGHT? SINCE THE DATA STORED WILL NOT BE ERASED EVEN AFTER POWER FAILURE.
    THANKS A LOT

    Reply
    • Swagatam says

      December 21, 2017 at 2:21 pm

      Hi Abba, thanks for liking the article.

      I have not yet gone through the article and I am yet to learn microprocessors.

      It was written by Mr. GR, who a microcontroller expert, and he would be knowing the exact answer to your question, You can contact him anytime through his FB ID.

      Reply
  3. Farhan says

    September 7, 2017 at 5:41 am

    Sir
    Can you please help me
    I need a circuit
    When I power the circuit it will be relay on .
    And when sensor or anything detect green color it will be turn the relay off . If get any other color never turn off the relay .
    Sir please help me by providing this circuit

    Reply
    • Swagatam says

      September 7, 2017 at 6:10 am

      Farhan, triggering a circuit with color detection looks difficult, I am not sure how to do it…

      Reply
    • GR says

      September 7, 2017 at 9:01 am

      Hi,

      Triggering a circuit with colour is possible with RGB colour sensor with a Arduino or any microcontroller.

      Regards

      Reply
      • Swagatam says

        September 7, 2017 at 9:23 am

        Hi GR,

        you can send the article to me for publication. you can write about the module and project article separately.

        Reply
        • GR says

          September 7, 2017 at 10:10 am

          OK!

          Reply
  4. Sani Alkali says

    September 6, 2017 at 2:27 pm

    I really understand your explanation. I did it at School HND level.

    Reply
    • Swagatam says

      September 6, 2017 at 2:41 pm

      Thank you!

      Reply
  5. walter says

    September 5, 2017 at 6:28 am

    Hallo ,
    das eeprom wurde sehr gut und verständlich erklärt.

    viele grüße

    walter

    Reply
    • Swagatam says

      September 5, 2017 at 6:47 am

      Vielen Dank! Froh, dass es Ihnen gefallen hat …

      Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Subscribe to New Circuit Ideas

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (82)
  • Datasheets and Components (102)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (100)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)

Calculators

  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Filter Capacitor Calculator
  • Buck Converter Calculator
  • Boost Converter Calculator
  • Solar Panel, Inverter, Battery Calculator
  • Wire Current Calculator
  • SMPS Transformer Calculator
  • IC SG3525, SG3524 Calculator
  • Inverter LC Filter Calculator

People Also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Recent Comments

  • Swagatam on Simple Delay Timer Circuits Explained
  • Swagatam on The Role of Inductor Coil in SMPS
  • Swagatam on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA
  • Swagatam on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA
  • Victor on 7 Modified Sine Wave Inverter Circuits Explored – 100W to 3kVA

Company

  • Privacy Policy
  • Cookie Policy
  • About Me
  • Contact
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin
  • © 2025 · Swagatam Innovations