AndreasVan:
Now, it's time for testing...
The first test run stops after 4 hours. It was a battery problem. Now I have to check the Check battery consumption...
The code I posted is not for battery operated devices, but for Arduinos with an AC power adapter.
Battery operated Arduino boards provide some difficulties caused by high power consumption.
A big difficulty is, that hardly any ready-to-use Arduino board is really well fitted for battery operation.
Most Arduino boards draw something like 47mA current (i.e. "UNO"), while just about 17 mA are drawn by the Atmega controller and 30 mA are used by the rest of the on-board components like power regulator, USB serial adapter and last but not least the power-on LED which is always on when the board is powered.
So the problem is: If you use some sleepmode to power-down the controller, you'd be able to just save the 17 mA of the controller in power-down mode, but the 30 mA power consumption for the rest of the board will keep going.
First thing you'd have to find is a circuit or a Arduino board, that can operate your Atmega as well as the RTC and the SD card modules, which NOT has continous power consumption of several milliamperes.
Then you could try to operate a battery powered data logger most of the time in power-down mode.
An Atmega328 in power-down mode draws less than 1µA
A DHT22 sensor in power-down draws less than 30µA
A RTC should also be less than 50 µA, same with SD card controller while powered down.
Operating times of 1000, 2000, 4000, 8000 hours and batteries are only possible using
- circuits that can be set into a power-down mode using much less than 1mA standby current
- operating the circuit in power-down mode most of the time
- waking up the system only for very short "active time" operation
Are you bound to battery operation?
Is there no house nearby where you can plug in an AC power adapter to provide 5V voltage for your Arduino?
In former years the "Arduino Mini 05" board had been a good choice for battery operated projects. But I think nowadays it is hard to find and the last ones are sold grossly overpriced, so I'd look out for a different solution if I'd need battery a operated device.