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.
Right
#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
← Previous
Arduino EEPROM.read Returns 255 — Complete Guide
Next →
Arduino Ethernet.begin Fails to Get IP
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro