Introduction
Your Arduino has some Random Access Memory (RAM) that you can use for storing and reading variables. However there is a limitation, if the power to the Arduino is turned off anything stored in RAM is lost. Often this doesn't matter but sometimes it's very important. Take for example a person counter in a art gallery. It's important to keep an accurate count of the total people that have visited the gallery, it would be unacceptable if the counter reset to zero every time the Ardunio power was switched off or reset.
Fortunately there is another area of memory on an Arduino called EEPROM (Electrically Erasable Programmable Read-Only Memory). This can be written to by your Arduino program and will be saved when the Arduino is switched off or reset.
There are two EEPROM functions that you use, EEPROM.write and EEPROM.read
- First make sure the EEPROM on your adruino is clear by following this tutorial
Tips
The EEPROM in your Arduino is rated by the manufacturer for 100,000 writes, so be aware that you can't write too often.
In reality it can last for more than that to over 1,000,000 writes.