Skip to content

SetAlarms.ino

Arnd edited this page Dec 12, 2020 · 2 revisions

Sample Arduino sketch to demonstrate setting, reading and calibrating an attached DS3231M real time clock and alarms. The DS3231M comes in a SO16 or SO8 package but is also available as an Adafruit Breakout board. The chip does not require external components such as oscillators/crystals and the associated capacitors.

Sample circuit

The image below shows the breadboard layout that I used for this sample program.

Program Overview

The sketch has been tested on Arduino Micro and ATMega 2560 and uses the serial port at 115200 baud. It starts off by initializing the serial interface and instantiates and initializes the DS3231M with the date/time that the library was pre-compiled (note that this might be earlier than when the sketch was compiled, which can lead to confusion). The sketch makes use of the sprintf() function to print out the date/time since this function allows formatting leading zeroes, which the Serial.print() function does not.

The program outputs the date/time to the display every second and sets the alarm to go off in 12 seconds after starting. Once the alarm goes off a message is displayed and the alarm is set to go off again in 12 seconds.

Clone this wiki locally