An every X-days alarm/output, suggestions?

I'm using TimeAlarms.h for daily event scheduling, but from what I can see Timealarms.h doesn't go beyond a daily alarm event, unless I use seconds, like 172,800 seconds for 2 days.

Does anyone have any suggestions for an every X-Days timer, 2-day, 4-day, etc. ? Would using seconds with timealarms.h consum any more resources than another long-duration library?

I'll be testing for odd/even day(), by adding an If statement in a daily alarm, then disallow the daily alarm of Odd, etc.. This doesn't help my every second, third, etc. day...

Derive the julian day number (JDN) from the date: Condition "JDN % 2 == 0" is true every second day Condition "JDN % 3 == 0" is true every third day Condition "JDN % 4 == 0" is true every fourth day etc

An similar version for the JDN calculation is also part of our RTC Arduino lib: (void DS1307new::calculate_cdn(void))



I have my RTC timing project designed around the libraries RTClib.h, Time.h, and TimeAlarms.h, and its working great. It has 1-2 daily timed events now working. But I need to add a couple of events evrey X-days.

So, it looks like the DS1307new.h library is also aware of Daylight Saving Time, the 'isMEZSummerTime'. True?

So, it looks like the DS1307new.h library is also aware of Daylight Saving Time, the 'isMEZSummerTime'. True?

Yes, but only the European rule is implemented here.


You could also divide now() by the number of seconds of the day (86400) to get a sort of absolute day since ever (1/1/1970)

(now()/8640)%2==0 //gives true if today is even
(now()/8640)%3==0 // true every third day

In my case, I allocated an int counter for this, set up an alarm to every day 6am and increment the counter at the alarm. Every time the counter hits %x==0 I would reset the counter and perform the actions I need every x days. For an every other day case, I used a simple bool type. This way I can easily see how many days are left to my event occur and alter it by external interfaces, e.g. telnet server.

Off-topic: Just finished my first arduino project and filled a UNO flash memory! This is great guys, great forum and great platform! In this one I used the ethernet shield to get the time via Network Time Protocol (ntp), set up alarms to water my herbs (nothing illegal hehe) every other day, set up alarms to post temperature and soil moisture via http POST requests, a telnet server responds to basic commands such as get temperature, get moisture, set watering interval. I have a 12v water pump that is turned on via relays during the watering interval. Hope to blog the project soon!

Sounds like a cool project, well done. The Arduino playground is thebest place to show off your work.