0
0
Arduinoprogramming~10 mins

EEPROM read and write in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - EEPROM read and write
Start
Write data to EEPROM
Read data from EEPROM
Use or display data
End
This flow shows writing data to EEPROM, then reading it back to use or display.
Execution Sample
Arduino
#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  EEPROM.write(0, 42);
  int val = EEPROM.read(0);
  Serial.println(val);
}

void loop() {}
Writes 42 to EEPROM address 0, reads it back, and prints it to serial.
Execution Table
StepActionAddressValue WrittenValue ReadOutput
1Write to EEPROM042
2Read from EEPROM042
3Print value42
4EndExecution stops
💡 Program ends after printing the EEPROM value.
Variable Tracker
VariableStartAfter WriteAfter ReadFinal
EEPROM[0]unknown424242
valundefinedundefined4242
Key Moments - 3 Insights
Why do we write to EEPROM before reading?
Because EEPROM stores data persistently, we must write data first to have something to read back, as shown in steps 1 and 2 of the execution table.
What happens if we read from an EEPROM address that was never written?
The value read may be random or default (often 255), since EEPROM memory retains old or default data until written, as implied by the initial 'unknown' state in variable_tracker.
Why do we use Serial.begin before printing?
Serial.begin initializes communication with the computer so Serial.println can send data, which is necessary before printing the value in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what value is read from EEPROM at step 2?
Aundefined
B0
C42
D255
💡 Hint
Check the 'Value Read' column at step 2 in the execution_table.
At which step does the program print the EEPROM value?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Output' column in the execution_table to find when printing happens.
If we change EEPROM.write(0, 100), what will be printed at step 3?
A100
B0
C42
Dundefined
💡 Hint
Refer to variable_tracker and execution_table to see how written value affects read and output.
Concept Snapshot
EEPROM.write(address, value) stores a byte persistently.
EEPROM.read(address) retrieves the stored byte.
Always write before reading to get valid data.
Use Serial.begin() before printing.
EEPROM retains data after power off.
Full Transcript
This example shows how Arduino EEPROM memory can store data permanently. First, the program writes the number 42 to EEPROM address 0. Then it reads back the value from the same address. Finally, it prints the value to the serial monitor. The execution table traces each step: writing, reading, and printing. The variable tracker shows how EEPROM[0] changes from unknown to 42, and how the variable val holds the read value. Key moments clarify why writing must happen before reading and why serial communication must start before printing. The quiz tests understanding of these steps and how changing the written value affects output.