Skip to content

Arduino EEPROM Clear Not Working

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about Arduino EEPROM Clear Not Working. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Trying to clear (reset) EEPROM does not produce all 0xFF values.

Quick Fix

Wrong

for (int i = 0; i < 1024; i++) {
  EEPROM.write(i, 0);  // Writes 0, not the erased state
}
EEPROM reads all zeros, not 0xFF (the factory erase state).
#include <EEPROM.h>

void clearEEPROM() {
  for (int i = 0; i < EEPROM.length(); i++) {
    EEPROM.write(i, 0xFF);  // FF is the factory-erased state
  }
  Serial.println("EEPROM cleared to 0xFF");
}

void setup() {
  Serial.begin(9600);
  clearEEPROM();
  // Verify
  if (EEPROM.read(0) == 0xFF) {
    Serial.println("Byte 0 is 0xFF — cleared");
  }
}
EEPROM cleared to 0xFF
Byte 0 is 0xFF — cleared

Prevention

Factory-erased EEPROM reads as 0xFF, not 0x00. To clear, write 0xFF to every byte. Writing 0 to all bytes produces a different default state. Use EEPROM.length() to get the total size (1024 on Uno). Clearing all 1024 bytes takes ~3.4 seconds (3.3 ms per write).

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is the erased state of EEPROM?

All bytes are 0xFF after Factory erase. Some programmers have an option to fill with 0x00 instead. Check your chip datasheet.

Does clearing reduce EEPROM life?

Yes. Writing all 1024 bytes consumes one write cycle on each byte. Clearing more than 100,000 times will wear out the EEPROM.

Can I clear specific addresses only?

Yes. Just write 0xFF to the addresses you want to reset. No need to clear the entire EEPROM.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro