EEPROM Read Values


Let’s take the following code and look at its output to the serial. On one hand, we have millis() assigned to time and it is printing out to the serial monitor every second give or a take some milliseconds. On the other hand, that millis() int value is being written via EEPROM to memory address 0, but reading EEPROM at address 0 outputs a different value to the serial monitor than what is expected. Why is this so?

#include <EEPROM.h>
int time; 
void setup()

void loop()

millis() returns an unsigned long of raw hex data. You are capturing it using an int. So two bytes are lost. Then storing that as a byte. Another byte is lost. Then sending that as data that the serial monitors shows as a character.

Look at and see if the truncated result you are seeing makes sense.

Read and write with the standard EEPROM.h is limited to byte values.

Check out EEPROMWriteAnything at

Your variable "time" which picks up millis() should be declared as an unsigned long.

Thanks. I understand now. :)