Consider the following Arduino code that writes and then reads a byte from EEPROM address 10. What will be printed on the Serial Monitor?
#include <EEPROM.h> void setup() { Serial.begin(9600); EEPROM.write(10, 42); byte val = EEPROM.read(10); Serial.println(val); } void loop() {}
EEPROM.write stores a byte at the given address, and EEPROM.read retrieves it.
The code writes the value 42 to EEPROM address 10, then reads it back and prints it. So the output is 42.
What is the size of the EEPROM memory available on a standard Arduino Uno board?
Check the Arduino Uno specifications for EEPROM size.
The Arduino Uno has 1024 bytes of EEPROM memory available for storing data.
The following code is intended to update the EEPROM value at address 5 to 100, but the stored value never changes. What is the problem?
#include <EEPROM.h> void setup() { Serial.begin(9600); byte current = EEPROM.read(5); if (current != 100) { EEPROM.update(5, 100); } Serial.println(EEPROM.read(5)); } void loop() {}
EEPROM.update only writes if the new value differs from the stored one to reduce wear.
EEPROM.update checks if the new value differs before writing to avoid unnecessary wear. If the value is already 100, it won't write again.
What error will this Arduino code produce when compiled?
#include <EEPROM.h> void setup() { EEPROM.write(1024, 123); } void loop() {}
EEPROM size limits valid addresses.
The Arduino Uno EEPROM size is 1024 bytes, so address 1024 is out of range. This causes a runtime error or unexpected behavior.
You want to save a struct with multiple settings to EEPROM and read it back. Which code snippet correctly stores and retrieves the struct?
struct Settings {
int volume;
bool enabled;
};
Settings settings = {10, true};
void saveSettings() {
// ???
}
void loadSettings() {
// ???
}EEPROM.put and EEPROM.get handle complex data types like structs.
EEPROM.put writes the entire struct to EEPROM starting at the given address. EEPROM.get reads it back. EEPROM.write and EEPROM.read only handle single bytes.