Save run time to eeprom on uno r3 /atmega328p mini for a robot car on display can anyone help me?


currently i am doing a project to count time from a motor and display on monitor

my question is using arduino can we count the idle time and run time of the motor or machine, The run time and idle time should be displayed on monitor,

#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t EEPROMaddresss =1;

void setup() {
while (!Serial) {}

void loop() {
String readableTime;
// readableTime =;

// Serial.println(readableTime);

void getReadableTime(String &readableTime) {
unsigned long currentMillis;
byte seconds;
byte minutes;
byte hours;
byte days;

currentMillis = millis();
seconds = currentMillis / 1000;
minutes = seconds / 60;
hours = minutes / 60;
currentMillis %= 1000;
seconds %= 60;
minutes %= 60;
hours %= 24;

if (hours > 0) {
readableTime += String(hours) + ":";

if (minutes < 10) {
readableTime += "0";
readableTime += String(minutes) + ":";

if (seconds < 10) {
readableTime += "0";
readableTime += String(seconds) ;
// EEPROM.write(EEPROMaddress,readableTime);



You can't write a String to EEPROM like that, nor can I tell why you'd want to.
Keep a uint32_t for the number of seconds of runtime, and use put and get functions for the EEPROM.
Watch out for the write/erase limit for the EEPROM.

Please remember to use code tags when posting code

okay, can tell me how i should write a string to save to eeprom?

Sorry for me bad English *can you please tell me how i can write a string to EEPROM?

Internet search on the words "arduino write string to eeprom" produces a result set.

... but be careful, because a string and a String are not the same thing.

But, as I said, I can't see why you'd want to write either, when a simple integer type would suffice.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.