I have very little experience with the Arduino and am hoping that you may provide me with some helpful info.

I would like to build a device that records time spent on a project. I envision the main Uno with a switch, microSD breakout, and an LED to indicate its tracking your time. When setup the user could simply press the switch/button (light up the LED to show you're "working") and while you plug away on your day job the Uno will track the time between switch on and switch off. Then at the time the switch is turned off, have the Uno write a simple data file containing the total time spent on that activity.

I have a basic idea of what I need hardware wise, but am hoping to find insight to the backbone of software programming to make something like this begin to take shape.

  • Use an RTC and record a start time and an end time (timestamp) for each job. This will give better quality raw data that is easy to use, and flexible, for calculations and reporting.
    – Dampmaskin
    Jul 12 '16 at 21:14
  • If you can live with an accuracy of only ~ 0.5%, then you don't need an RTC, millis() is fine. For more precise timekeeping, you do want the RTC. Jul 13 '16 at 9:36

There are two ways of doing this:

  1. Using a Real Time Clock (RTC) chip, which you connect to your Arduino.
  2. Using the millis() function of the Arduino.

Needless to say, they aren't completely the same in efficiency. An RTC is a dedicated chip for measuring time and is incredibly accurate. The millis() is not as accurate, but still pretty accurate.

So, it really depends on how accurate you want it to be. You can make millis() more accurate through code, which isn't something difficult. But an RTC always works fine and is always more accurate, if only by milliseconds. In general: need to time long durations, an RCT is probably better.

Regardless of the method you will use, you can convert the data into the desired format so it can be read easily when looking at the files on the SD card. So, for example: you can write code that simply checks how many hours fit in the saved time data, and after that you can check the minutes and even after that you can check for the last seconds. For this you're going to need modulo.

Here are some resources you might want to check out:

  • Your link about millis() inaccuracy is way out of date. The 9.54 hours rollover issue was solved in 2008. Jul 13 '16 at 9:34
  • Well, good to know because that basically means millis() is almost as accurate as an RTC without needing to correct it with code.
    – Len
    Jul 13 '16 at 10:05
  • That depends on the Arduino. Many of them, like the Uno, are clocked off a ceramic resonator, not nearly as accurate as the quartz you have in a typical RTC. Jul 13 '16 at 10:50
  • Yep. So if OP is going to be using it for long periods of time, he's definitely better off using an RTC.
    – Len
    Jul 13 '16 at 14:11
  • Thank you guys, this is all very helpful!! I don't need extreme accuracy for this application - only looking to deal in nearest tenths of an hour (0.1 or every six minutes) so the millis will probably work for me. Happy to hear its nearly as simple as my brain is saying it should be :)
    – JoeP
    Jul 13 '16 at 20:29

An RTC is a dedicated chip for measuring time and is incredibly accurate.

its accuracy will depend on the crystals used. a temperature controlled one will be very accurate. But a regular one will just be as accurate as the crystal used, like a mcu.

The millis() is not as accurate, but still pretty accurate.

stock millis() undercounts. however, that undercounting can be mitigated via code. for long durations, the undercounting can be practically (but not completely) eliminated.

  • 1
    stock millis() undercounts”. Do you have some evidence to back this? Sep 9 '17 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.