record runtime for a motor...

Hi

I have a small project for controlling a water pump.
For each time the pump starts or stops, it calls a webpage sending some data to be logged in a sql database... Here I can do some calculating of runtime...
But i want to print it in the display as well... So trying to use millis() to record the runtime, and store it in EEPROM each time the pump stops. It starts and stops maximum every other day, so i'm not worried about wearing out the eeprom...

But cant get my head around recording the millis for each action...

if (pumpstate) {
    if (!lowpinstate && !highpinstate) { 
      pumpstate = 0; 
    }
  } else {
    if (highpinstate && lowpinstate) { 
      pumpstate = 1; 
    }
  }
if (pumpstate == 1){
    digitalWrite(pump, HIGH);
    lcd.setCursor(0,0);
    lcd.print("Pump ON ");
    delay(100);
  } else {
    digitalWrite(pump, LOW);
    lcd.setCursor(0,0);
    lcd.print("Pump OFF");
  }

bengtdg:
But cant get my head around recording the millis for each action...

The code snippets you have posted make no attempt to use millis().

I reckon you need to save the value of millis() to a variable when the pump starts and again (to a different variable) when the pump stops. Then you need to calculate how long the pump was running - something like this

pumpRunTime = pumpStopTime - pumpStartTime;

and save the value of pumpRunTime to the EEPROM

As you are working over a long period of time if you just save the values of millis() to the EEPROM at start and stop you will probably run into confusion when millis() rolls over.

...R

The run time will only be a few hours. But it can go several days between each run.

bengtdg:
The run time will only be a few hours. But it can go several days between each run.

That's what I had in mind when I wrote Reply #1

...R

Thanx alot...:slight_smile:

It was a simple solution... but i got stuck... thats why there was noe millis in the first code...:slight_smile:

Got it working...:slight_smile:

Bengt