2

I want to know if it is possible to set an alarm in DS3231. I want to set the alarm every 6 AM in the morning. Is this possible?

2

Yes it is (see datasheet datasheet) ... the DS3231 has 2 alarms.

There is also a library for the Arduino, see: library. The alarm(s) can be set (repeatedly) via one of the following functions:

Alarm.alarmRepeat(hours, minutes, seconds, function); 
Create an alarm that will call a function every day at a particular time. 

Alarm.alarmRepeat(dayofweek, hours, minutes, seconds, function); 
Create an alarm that will call a function every week on a specific day at     
a particular time.

 "dayofweek" can be dowSunday, dowMonday, dowTuesday, dowWednesday,
 dowThursday, dowFriday, or dowSaturday. 

Detailed info and more functions: link

8
  • is it okay that i used the SDA SCL pins ? for ds3231 although I use the timelib.h and timealarm library? May 3 '17 at 13:11
  • I'm not sure, I never played with I2C so far, I see the DS3231 uses I2C, so I assume the library uses I2C to interact with the DS3231. Probably it needs to be connected via I2c (thus SDA/SCL). May 3 '17 at 13:16
  • When I try this ` Alarm.alarmRepeat(8,30,0, MorningAlarm); // 8:30am every day Alarm.alarmRepeat(17,45,0,EveningAlarm); // 5:45pm every day ` using the timelib.h and timerAlarm.h library , when i close the serial monitor it restart counting .. May 3 '17 at 13:25
  • What do you mean exactly with 'restarts counting' ? I assume when the alarm(s) set is equal to the time of the IC, the alarm callback function is fired. May 3 '17 at 13:29
  • In the TimeAlarmExample .. setTime(9,21,0,05,03,17); // set time to Saturday 8:29:00am Jan 1 2011 time is set to 8:29 am .. and then Alarm.alarmRepeat(8,30,0, MorningAlarm); // 8:30am every day when i close the serial monitor it restart counting back to 8:29 am .. May 3 '17 at 13:33
0

I find the answer to my question . I just add Time t; and t = rtc.getTime(); into my code then an if statement like this if (t.hour == 11 && t.min == 59 && t.sec == 00)

ref http://www.instructables.com/id/Setup-for-DS3231-AlarmTimer-Function/

1
  • The correct way to use RTC alarms is to setup them to fire an interrupt when alarm date/time occurs. This way MCU doesn't have to poll RTC frequently. The configuration is described in "Alarms" paragraph of the datasheet.
    – Flanker
    May 3 '17 at 16:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.