0

I would like to use the DS1302, as a count up timer. My goal is to have the arduino time the amount of me driving my car. So it DS1302 will be used a count-up timer ie accumulate time. however when the car is switched off, I don't want to lose the value, and when I use my car again I would like to the time to continue accumulating. The resolution can be in minutes, as this will probably be the best.

I would like something like an odometer of a car, except its going to be the time, instead of distance.

Q: Can this be done with the DS1302 Module? and also how can I do this? Is there a sample code for a count-up timer?

  • The Arduino can do the whole task by itself well enough. – Russell McMahon Jun 16 '15 at 2:06
  • In theory yes, but in practice it's become unreliable. – 3kstc Jun 16 '15 at 2:14
  • 1
    In practice the DS1302 is unreliable - as noted on the page you reference. Perhaps starting with "My Arduino does not time things as well as it should be perfectly able to - here is what I have tried in adequate detail - any ideas?" question may be a good start. Adding known bad hardware to a bad software or hardware issue may not help. || Arduino needs to be powered on when car is off OR stay on long enough to save data to non volatile memory. Either should be "easy enough". – Russell McMahon Jun 16 '15 at 2:17
  • "I don't want to lose the value" -> store it in non-volatile memory before shutting down the Arduino or in regular intervals -> e.g. EEPROM -> look for questions how to do this on this site / google. – fuenfundachtzig Jun 16 '15 at 8:05
  • What's the maximum time you want to record? Days, months or years? – Ricardo Jun 16 '15 at 13:21
2

Do you mean only accumulate during powered/driving, or also during standing still?

If the former, just get the start time in setup, then in loop continuously get the time and calculate the difference between it and the time read in setup. Since you don't know when power is lost you need to continually write the elapsed time to some form of non-volatile memory. You could use the Arduinos EEPROM, but that can wear out over time. It's better the use the DS1302s 31 byte of battery backed RAM. Next time the arduino starts up you need to read out this value and add this to the difference.

In case of the latter, you can halt the DS1302 so it stops incrementing time.

  • I'm only after the time the keys are on the ignition, I don't care if they're sitting my car and listening to the radio or driving on the freeway, I'm just after the time the car is 'on'. Q: Is there any alternative methods in obtaining this data/statistics? – 3kstc Jun 16 '15 at 23:18
  • In that case use the first part of my answer. If you don't mind a bit less accuracy, you can even drop the DS1302 entirely. Just use the arduino millis function for tracking time. The crystal on the arduino is not that accurate, but you can measure the inaccuracy and account for this in code. You can probably get to less than 1 minute of drift per day. – Gerben Jun 17 '15 at 11:54
1

What you're describing is the equivalent of a digital Hobbs hour meters. You can read up about them if your are interested. The old ones (not digital in today's sense) clicked an odometer-like movement every 0.1 hours (typically). I don't think you need a real-time clock module as long as you're not interested in when you drove the car, but only in the accumulated duration.

A simple way would be a 1-minute delay loop that increments a counter and writes it to EEPROM. The EEPROM has a write-endurance spec of 100,000 writes, equivalent to over 800 hours, used this way. You'll lose the last fraction of a minute, whether it's a few seconds or nearly a while minute, whenever you shut down the Arduino. There are ways around this, if it matters, but that's an "exercise left for to the reader" as my textbooks used to say. Clock your micro with a crystal, not with its internal resonator, for best accuracy.

  • When I rent out my car, I already have an analogue gauge for reference, The only way of seeing it would be physically being next to the car. I want the arduino to sms (gsm shield) me the hours every so often (every 8 minutes). Q: Do you know if the digital hobbs hour meter can be tapped into by the Arduino? – 3kstc Jun 16 '15 at 23:13
  • I've no idea, but wouldn't it be much simpler to let the Arduino do the whole job - timing + communication? I didn't mean to suggest you should install a Hobbs meter; just that you might get some ideas by reading about them. I think an AVR chip and the GSM module would probably do just what you want. – JRobert Jun 16 '15 at 23:40
  • The comms are at a later stage -I just want to do the timing at the moment. You might be right, letting the Arduino do all the work might be easier. – 3kstc Jun 16 '15 at 23:44

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.