Arduino EEPROM Write & Read, Arduino EEPROM Examples

(Last Updated On: February 15, 2020)

Description:

Arduino EEPROM Write & Read Operations– In this tutorial you will learn how to use the Arduino EEPROM at the basic and advanced level. We will cover the extreme basics including storing a string message in the Arduino EEPROM and then reading and erasing the stored message. I will explain in detail the Arduino EEPROM Read and Arduino EEPROM Write operations.

I will also explain how to make an advanced level project based on the Arduino and Bluetooth Module for storing

  • Multiple cell phone numbers in the Arduino EEPROM.
  • How to update any cell phone number in the EEPROM?
  • How to erase a particular cell phone number?
  • How to erase all the cell phone numbers and string messages stored in the Arduino EEPROM?
  • How to display all the stored cell phone numbers?

These EEPROM Reading and Writing processes will be wirelessly controlled using the android cell phone. Once a program is uploaded into the Arduino Uno, then there is no need to manually connect the Arduino with the computer to update any cell phone number or any other data. The user can store, update, read, erase, and display any information using the android cell phone. The commands are sent wirelessly from the Android cell phone application to the Arduino using the HC-05 Bluetooth Module.

This tutorial will really help you in making advanced level projects where you need to store the information permanently. You can use the Arduino EEPROM in different projects e.g.

  • Arduino and GSM based security system.
  • Car accident location tracking system.
  • Home automation systems
  • Data logging projects, and so on.

This tutorial can be a bit longer as I will be explaining the basic and advanced things about the Arduino EEPROM. I will also share with you the simulation screenshot.

Without any further delay let’s get started!!!


What is EEPROM?

The term EEPROM stands for electrically erasable programmable read-only memory. This is the Non-volatile memory and is used in Computer systems, microcontrollers, smart cards, remote keyless systems, and other electronic devices for storing small amounts of data that can be erased/deleted and reprogrammed. We have other types of the Non-volatile memory including

  • Mask Rom
  • PROM
  • EPROM
  • EEPROM
  • Flash Memory etc

Unlike the computer systems, Arduino also comes with the Internal and External type of EEPROMs

Arduino Internal EEPROM

The Arduino’s internal EEPROM is quite fast as compared to the external EEPROM. We can use the Arduino’s internal EEPROM in different types of projects quite easily. The amount of the EEPROM memory depends upon which Arduino Model we are using.

Arduino Model                                              Capacity

Arduino Mega 2560 “Atmega2560”              4096 Bytes

Arduino Uno, Mini, and some Nanos             1024 Bytes

Atmega168 “Nanos”                                       512 Bytes

Arduino Internal EEPROM limitations:

The Arduino internal EEPROM has some limitations that you need to consider before you are going to use this in your project. Although it is easy to use EEPROM in the Arduino, it does have a limited life. The Arduino’s internal EEPROM is specified to handle 100,000 read/erase cycles. This means you can write, erase the data/re-write the data 100,000 times before the EEPROM will become unstable. So this is the major limitation that you definitely take into consideration. So, if you are working on a project and you are constantly storing and erasing the data then you are not supposed to use the Arduino’s internal EEPROM. In a situation like this you can use an SD card, because the external EEPROM won’t work as well.



Arduino External EEPROM

The Arduino compatible External EEPROM chips are not that fast as the Arduino’s internal EEPROM, but if you need more capacity and larger write-cycle tolerance than the 100,000 writes then the Arduino External EEPROM is the only choice you are left with. You can easily interface the external EEPROMs with the Arduino Boards using the I2C bus. I will talk about the Arduino’s external EEPROM in a separate tutorial, for now let’s stick with the Arduino’s internal EEPROM.

When not to use the EEPROM?

It really doesn’t matter if you are using the Arduino internal EEPROM or External EEPROM, each one has a limited number of write cycles. If you are performing thousands of writing and erasing cycles, like storing the sensors data and then erasing them, soon the EEPROM writes cycles will be completed and the EEPROM will become unstable. In data logging projects you can use large size SD.

How to perfectly use the Arduino’s internal EEPROM?

The Arduino Uno, Mini, and some Nanos can store 1024 Bytes of data which is more than enough for thousands of projects. And as I already explained Arduino can handle 100,000 read/erase cycles. You can use the Arduino’s internal EEPROM in all those projects where you perform the writing and erasing tasks on random basis, like for example, updating a cell phone number used in a security based project. this number is not updated on daily basis, may be after one month or 1 year, or may be 2 years in a situation like this it works perfectly. 100,000 write cycles are more than enough.

