Keep track of time while arduino asleep, questions on different ideas

Hello,

The project I am working on is basically a lamp that is powered by a battery. There is a manual swithch to turn On/Off the light and the trick is that the device should be activated only for 24 hours and if the voltage is higher that a treshold. When the activation time is over, it can be reactivated by USART connection. There are actually other features, but for simplicity, we can keep it to the simple lamp configuration.

To do that I use an arduino nano with the switch on pin D2 and the LED on D10. I don't give all the hardware details because I think it is not usefull for my question, but i can give you more details if you want. The battery is a 3.4V LFP with 6000 mAh capacity.

So the challenge is to diminish the arduino consumption to allow the LED to work for the longest time possible (at the moment, light can be emit for 10 hours and if not used, the device use the whole battery after ~4 days). An other important point is the precision of the activated time. For 24 hours, a +/- 10min would be okay, but not more.

To lower the consumption, I started reading the topic about Power on gammon.com. Seeing that the microcontroller has no work to do for long period (no one will use the lamp to make a manual stroboscope for hours I guess), put the arduino to sleep seems to be a good option to me. I would also try other ideas from Gammon i think, but I started with the sleep. I have also already check a lot on the forum for this topic and found some good answers for previous issues, but I reach a point where a I am stucked even with what I have found.

Below I present the 3 main steps I tried with my conclusion for each of them:

  1. Firstly, I have used the Power-Down mode with a PinInterrupt on the switch (D2) and a Watchdog to have a voltage check every 8 seconds and keep track of activated time. But two main drawback occurs : Firstly the watchdog is not precise enough and secondly, we decided that USART communication for the activation of the device should be instantaneous. To solve the USART problem, I have tried option 2.

  2. I have used the IDLE mode using power_all_disable() + power_usart0_enable() (to maximize power saving) and keep the 8s watchdog for the moment. It works pretty well to wakeup the arduino as soon as something was sent by USART. But again watchdog is not precise enough, which lead to next option.

  3. To have a more precise track of time, I decided to keep Timer0 enabled to use millis(). The problem is that the device wake up every millisecond due to the Timer0 interrupt. Which is not really usefull to have a proper sleep.

After this introduction, which I hope is clear and present correctly what I have already tried, here are my questions :

  1. Is it possible to deactivated the timer0 interrupt only (so keep the Pin ans WDT interrupt) while being able to use millis() ? and if so, how ?

  2. If answer to question 1 is negative, I immagine that I would have to use an external RTC. I check for available RTC, and many have a battery backup and are quite expensive. Seeing that I don't want any other battery than the main one and keep the electronic system as cheap as possible (less than 1$ for extra RTC device), I saw that the brand Microchip seems to make some RTC that would suit my requirements. Do you thing it is a good idea to try one of those ? I found some project using them, but if you have some good examples, I would be glad to see them !

If you have any other ideas, feel free to make sugestions ! Just keep in mind that any options with a supplementary battery or that is more than 1$ are not an option, and that a maximum of +/-10 min out of 24h is necessary !

Hope it was clear and thanks in advance for your help ! if you need any information, I will be pleased to give you more details.

Manuel

m_pi:
If you have any other ideas, feel free to make suggestions ! Just keep in mind that any options with a supplementary battery or that is more than 1$ are not an option, and that a maximum of +/-10 min out of 24h is necessary !

Hmmm. I was going to suggest a DS1307!

That chip says DS1302 on it. I see similar DS1307 modules, some as low as $1.16 for two! Check whether they include the battery or not. Note that I do not endorse buying electronics on e-bay, too many counterfeit/bad part stories out there.

I prefer the DS3231. You should compare specs.

RTC are generally low cost, and if your just making one device, I dont see why you would have an artifical limit of $1 to add to the cost.

Surely, within reason, the actual added cost is not significant ?

Yes the DS3231 keeps time much better.

hammy:
Yes the DS3231 keeps time much better.

Indeed it does, but it does not fall within the OP's budget specification and he specifically states that such accuracy is not required. Otherwise do you not think I would have suggested it?

Engineering - as Henry Ford is reputed to have based his business - is "horses for courses".

The ATmega chips can use a 32 kHz crystal and Timer2 to make an RTC, which works in most of the sleep modes.

Examples are posted on the forum.

Thanks all for your sugestions !

Paul is right, the requirements I gave are mandatory for the final project, even if it seems absurd to you at the moment, sorry.

So I will probably try both solutions, the "RTC chip + Crystal" and the "Timer2 + Crystal". If someone is interested, I will post what I end up with !