EEPROM lets your Arduino save information even when it is turned off. This is useful for keeping settings or data that you want to remember later.
You want to save user preferences like brightness or volume.
You need to keep track of scores or progress in a game.
You want to store calibration data for sensors.
You want to remember the last state of a device after power loss.
Syntax
Arduino
#include <EEPROM.h>
EEPROM.write(address, value); // Save a byte
byte val = EEPROM.read(address); // Read a byte
Address is the location in EEPROM memory (0 to 1023 on many Arduinos).
Value is a byte (0-255) to store.
Examples
This saves the number 123 at EEPROM address 0.
Arduino
#include <EEPROM.h>
void setup() {
EEPROM.write(0, 123); // Save 123 at address 0
}
void loop() {}
This reads the saved value from address 0 and prints it.
Arduino
#include <EEPROM.h>
void setup() {
Serial.begin(9600);
byte val = EEPROM.read(0); // Read value from address 0
Serial.println(val); // Print the saved value
}
void loop() {}
Sample Program
This program saves the number 42 in EEPROM at address 10, then reads it back and prints it to the Serial Monitor.
Arduino
#include <EEPROM.h>
void setup() {
Serial.begin(9600);
// Save a setting
EEPROM.write(10, 42); // Store 42 at address 10
delay(1000); // Wait a bit
// Read the setting back
byte setting = EEPROM.read(10);
Serial.print("Stored setting: ");
Serial.println(setting);
}
void loop() {
// Nothing here
}
OutputSuccess
Important Notes
EEPROM can only store bytes (0-255). For bigger data, you need to split it into bytes.
EEPROM has a limited number of writes (about 100,000), so avoid writing too often.
Always check your Arduino model's EEPROM size to avoid writing outside its range.
Summary
EEPROM stores data that stays saved even when power is off.
Use EEPROM.write() to save and EEPROM.read() to get data.
Good for saving settings, scores, or calibration data.
Practice
(1/5)
1. What is the main purpose of using EEPROM in an Arduino program?
easy
A. To increase the speed of the program
B. To store data permanently even when the power is off
C. To connect to the internet
D. To control the brightness of an LED
Solution
Step 1: Understand EEPROM functionality
EEPROM memory keeps data saved even if the Arduino loses power.
Step 2: Compare options with EEPROM purpose
Only To store data permanently even when the power is off describes permanent data storage, which matches EEPROM use.
Final Answer:
To store data permanently even when the power is off -> Option B
Quick Check:
EEPROM stores permanent data = A [OK]
Hint: EEPROM saves data without power loss [OK]
Common Mistakes:
Confusing EEPROM with RAM (temporary memory)
Thinking EEPROM speeds up the program
Mixing EEPROM with internet or LED control
2. Which of the following is the correct syntax to write the value 42 to EEPROM address 10?
easy
A. EEPROM.save(42, 10);
B. EEPROM.read(10, 42);
C. EEPROM.write(10, 42);
D. EEPROM.store(10, 42);
Solution
Step 1: Recall EEPROM write syntax
The correct function to save data is EEPROM.write(address, value);.
Step 2: Match syntax with options
Only EEPROM.write(10, 42); uses EEPROM.write with correct parameter order.
Final Answer:
EEPROM.write(10, 42); -> Option C
Quick Check:
Write uses EEPROM.write(address, value) = D [OK]
Hint: Use EEPROM.write(address, value) to save data [OK]
Common Mistakes:
Using EEPROM.read() to write data
Using non-existent functions like EEPROM.store()
Swapping address and value parameters
3. What will be the output of this Arduino code snippet?
EEPROM.write(5, 100);
int val = EEPROM.read(5);
Serial.println(val);
medium
A. Error
B. 0
C. 5
D. 100
Solution
Step 1: Understand EEPROM write and read
The code writes 100 to address 5, then reads from address 5.
Step 2: Predict Serial output
Reading address 5 returns 100, so Serial.println prints 100.
Final Answer:
100 -> Option D
Quick Check:
Write 100, read 100 = A [OK]
Hint: Read returns last written value at address [OK]
Common Mistakes:
Expecting read to return address instead of value
Confusing EEPROM.read() with EEPROM.write()
Assuming default value 0 without write
4. Identify the error in this code that tries to save a setting to EEPROM:
int setting = 25;
EEPROM.read(0, setting);
medium
A. Using EEPROM.read() instead of EEPROM.write() to save data