0
0
Arduinoprogramming~10 mins

EEPROM for storing settings in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - EEPROM for storing settings
Start Program
Initialize EEPROM
Read Settings from EEPROM
Use Settings in Program
Modify Settings?
NoContinue Running
Yes
Write New Settings to EEPROM
End or Loop Back
The program starts, reads settings from EEPROM, uses them, optionally updates and writes back new settings, then continues running.
Execution Sample
Arduino
#include <EEPROM.h>

int brightness = 0;

void setup() {
  brightness = EEPROM.read(0);
}

void loop() {
  // Use brightness
}
This code reads a brightness setting from EEPROM address 0 during setup and uses it in the loop.
Execution Table
StepActionEEPROM AddressValue Read/WrittenVariable StateNotes
1Start Program---Program begins execution
2Initialize EEPROM---EEPROM library ready
3Read brightness from EEPROM050brightness = 50Read stored brightness value 50
4Use brightness in program--brightness = 50Brightness used for LED or display
5Modify brightness?---User changes brightness to 100
6Write new brightness to EEPROM0100brightness = 100New brightness saved to EEPROM
7Continue running--brightness = 100Program runs with updated brightness
8End or loop---Program loops or ends
💡 Program runs continuously; EEPROM read/write happens only when settings change.
Variable Tracker
VariableStartAfter Step 3After Step 6Final
brightness0 (default)50 (read from EEPROM)100 (updated and written)100
Key Moments - 3 Insights
Why do we read from EEPROM in setup() and not in loop()?
Reading in setup() happens once at start, saving time and EEPROM wear. The execution_table row 3 shows reading brightness only once.
What happens if we write to EEPROM every loop without checking?
EEPROM has limited write cycles. Writing every loop (not shown here) would wear it out quickly. The table shows writing only when brightness changes (row 6).
Why do we store settings at a specific EEPROM address?
Each setting needs a unique address to avoid overwriting. Here brightness is stored at address 0 (rows 3 and 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of brightness after step 3?
A100
B0
C50
DUndefined
💡 Hint
Check the 'Variable State' column at step 3 in the execution_table.
At which step is the new brightness value written to EEPROM?
AStep 4
BStep 6
CStep 3
DStep 2
💡 Hint
Look for the action 'Write new brightness to EEPROM' in the execution_table.
If the brightness never changes, how would the execution_table change?
AStep 6 would be skipped
BStep 3 would be skipped
CStep 5 would be 'Yes'
DStep 7 would not happen
💡 Hint
Refer to the 'Modify brightness?' decision at step 5 and the write action at step 6.
Concept Snapshot
EEPROM stores data permanently on Arduino.
Use EEPROM.read(address) to get a byte.
Use EEPROM.write(address, value) to save a byte.
Read settings once in setup(), write only when changed.
Each setting uses a unique EEPROM address.
Avoid frequent writes to protect EEPROM life.
Full Transcript
This visual execution shows how Arduino programs use EEPROM to store settings like brightness. The program starts and initializes EEPROM. It reads the brightness value from EEPROM address 0 once during setup. This value is stored in the variable brightness and used in the program loop. If the user changes brightness, the program writes the new value back to EEPROM at the same address. This prevents losing settings after power off. Writing only happens when settings change to avoid wearing out EEPROM memory. Each step shows the action, EEPROM address accessed, value read or written, and the current variable state. This helps beginners see exactly when and how EEPROM is used to save and load settings.