Arduino Uno - Wifi Engine Hour Meter

Hi all,

I would like to keep track of the engine run time hours of a Generator/Genset.

To do that I would like to use an Arduino Uno and an ESP8266 WiFi Module to keep track of the engine hour meters. When the generator is switched on the Arduino must also be switched on and start running simple code to keep track of the run time in hours. So in other words, for as long as the Arduino receives electrical power from the generator it should keep track of the run time in hours.

It should store the run time every 5 minutes on the EEPROM. When the generator is switched off and then back on again the Arduino should retreive the previously stored hour reading and continue counting the run time hours for as long as the generator is running.

The WIFI Module should send the latest hour reading of the generator to a self made Website every hour of generator uptime, or when in range of internet WIFI.

Can anyone assist me with this project and give advise on how to connect the hardware components with each other and with the generator, as well as with the programming code?

Thank you in advance for your time and assistance. Much appreciated.

Kind regards.

Pierre

so,
wifi to read when the motor is running
send data periodically to .....
if you have WiFi , why not just have the ESP log the file and host the website ?

now the 'when in range of WiFi' becomes an issue.
if you want to know your car engine running time and when you pull into your garage, where you have your WiFi that has your SSID and your password.... then you could do that.

most guest WiFi require activity on your part to agree to terms or some such.

if you have 10 places, home, work, store, garage, shop, friends home, other store... where you already have the SSID and password, you can have it automatically link and send data.

you could have your ESP host it's website and you would use your phone to access and get the data anytime you are near the unit.

next question is are you looking for a running total as the only value ?
are you looking for an hourly log?

@dave-in-nj, it is not a car

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

As @dave-in-nj has suggested, an ESP32 will be able to do all of your requirements on one controller board.

Also using myDevices, Cayenne or Thingspeak dashboards you will have access to info from any platform, even be able to control the generator, and monitor any parameters, voltage, current, oil pressure, temperature.

Tom... :slight_smile:

Juraj:
@dave-in-nj, it is not a car

the analogy is that if you have a thing, that you take from place to place.
a temperature/humidity sensor.
we had a guy asking about tracking wine shipments.....
it could travel past dozens of WiFi hot-spots, but without a password and they were not accessible.
I was just trying to point out that some thought is needed.

Pierre_Swanepoel_94:
It should store the run time every 5 minutes on the EEPROM.

If I remember correctly, each EEPROM cell is only good for 100000 writes.
So, if you always write the time to the same EEPROM location, that is 100000 times 5 minutes, or about 8333 hours. After that, the EEPROM might continue to work... or it might not.

You will need to learn about wear leveling. I'm not sure about how to do it properly myself, but it sounds like what you need.

As for the actual timekeeping itself (not the EEPROM stuff), this code should work.
It shows the total runtime on a 16x2 LCD display. Or, at least, it should if I haven't made a mistake somewhere. I have not actually tested this code, so it might have bugs in it. (I modified it from something else I once had, which I know worked properly. But I do not know if it will still work properly after these modifications.)

#include <LiquidCrystal.h>

// declare and initialize variables
byte totalMyriads  = 0; // myriads of hours (1 myriad = 10000)
byte totalHundreds = 0; // hundreds of hours
byte totalHours    = 0; // hours, from 0 to 99
byte totalMinutes  = 0; // "minutes" part of total
byte totalSeconds  = 0; // "seconds" part of total
unsigned long microsAtLastSecond = 0UL; // value of micros() at most recent 1/10 second

// a pretty important constant
const unsigned long MICROS_PER_SECOND = 1000000UL; // number of microseconds per second

// here we specify what pins our LCD is on
//                RS  EN  D4  D5  D6  D7
LiquidCrystal lcd(12, 11,  5,  4,  3,  2);

void setup() {
 
  // start the LCD going
  lcd.begin(16, 2);
 
  // display the time (which at this point will be all zeros)
  updateTimeDisplay();
 
}

void loop() {
 
  // check if it is time for the clock to advance
  if ((micros() - microsAtLastSecond) >= MICROS_PER_SECOND) {
   
    // make the clock advance 1 second
    totalSeconds++;
   
    // make sure that the next advance happens exactly when it is due
    // (they should happen exactly at 1-second intervals)
    microsAtLastTenth += MICROS_PER_TENTH;
   
    // our clock needs to do more than count seconds
    // it also needs to count minutes, hours, hundreds, and myriads
    // so let's go ahead and do that

    // too many seconds?
    if (totalSeconds >= 60) {
      // trade 60 seconds for 1 minute
      totalSeconds -= 60;
      totalMinutes++;
    }
   
    // too many minutes?
    if (totalMinutes >= 60) {
      // trade 60 minutes for 1 hour
      totalMinutes -= 60;
      totalHours++;
    }
   
    // too many hours?
    if (totalHours >= 100) {
      // trade 100 hours for 1 hundred
      totalHours -= 100;
      totalHundreds++;
    }
    
    // too many hundreds?
    if (totalHundreds >= 100) {
      // trade 100 hundreds for 1 myriad
      totalHundreds -= 100;
      totalMyriads++;
    }
   
    // update the display so we can see the new time
    updateTimeDisplay();
   
  }
 
}


void updateTimeDisplay () {
  // function to update the display to show the current elapsed time
  //
  // we want the display to look like this
  //   Position: 01234567890123456
  //     Line 0:       h  m  s 
  //     Line 1:   00000:00:00

  // declare a buffer for storing a string (we'll need it later)
  // we expect to need only 16 characters, but to be safe, let's make room for 20
  // so we allow 20 characters worth of room, plus 1 extra for the null terminator
  // (Always allow 1 character extra worth of room for the null terminator!)
  char buf[21];

  // move to the top line of the display
  lcd.setCursor(0,0);
 
  // show the units
  lcd.print("      h  m  s   ");
 
  // convert the elapsed time to a string
  // for myriads, allow 3 digits worth of room
  // for hundreds, hours, minutes, and seconds, allow 2 digits for each, and use leading zeros
  sprintf(buf,"%3d%02d%02d:%02d:%02d   ",totalMyriads,totalHundreds,totalHours,totalMinutes,totalSeconds);

  // move to the bottom line of the display 
  lcd.setCursor(0,1);
 
  // show the string for the elapsed time
  lcd.print(buf);
}