Bird
Raised Fist0
Arduinoprogramming~20 mins

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

Choose your learning style10 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).

Practice

(1/5)
1. What does EEPROM.write(address, value) do in Arduino?
easy
A. Stores a byte value at the specified EEPROM address
B. Reads a byte value from the specified EEPROM address
C. Deletes all data from EEPROM
D. Initializes the EEPROM memory

Solution

  1. Step 1: Understand EEPROM.write function

    The function EEPROM.write(address, value) saves a byte value at the given address in EEPROM memory.
  2. Step 2: Differentiate from EEPROM.read

    EEPROM.read(address) is used to read data, not write it.
  3. Final Answer:

    Stores a byte value at the specified EEPROM address -> Option A
  4. Quick Check:

    EEPROM.write saves data [OK]
Hint: Write saves data, read retrieves data from EEPROM [OK]
Common Mistakes:
  • Confusing write with read function
  • Thinking EEPROM.write clears memory
  • Assuming EEPROM.write initializes EEPROM
2. Which of the following is the correct syntax to read a byte from EEPROM at address 10?
easy
A. EEPROM.get(10);
B. EEPROM.write(10);
C. EEPROM.readByte(10);
D. EEPROM.read(10);

Solution

  1. Step 1: Identify correct EEPROM read syntax

    The correct function to read a byte from EEPROM is EEPROM.read(address).
  2. Step 2: Check options for exact match

    Only EEPROM.read(10); matches the correct syntax.
  3. Final Answer:

    EEPROM.read(10); -> Option D
  4. Quick Check:

    EEPROM.read(address) reads byte [OK]
Hint: Use EEPROM.read(address) to get stored byte [OK]
Common Mistakes:
  • Using EEPROM.write to read data
  • Using non-existent EEPROM.readByte function
  • Confusing EEPROM.get with EEPROM.read
3. What will be the output of this Arduino code snippet?
EEPROM.write(5, 42);
byte val = EEPROM.read(5);
Serial.println(val);
medium
A. 0
B. 42
C. 5
D. Undefined behavior

Solution

  1. Step 1: Write value 42 at EEPROM address 5

    The code stores the byte 42 at address 5 using EEPROM.write(5, 42);.
  2. Step 2: Read the value back from address 5

    EEPROM.read(5) reads the stored value, which is 42.
  3. Final Answer:

    42 -> Option B
  4. Quick Check:

    Write 42, read 42 [OK]
Hint: Write then read same address returns stored value [OK]
Common Mistakes:
  • Assuming EEPROM.read returns address instead of value
  • Forgetting to write before reading
  • Expecting default 0 without writing
4. Identify the error in this code snippet:
EEPROM.write(1024, 100);
byte val = EEPROM.read(1024);
Serial.println(val);
medium
A. Serial.println cannot print byte values
B. EEPROM.write requires two arguments
C. Address 1024 is out of EEPROM range
D. EEPROM.read cannot be assigned to byte

Solution

  1. Step 1: Check EEPROM address range

    Typical Arduino EEPROM size is 1024 bytes, so address 1024 is out of range (valid addresses are 0-1023).
  2. Step 2: Validate other code parts

    EEPROM.write has correct arguments, EEPROM.read returns byte, and Serial.println can print bytes.
  3. Final Answer:

    Address 1024 is out of EEPROM range -> Option C
  4. Quick Check:

    EEPROM address must be within 0-1023 [OK]
Hint: EEPROM addresses start at 0, max 1023 on typical boards [OK]
Common Mistakes:
  • Using address equal to EEPROM size
  • Assuming EEPROM size is larger than actual
  • Misunderstanding Serial.println capabilities
5. You want to store a user's high score (an integer between 0 and 1000) in EEPROM. Which approach correctly saves and reads this value?
hard
A. Use EEPROM.put(address, highScore); and EEPROM.get(address, highScore);
B. Use EEPROM.write(address, highScore); and EEPROM.read(address);
C. Use EEPROM.write(address, highScore % 256); only
D. Use EEPROM.read(address); to save and EEPROM.write(address, highScore); to read

Solution

  1. Step 1: Understand data size and EEPROM functions

    High score is an integer (2 bytes), so EEPROM.write (1 byte) is insufficient to store full value.
  2. Step 2: Use EEPROM.put and EEPROM.get for multi-byte data

    EEPROM.put(address, highScore); saves the entire integer, and EEPROM.get(address, highScore); reads it back correctly.
  3. Final Answer:

    Use EEPROM.put(address, highScore); and EEPROM.get(address, highScore); -> Option A
  4. Quick Check:

    Use put/get for multi-byte data [OK]
Hint: Use EEPROM.put/get for integers, write/read for bytes [OK]
Common Mistakes:
  • Using EEPROM.write for multi-byte integers
  • Not reading back with EEPROM.get
  • Mixing read and write roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard