0
0
Arduinoprogramming~20 mins

EEPROM read and write in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
EEPROM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this EEPROM write and read code?

Consider the following Arduino code that writes a value to EEPROM and then reads it back. What will be printed on the Serial Monitor?

Arduino
 #include <EEPROM.h>

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

void loop() {}
A123
B0
C255
DCompilation error
Attempts:
2 left
💡 Hint

EEPROM.write stores a byte at the given address, and EEPROM.read retrieves it.

Predict Output
intermediate
2:00remaining
What value is stored after this EEPROM update code?

This code uses EEPROM.update to write a value. What value will be stored at address 5 after running this code?

Arduino
 #include <EEPROM.h>

void setup() {
  EEPROM.write(5, 50);
  EEPROM.update(5, 50);
  EEPROM.update(5, 100);
}

void loop() {}
A0
B100
C50
DCompilation error
Attempts:
2 left
💡 Hint

EEPROM.update only writes if the new value differs from the stored one.

🔧 Debug
advanced
2:00remaining
Why does this EEPROM read code print wrong values?

The code below tries to read an int from EEPROM but prints unexpected values. What is the main reason?

Arduino
 #include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  int val = EEPROM.read(0) + (EEPROM.read(1) << 8);
  Serial.println(val);
}

void loop() {}
AEEPROM.read returns bytes, but int needs two bytes combined correctly
BEEPROM.read returns signed values causing wrong results
CThe code should use EEPROM.get to read an int instead of manual byte combination
DEEPROM.read can only read one byte, so reading two addresses is invalid
Attempts:
2 left
💡 Hint

Think about how to read multi-byte data types from EEPROM safely.

📝 Syntax
advanced
2:00remaining
Which option causes a compilation error in EEPROM write code?

Which of these code snippets will cause a compilation error?

AEEPROM.write(10, 100);
BEEPROM.write(10, 'A');
CEEPROM.write(10, 0xFF);
DEEPROM.write(10, 256);
Attempts:
2 left
💡 Hint

EEPROM.write expects a byte value (0-255).

🚀 Application
expert
2:00remaining
How many bytes are written by this EEPROM.put call?

Given the struct and EEPROM.put code below, how many bytes are written to EEPROM?

Arduino
 #include <EEPROM.h>

struct Data {
  int a;
  byte b;
  float c;
};

void setup() {
  Data d = {100, 5, 3.14};
  EEPROM.put(20, d);
}

void loop() {}
A7 bytes
B9 bytes
C8 bytes
D10 bytes
Attempts:
2 left
💡 Hint

Consider the size of each data type on Arduino Uno (int=2 bytes, byte=1 byte, float=4 bytes).