Ds3231 alarm when date match

Hi everyone!
I want to alarm my arduino evrery month's 31st with ds3231. What happen if this month has 30 days? Will it not alarm in this month?

For the alarm to trigger, the values you set up must match. So something you've set up for the 31 day will not go off unless the day is 31.

So it won't happen in the months of 30 only days.

But try it and see! Set the clock to a test time and date and watch what happens when midnight strikes. Midnight that becomes the 1st of the next month, then try a few seconds before a midnight date that would become the 31st day of the current month.


1 Like

Okay, thanks for the answer.

I'd expect proper library wont let you set alarm on invalid date

The alarm registers on the DS3231 only allow you to store seconds, minutes, hours, and either the day of the month(1-31) or the day of the week (1-7), so there is no way for it to internally adjust for the last day of the month. If you want an alarm on the last day of the month, presumably your code would need to set the day of the month properly.

int days_in_month (int y, int m) {
  // Fourth, eleventh, ninth, and sixth,
  // thirty days to each we fix. 
  if ((m==4)||(m==11)||(m==9)||(m==6)) return 30; 
  // Every other, thirty-one,
  // except the second month alone,
  if (m!=2) return 31;
  // which hath twenty-eight, in fine,
  // till leap-year give it twenty-nine.
  if ((y%400)==0) return 29; // leap year
  if ((y%100)==0) return 28; // not a leap year
  if ((y%4)==0)   return 29; // leap year
  return 28; // not a leap year 
1 Like

Please explain what you actually want to do.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.