## Experiment: GPS Data Logger
Store GPS data in UNO R3's EEPROM for later retrieval.
**Background:** UNO R3 UNO has 1KB EEPROM (1024 bytes). Each record uses ~14 bytes (struct size), allowing ~73 records.
**Required Hardware:** Same as before.
**Wiring:** Same.
**Code:**
```cpp
#include
#include
#include
#include
#define RX 2
#define TX 3
#define GPS_BAUD 9600
#define FREQUENCY 5000 // Record every 5 seconds
SoftwareSerial ss(RX, TX);
TinyGPSPlus gps;
struct GPSRecord {
uint8_t hour;
uint8_t minute;
float latitude;
float longitude;
float altitude;
};
GPSRecord gpsRecord;
int maxRecords = 0;
int gpsRecordLength = 0;
int gpsRecordCount = 0;
void printGPSRecord(GPSRecord rec) {
Serial.print(rec.hour);
Serial.print(":");
Serial.print(rec.minute);
Serial.print(", latitude: ");
Serial.print(rec.latitude, 2);
Serial.print(", longitude: ");
Serial.print(rec.longitude, 2);
Serial.print(", altitude: ");
Serial.println(rec.altitude, 2);
}
void saveGPSRecord() {
int address = gpsRecordCount * gpsRecordLength;
EEPROM.put(address, gpsRecord);
gpsRecordCount++;
if (gpsRecordCount > maxRecords - 1) {
gpsRecordCount = 0; // Overwrite from start
}
}
void setup() {
Serial.begin(9600);
ss.begin(GPS_BAUD);
delay(5000);
gpsRecordLength = sizeof(GPSRecord);
Serial.println("GPS Record Length: " + String(gpsRecordLength));
maxRecords = EEPROM.length() / gpsRecordLength;
Serial.println("Max Records in EEPROM: " + String(maxRecords));
}
void loop() {
static unsigned long lastRecordTime = 0;
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
if (gps.location.isValid() && gps.altitude.isValid() && gps.time.isValid()) {
if (millis() - lastRecordTime > FREQUENCY) {
gpsRecord.hour = gps.time.hour();
gpsRecord.minute = gps.time.minute();
gpsRecord.latitude = gps.location.lat();
gpsRecord.longitude = gps.location.lng();
gpsRecord.altitude = gps.altitude.meters();
saveGPSRecord();
printGPSRecord(gpsRecord);
lastRecordTime = millis();
}
}
}
}
}
```
**Code Explanation:**
- `struct GPSRecord`: Defines data format.
- `EEPROM.put()`/`get()`: Stores/retrieves data.
- Overwrites when full.
**Results:** Logs position every 5 seconds; view in Serial Monitor.

**Tips:** For larger storage, use SD card modules. EEPROM has ~100,000 write cycles limit.
**Related Information:** Consider SPIFFS on ESP32 for file-based logging.
- Choosing a selection results in a full page refresh.