Simple RTC Alarm with a SAMD Board

This example demonstrate how to use the RTC library methods in order to do something when an alarm is matched.

This example demonstrate how to use the RTC library methods in order to do something when an alarm is matched. In particular in this example, the RTC time is set at 16:00:00 and an alarm at 16:00:10. When the time match using the match type

MATCH_HHMMSS
is reached, the attached interrupt function will print on the serial monitor Alarm Match!.

Hardware Required

Circuit

Only your Arduino Board is needed for this example.

The circuit for this example.
The circuit for this example.

Code

1/*
2
3 Simple RTC Alarm for Arduino Zero and MKR1000
4
5 Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000
6
7 This example code is in the public domain
8
9 http://arduino.cchttps://www.arduino.cc/en/Tutorial/SimpleRTCAlarm
10
11 created by Arturo Guadalupi <a.guadalupi@arduino.cc>
12
13 25 Sept 2015
14
15
16
17 modified
18
19 21 Oct 2015
20
21*/
22
23#include <RTCZero.h>
24
25/* Create an rtc object */
26
27RTCZero rtc;
28
29/* Change these values to set the current initial time */
30
31const byte seconds = 0;
32
33const byte minutes = 0;
34
35const byte hours = 16;
36
37/* Change these values to set the current initial date */
38
39const byte day = 25;
40
41const byte month = 9;
42
43const byte year = 15;
44
45void setup()
46{
47
48 Serial.begin(9600);
49
50 rtc.begin(); // initialize RTC 24H format
51
52 rtc.setTime(hours, minutes, seconds);
53
54 rtc.setDate(day, month, year);
55
56 rtc.setAlarmTime(16, 0, 10);
57
58 rtc.enableAlarm(rtc.MATCH_HHMMSS);
59
60
61
62 rtc.attachInterrupt(alarmMatch);
63}
64
65void loop()
66{
67
68}
69
70void alarmMatch()
71{
72
73 Serial.println("Alarm Match!");
74}

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.