Arduino sleep for 2 hours !

I want to program an arduino to read a signal then it goes for sleep mode for 2 hours! (where it has to do nothing) and then wakes up again and take reading and so on. I thought about using Timer 1 which has its largest cycle of about 4 seconds and keep repeating this in a for loop to get 2 hours. However, this seems for me a very non practical solution. So any suggestions to help? Thanks in advance

I would guess a simple counter and delay(1000) should work.

unsigned long counter = 0;
setup() {
  //read sensor
 // go to sleep
}
loop(){
counter ++;
if(counter >= (2*60*60)) {  // 2 hours
   counter = 0;
   // wake up
   // read sensor
  // go to sleep
}

delay(1000);
}

It all depends on how accurate the two hours has to be. It is possible to use the watchdog timer to wake the processor approximately every eight seconds, but the timer can be wildly inaccurate, so hitting exactly two hour's worth of eight second delays can't be guaranteed.

mistegreen: thanks for reply. I think your method could work if counter increases every 1 second. But this is not the case!

AWOL: It all depends on how accurate the two hours has to be. It is possible to use the watchdog timer to wake the processor approximately every eight seconds, but the timer can be wildly inaccurate, so hitting exactly two hour's worth of eight second delays can't be guaranteed.

So do you have any other alternative approach? I mean: what is the common approach people always use in such a situation where you need to have a sleep mode for a long period?

I would use a real time clock like DS3231, set alarm to generate interrupt signal at 2 o'clock, wake up Arduino which resets RTC to 00:00 then does the task and goes back to sleep. https://www.adafruit.com/products/3013 You can get these much cheaper on Amazon or E-Bay but I trust Adafruit.

I would not use any external hardware to Wake up your board every two hours which doesn’t need to be a very precise timing. Use timer chaining and Wake up from sleep on any interrupt, even an empty interrupt like :

ISR (PCINT1_vect) { }

See this Application Note AVR 133: Long Delay Generation Using
the AVR Microcontroller:

http://www.atmel.com/Images/doc1268.pdf

Edit : See Nick Gammon Tutorial for AVR Timers:

https://www.gammon.com.au/timers

ard_newbie: See this Application Note AVR 133: Long Delay Generation Using the AVR Microcontroller:

http://www.atmel.com/Images/doc1268.pdf

That is really useful, thanks!. One point is missing for me, I read that AVR is the processor for arduino board (am I correct?). If so, if i have an arduino uno board, how can I cascade the two yimers as mentioned in the paper?