How can we get a timer interrupt at a specific time or date?

For example: I want to make a project with an Uno and I'm using sleep mode and the wake-up source is timer2, as per the ATMega328p datasheet.

I want to turn on an LED, for example every day at 3pm, and the chip is in sleep mode on other times of the day.

So, how can I set the timer?

I think I have to use CTC mode of timer2 and set the OCR amount but I'm not sure how to do it.

There's a project on (Link) this link on the Arduino site that is perfect for this project, but when I compile it, it gives me an error saying that it can't be compiled for the Uno.

enter image description here

  • 1
    Use an RTC chip. The Arduino timers have no concept of real time, only relative time, and that usually over very short periods.
    – Majenko
    Mar 25 '20 at 15:52
  • 1
    Incidentally, that project uses an RTC that is built in to some of the more advanced (ARM) chips.
    – Majenko
    Mar 25 '20 at 15:54
  • 16.38 ms is the longest period you can get out of Timer 2. And 4.19 s is the longest you can get out of any timer of the Uno. Dec 22 '20 at 16:25

Your Answer

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

Browse other questions tagged or ask your own question.