Skip to content

Arduino EEPROM.write Not Saving Data

DodaTech Updated 2026-06-26 1 min read

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

The Problem

Values written with EEPROM.write() are lost after power cycle.

Quick Fix

Wrong

EEPROM.write(0, 42);  // Called in loop too often, wears EEPROM
EEPROM wears out quickly or value lost due to frequent writes.
#include <EEPROM.h>

int lastVal = -1;

void saveValue(int val) {
  int addr = 0;
  if (val != lastVal) {  // Only write on change
    EEPROM.write(addr, val);
    lastVal = val;
    Serial.print("Saved: ");
    Serial.println(val);
  }
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensor = analogRead(A0) / 4;  // 0-255
  saveValue(sensor);
  delay(100);
}
Saved: 42  (only when value changes).

Prevention

Always check if the value changed before writing to EEPROM. A single EEPROM.write() takes ~3.3 ms on AVR (during which interrupts may be disabled). For multi-byte values, use EEPROM.put(). For frequently changing data, store in RAM and save to EEPROM periodically.

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

FAQ

### How long does EEPROM.write take?

~3.3 ms on AVR at 16 MHz. During this time, interrupts are disabled briefly. The function waits for the EEPROM program cycle to complete.

What is EEPROM endurance?

100,000 write cycles per byte. Writing every 100 ms would exhaust one byte in ~3 hours. Always minimize writes.

Can I write during loop() safely?

Yes, but avoid writing every iteration. Use a timer (millis()) to limit writes to once per minute or less for frequently changing data.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro