RTC Sleep Example with a SAMD Board

This example demonstrate how to use the RTC library methods in order to wake up from the standby mode.

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 Sleep RTC Alarm for Arduino Zero
4
5 Demonstrates the use an alarm to wake up an Arduino zero from Standby mode
6
7 This example code is in the public domain
8
9 http://arduino.cchttps://www.arduino.cc/en/Tutorial/SleepRTCAlarm
10
11 created by Arturo Guadalupi
12
13 17 Nov 2015
14
15 modified
16
17 01 Mar 2016
18
19
20
21 NOTE:
22
23 If you use this sketch with a MKR1000 you will see no output on the serial monitor.
24
25 This happens because the USB clock is stopped so it the USB connection is stopped too.
26
27 **To see again the USB port you have to double tap on the reset button!**
28
29*/
30
31#include <RTCZero.h>
32
33/* Create an rtc object */
34
35RTCZero rtc;
36
37/* Change these values to set the current initial time */
38
39const byte seconds = 0;
40
41const byte minutes = 00;
42
43const byte hours = 17;
44
45/* Change these values to set the current initial date */
46
47const byte day = 17;
48
49const byte month = 11;
50
51const byte year = 15;
52
53void setup()
54{
55
56 pinMode(LED_BUILTIN, OUTPUT);
57
58 digitalWrite(LED_BUILTIN, LOW);
59
60 rtc.begin();
61
62 rtc.setTime(hours, minutes, seconds);
63
64 rtc.setDate(day, month, year);
65
66 rtc.setAlarmTime(17, 00, 10);
67
68 rtc.enableAlarm(rtc.MATCH_HHMMSS);
69
70 rtc.attachInterrupt(alarmMatch);
71
72 rtc.standbyMode();
73}
74
75void loop()
76{
77
78 rtc.standbyMode(); // Sleep until next alarm match
79}
80
81void alarmMatch()
82{
83
84 digitalWrite(LED_BUILTIN, HIGH);
85}

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.