This comprehensive guide to Arduino Nano I2C EEPROM programming has been refined for technical accuracy and clarity. I have updated all internal links to the ee-diary.net domain and corrected the memory unit terminology (addressing the common confusion between kilobits and kilobytes).
const int writeBTN = 9;
const int readBTN = 8;
const int debounceDelay = 50;
const byte EEPROM_ADDR = 0x50; // Address with A0-A2 grounded
char myMessage[50] = {"This text was saved in EEPROM memory."};
char MEM[50];
void setup() {
Serial.begin(9600);
Wire.begin();
pinMode(writeBTN, INPUT_PULLUP);
pinMode(readBTN, INPUT_PULLUP);
}
void loop() {
if(!debounce(writeBTN)){
Serial.println(F("\nWriting to Ext. EEPROM..."));
for(unsigned int i=0; i < sizeof(myMessage); i++){
writeEEPROM(i, myMessage[i]);
}
Serial.println(F("Write Complete"));
}
if(!debounce(readBTN)){
Serial.println(F("\nReading Ext. EEPROM..."));
for (unsigned int j = 0; j < sizeof(MEM); j++){
MEM[j] = readEEPROM(j);
}
Serial.println(F("Read Complete. Content:"));
Serial.println(MEM);
}
}
void writeEEPROM(unsigned int address, byte data){
Wire.beginTransmission(EEPROM_ADDR);
Wire.write((int)highByte(address)); // Send MSB of address
Wire.write((int)lowByte(address)); // Send LSB of address
Wire.write(data);
Wire.endTransmission();
delay(5); // Essential 5ms write cycle delay
}
byte readEEPROM(unsigned int address){
byte data = 0xFF;
Wire.beginTransmission(EEPROM_ADDR);
Wire.write((int)highByte(address));
Wire.write((int)lowByte(address));
Wire.endTransmission();
Wire.requestFrom(EEPROM_ADDR, (byte)1);
if(Wire.available()) data = Wire.read();
return data;
}
boolean debounce(int pin){
boolean state;
boolean previousState = digitalRead(pin);
for(int counter=0; counter < debounceDelay; counter++){
delay(1);
state = digitalRead(pin);
if(state != previousState){
counter = 0;
previousState = state;
}
}
return state;
}
Code Explanation
Debouncing: Critical for push buttons to prevent multiple triggers from a single press. See our Arduino Debounce Code tutorial for a deeper look.
Write Cycle Delay: The delay(5) in writeEEPROM is mandatory. EEPROMs require time to internally move data from the buffer to the non-volatile cells.
Addressing: We manually split the 16-bit address into two bytes because I2C sends data in 8-bit increments. For more details on this logic, see How to Read/Write External EEPROM.
Demonstration Video
Conclusion and Further Reading
Expanding your Arduino Nano's memory opens the door to complex IoT and data-logging projects. Once you have mastered basic I2C communication, you can move on to:
Arduino Nano I2C LCD Interfacing
Logging Sensor Data to I2C EEPROM
Using I2C EEPROM with NodeMCU (ESP8266)
I2C remains the most efficient protocol for adding modular functionality to pin-limited microcontrollers like the Nano.
In this tutorial, we demonstrate how to interface an Arduino Nano with an external I2C EEPROM. While the Arduino Nano (ATmega328P) contains 1KB of internal EEPROM, this space is often insufficient for data-heavy applications like data logging or storing large look-up tables. By using the Microchip 24LC256, we can expand our non-volatile storage significantly.
Technical Note: The 24LC256 is a 256-Kilobit EEPROM, which equates to 32 Kilobytes (32,768 bytes) of storage. This is 32 times the internal storage of the Nano. Hardware Interfacing and Circuit Diagram To demonstrate the read/write process, we use two push buttons: Write Button: When pressed, a predefined string is stored in the EEPROM. Read Button: When pressed, the stored data is retrieved and displayed on the Serial Monitor. The circuit includes 10kΩ pull-up resistors for the I2C bus (SDA and SCL) to ensure reliable communication. Understanding the 24LC256 Pinout The 24LC256 comes in a standard 8-pin DIP package. Understanding the pins is crucial for correct addressing: A0, A1, A2 (Pins 1-3): Address inputs. Grounding all three sets the I2C address to 0x50. SDA / SCL (Pins 5-6): Serial Data and Clock lines. Connected to Nano pins A4 (SDA) and A5 (SCL). WP (Pin 7): Write Protect. Must be connected to GND to enable write operations. VCC / GND (Pins 8, 4): Power supply (typically 5V for Nano projects). Arduino Nano Code: I2C Read/Write Implementation This code utilizes the Wire.h library. Note the use of highByte() and lowByte() to send the 16-bit memory address over the 8-bit I2C bus. C++ #include