You can use this for storing the RFID cards identity numbers. Let’s say you have a door security system and you have given access to 5 persons. You can erase/rewrite any number. This erase/rewrite thing is not performed on daily basis.

Enough with the theory.


Arduino EEPROM Example Number1:

In example 1 we will write a simple program which displays the data stored in the EEPROM, delete/erase the stored string message, and asks again for the new message to enter. You can enter the text using the Arduino’s serial monitor. For the best understanding I designed a simulation in Proteus, which is available for the download, the link is given below.

Arduino EEPROM

Download Arduino EEPROM Example 1 Simulation: Proteus simulation

Arduino EEPROM Example 1 programming:


Testing:

Simply copy the above code and open the Arduino IDE and paste it. Before you click on the compile button.

Click on the Arduino IDE file menu and then click on the preferences.

Arduino EEPROM

Make sure the compilation and upload boxes are checked and then click on the OK button. Now, click on the compile/verify button. This will check for the errors and will also generate the Hex file link.

Arduino EEPROM

Copy this link. Now open the Proteus simulation. Double click on the Arduino and paste this link.

Arduino EEPROM

Now click on the ok button. You are all set. Now you can click on the play button to start the simulation.

Arduino EEPROM

When you run the simulation, it will display the previous text saved in the EEPROM, then it Erase the EEPROM. Then it will ask you to enter new text. I simply entered Electronic Clinic. Now if you stop the simulation and run this simulation again.

Arduino EEPROM

As you can see this time it displayed the previous text which was electronic Clinic, erased this text and now asking for new text, now this is repeated again and again.


Arduino EEPROM Example 2:

This example itself is an advanced level project, which I designed for a client long time again. In this project a user can enter 10 cell phone numbers wirelessly using the Android cell phone application. Any number can be erased or updated. The user can display all the stored numbers and can also delete all the stored numbers. Different commands are used.

So there is no need to connect the Arduino board with the laptop to update any number. The same project can be used for storing the identity numbers of the RFID tags in the Arduino EEPROM.

 

Arduino Bluetooth Circuit Diagram:

Arduino EEPROM

The Tx and Rx pins of the HC-05 or HC-06 are connected with the Arduino’s Rx and Tx pins, while the ground and VCC pins are connected with the Arduino’s gnd and 5 volts pins.

If you don’t have the Bluetooth module then you can simply use the Arduino’s serial monitor for the testing purposes. Or you can use the Proteus simulation given above.



Arduino EEPROM program for storing and Erasing cell phone numbers:


Testing:

In example 1 I have already explained how to generate the Hex file link. Follow the same exact steps. After the link has been pasted into the Proteus simulation. Click on the Play button to start the simulation.

Cell numbers storing commands:

The commands a, b, c, d, e, f, g, h, I, and j are used for storing ten numbers. if you want to update the third cell phone number simply enter c and press enter, and then write the cell phone number.

Cell numbers Erasing commands:

The commands l, m, n, o, p, q, r, s, t, and u are used for deleting any of the ten cell phone numbers. if you want to delete the 7th cell phone number simply write r and press enter.

Erase all cell phone numbers:

The command y is used to erase all the stored cell phone numbers.

Display all the cell phone numbers:

The command z is used to display all the cell phone numbers stored in the Arduino EEPROM.

So now you know how to use the simulation.

 

Arduino EEPROM

After you run the simulation, it will display all the stored cell phone numbers. currently, no cell number is stored. Let’s say I want to store my cell number under number7.

Arduino EEPROM

I simply entered g on the keyboard, or you can write the letter g in the android cell phone application and press enter, in replay you will be asked to enter your cell phone number. As you can see I wrote my number, the Arduino replied with number saved. Now to check if the number is saved you can write the letter z to display all the numbers.

Arduino EEPROM

As you can see my number is stored in the Arduino’s EEPROM which will remain in the memory no matter if I turn off the Arduino.

You can try all the commands.

Now you can make an advanced level Security system and use multiple numbers. So when an intruder is detected the same message is sent on multiple cell phone numbers, you can update any number.

 Let me know in the comment if you find this tutorial helpful?  For more tutorials you can subscribe to my Website and my YouTube channel “Electronic Clinic”.

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply