How to use Clear Eeprom sktech on a Mega

Eh, OK, this might be a bit weird question, but I just don't know / understand. In the example section, I fiend the EEPROM-CLEAR sketch. I want to use that to clear the EEPROM (really?) of my Arduino Mega. Do I need to alter the sketch anywhere to tell it the Mega's EEPROM size, or does it work on any Arduino regardless of EEPROM size?



Hello HugoW
Check length by:


The console shows:

17:06:32.242 -> 4096

Have a nice day and enjoy coding in C++.

I assume that you realise that the EEPROM will still contain the value that you write to it, but at least you will know what that value is

Hi @HugoW. Do you mean this example?:

If so, as paulpaulson explained, EEPROM.length() returns the size of the EEPROM for the board you are using, so that for loop at line 29 automatically adjusts to iterate over the entire EEPROM of any board you run the program on:

for (int i = 0 ; i < EEPROM.length() ; i++) {

So the answer is that no alterations are needed.

@paulpaulson ; thanks, no alterations it is. My question answered.
@UKHeliBob ; thanks, yes, I know. I want to be sure the Mega 'forgets' what is on there, now.

Thanks all,


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.