{"id":11013,"date":"2021-02-04T21:40:20","date_gmt":"2021-02-04T21:40:20","guid":{"rendered":"https:\/\/wolles-elektronikkiste.de\/?p=11013"},"modified":"2024-05-30T13:59:26","modified_gmt":"2024-05-30T13:59:26","slug":"ds3231-real-time-clock","status":"publish","type":"post","link":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock","title":{"rendered":"DS3231 &#8211; Real-time clock"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">About this post<\/h2>\n\n<p>In this article I would like to introduce the real-time clock module DS3231. For this, I use the <a href=\"https:\/\/github.com\/adafruit\/RTClib\" target=\"_blank\" rel=\"noopener\">RTCLib<\/a> library from Adafruit, as I think it is the best compromise of usability and completeness. <\/p>\r\n<p>With the help of example sketches I will introduce you step by step to the functions of the DS3231 and the library. Since I found the original example sketches a bit confusing, I modified them slightly and added my own.<\/p>\r\n<p>With the RTCLib, you can also control the alternative real-time clocks DS1307, PCF8523 and PCF8563. I will briefly deal with this at the end of this post. You can find a separate post about the DS1302, the DS1307, and the &#8220;Rtc by Makuna&#8221; library <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/ds1302-and-ds1307-rtc-real-time-clock\" target=\"_blank\" rel=\"noopener\">here<\/a>. <\/p>\r\n<p>As usual, I will first go a little further and introduce the features of the DS3231 module.<\/p>\r\n\n<h2 class=\"wp-block-heading\">What is a real-time clock?<\/h2>\n\n<p>In other words, is there also an &#8220;unreal-time clock&#8221;? Well, even the Arduino boards measure the time. You can use the <code>millis()<\/code> function to query the time in milliseconds that has elapsed since the program was started. However, the Arduino does not know the time or the date. Real-time clocks, on the other hand, have registers that store the date and time. In addition, they are battery-powered and therefore do not &#8220;forget&#8221; this data. These features turn them into real-time clocks.<\/p>\r\n\n<h2 class=\"wp-block-heading\">The DS3231 module<\/h2>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-1024x364.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"364\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-1024x364.jpg\" alt=\"DS3231 module, front and back\" class=\"wp-image-10952\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-1024x364.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-300x107.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-768x273.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-1536x545.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-2048x727.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds3231_front_back_small_2-1320x469.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">DS3231 module, front and back<\/figcaption><\/figure>\n\n<p>The DS3231 in a narrower sense is the large IC with the 16 pins, which can be easily recognized on the board. A data sheet about it can be found <a href=\"https:\/\/datasheets.maximintegrated.com\/en\/ds\/DS3231.pdf\" target=\"_blank\" rel=\"noopener\">here<\/a>. In this article, however, I always refer to the module, even if I speak of the DS3231 in short form.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Technical features of the DS3231 <\/h3>\n\n<p>The most important features in my view are:<\/p>\r\n<ul>\r\n<li><strong>Counts<\/strong> seconds, minutes, hours, days, days of the week, months, years.\r\n<ul>\r\n<li>Including <strong>leap year function.<\/strong><\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><strong>Maximum deviation<\/strong> (at 0 to 40 \u00b0C): +\/-2 ppm (equivalent to +\/-63 seconds \/ year).<\/li>\r\n<li><strong>Power supply<\/strong>: 2.3 &#8211; 5.5 volts.<\/li>\r\n<li><strong>(Rechargeable) Battery<\/strong>: CR2032 \/LIR2032, <strong>built-in charging function<\/strong>\r\n<ul>\r\n<li>be careful when batteries (<strong>see note below!<\/strong>).<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><strong>Power consumption<\/strong> <strong>in VCC operation<\/strong> (own measurement):\r\n<ul>\r\n<li>at <strong>5 volts<\/strong>: 3.6 mA (with LED) \/ 0.64 mA (LED removed).<\/li>\r\n<li>at <strong>3.3 volts<\/strong>: 1.8 mA (with LED) \/ 0.36 mA (LED removed).<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><strong>Battery power consumption<\/strong>: 0.84 &#8211; 3.0 \u00b5A (timekeeping mode).<\/li>\r\n<li>Two programmable <strong>alarms with interrupt function.<\/strong><\/li>\r\n<li>Programmable output for <strong>square wave signals<\/strong> (I do not go into this in detail).<\/li>\r\n<li>Integrated <strong>temperature sensor<\/strong>, but with modest accuracy (+\/-3 \u00b0C)<strong>. <\/strong> <\/li>\r\n<li><strong>Communication<\/strong>: I2C, address: 0x68, integrated <strong>pull-up<\/strong> resistors.<\/li>\r\n<li><strong>Inputs\/outputs:<\/strong>\r\n<ul>\r\n<li>VCC \/ GND: Supply voltage<\/li>\r\n<li>SDA \/ SCL: I2C<\/li>\r\n<li>SQW: Output for <strong>sq<\/strong>uare <strong>w<\/strong>ave signals or low-active interrupt<\/li>\r\n<li>32K: Output for square wave signal with 32 kHz (fixed)<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n\n<h3 class=\"wp-block-heading\">Be careful using batteries<\/h3>\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/load_function.png\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"440\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/load_function.png\" alt=\"Charging function of the DS3231\" class=\"wp-image-10949\" style=\"width:326px;height:220px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/load_function.png 651w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/load_function-300x203.png 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/a><figcaption class=\"wp-element-caption\">Charging function of the DS3231<\/figcaption><\/figure>\n<\/div>\n<p>The DS3231 and other RTC modules have a charging circuit for LIR2032, i.e. rechargeable batteries. You can recognize this by the presence of a diode (see picture on the right). Many stores and deliver the module with a CR2032, i.e. a non-rechargeable button cell. This can be dangerous because the module still tries to charge the button cell. It can then inflate due to gas development, be destroyed and emit very unhealthy hydrofluoric acid in the process. <\/p>\r\n\r\n<p> Unfortunately, the charging circuit is also only suitable for LIR2032 batteries to a very limited extent. Typically, a LIR is charged with 4.2 V. At 5 volts supply voltage I measured 4.75 volts at the contacts of the battery holder. <\/p>\r\n<p> My recommendation: Remove the diode and \/ or the 200 Ohm resistor next to the diode when using a rechargeable or non-rechargeable button cell in parallel to an external power supply.\r\n<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-1024x340.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-1024x340.jpg\" alt=\"Battery vs. Battery\" class=\"wp-image-10955\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-1024x340.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-300x100.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-768x255.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-1536x511.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie-1320x439.jpg 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/akku_vs_battery-Kopie.jpg 2000w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Battery vs. Battery<\/figcaption><\/figure>\n\n<p>In case of doubt you can supply the DS3231 via VCC for testing and measure the voltage at the contacts of the battery holder.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Integrated EEPROM<\/h3>\n\n<p>You may have wondered what the small, eight-pin IC and the three address jumpers are all about. This IC is an EEPROM called AT24CS32. A data sheet can be found <a href=\"http:\/\/ww1.microchip.com\/downloads\/en\/devicedoc\/Atmel-8869-SEEPROM-AT24CS32-Datasheet.pdf\" target=\"_blank\" rel=\"noopener\">here<\/a>. The AT24CS32 has a capacity of 32 kBit. So you can store a lot of data on it. Together with the DS3231, for example, you could regularly record readings from a sensor. Or you can save events, e.g. the times when a motion detector triggers.<\/p>\r\n<p>Unlike the DS3231, you can modify the I2C address of the AT24CS32. If all jumpers are open, the address is 0x57. By closing jumpers you can set the addresses 0x50 to 0x56. If you want to check the addresses, you find an IC2 scanner <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/i2c-scanner\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\r\n<p>The RTCLib has not implemented any functions to use the EEPROM. I will therefore not go into any further detail.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Connection of the DS3231 to an Arduino UNO<\/h3>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231-1024x573.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"573\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231-1024x573.png\" alt=\"\" class=\"wp-image-10947\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231-1024x573.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231-300x168.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231-768x430.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/wiring_ds3231.png 1285w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The DS3231 connected to an Arduino UNO<\/figcaption><\/figure>\n\n<p>As you can see, the wiring is simple. Alternatively, you could connect VCC to 3.3 volts. But then charging the battery won&#8217;t work. Pull-ups for the I2C lines are not required. I use SQW as an interrupt output in some sketches.<\/p>\r\n\n<h2 class=\"wp-block-heading\">Installing the RTCLib for the DS3231<\/h2>\n\n<p>You can install the RTCLib (Adafruit) via the Arduino IDE Library Manager:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/RTCLib_selection.png\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/RTCLib_selection.png\" alt=\"Selection of RTCLib\" class=\"wp-image-10958\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/RTCLib_selection.png 786w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/RTCLib_selection-300x169.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/RTCLib_selection-768x433.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/a><figcaption class=\"wp-element-caption\">Selection of RTCLib<\/figcaption><\/figure>\n\n<p>Alternatively, download the library <a href=\"https:\/\/github.com\/adafruit\/RTClib\" target=\"_blank\" rel=\"noopener\">here<\/a> from GitHub.<\/p>\r\n<p>RTCLib requires another library called Adafruit BusIO. You can also find it via the library manager or <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BusIO\" target=\"_blank\" rel=\"noopener\">here<\/a> on GitHub.<\/p>\r\n\n<h2 class=\"wp-block-heading\">Introduction to RTCLib<\/h2>\n\n<p>As announced, I&#8217;ll explain the features of the RTCLib to you using a series of example sketches.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Setting and querying the time<\/h3>\n\n<p>Of course, when you use the DS3231 for the first time, it doesn&#8217;t know the current time and date. This is like any other watch that is not a radio clock. There are two ways to set it:<\/p>\r\n<ul>\r\n<li><code>rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));<\/code> conveniently uses the system time of your computer. However, this is the time when the sketch is compiled. Your clock will then be a few seconds past<\/li>\r\n<li><code>rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));<\/code> sets the date according to the scheme: year, month, day, hour, minute, second. Further below, I will show you how to set the time using this function via the serial monitor.<\/li>\r\n<\/ul>\r\n<p>For the definition of specific times (date and time of day) there is a useful class in the RTCLib called DateTime.<\/p>\r\n<ul>\r\n<li><code>DateTime now = rtc.now();<\/code> creates the object &#8220;now&#8221; of the DateTime class and assigns the current time to it with <code>rtc.now();<\/code>.<\/li>\r\n<\/ul>\r\n<p>Didactically, it may not be ideal to use the same name for the &#8220;now&#8221; object and the <code>now();<\/code> function. I copied that from the original example sketches.<\/p>\r\n<p>You access the years, months, days, hours, minutes and seconds of the DateTime object &#8220;now&#8221; with <code>now.year()<\/code>, <code>now.month();<\/code>, etc.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SetTime.ino\" data-enlighter-title=\"SetTime.ino\">#include \"RTClib.h\"\r\n\r\nRTC_DS3231 rtc;\r\n\r\nchar daysOfTheWeek[7][12] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"};\r\n\r\nvoid setup () {\r\n  Serial.begin(9600);\r\n\r\n#ifndef ESP8266\r\n  while (!Serial); \/\/ wait for serial port to connect. Needed for native USB\r\n#endif\r\n\r\n  if (! rtc.begin()) {\r\n    Serial.println(\"Couldn't find RTC\");\r\n    Serial.flush();\r\n    abort();\r\n  }\r\n\r\n    Serial.println(\"Setting the time...\");\r\n    \/\/ When time needs to be set on a new device, or after a power loss, the\r\n    \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n    \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n    \/\/ January 21, 2014 at 3am you would call:\r\n    \/\/ rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));\r\n  }\r\n\r\n\r\nvoid loop () {\r\n    DateTime now = rtc.now();\r\n\r\n    Serial.print(now.year(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(now.month(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(now.day(), DEC);\r\n    Serial.print(\" (\");\r\n    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);\r\n    Serial.print(\") \");\r\n    Serial.print(now.hour(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(now.minute(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(now.second(), DEC);\r\n    Serial.println();\r\n\r\n    Serial.println();\r\n    delay(3000);\r\n}<\/pre>\r\n<p> <\/p>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of SetTime.ino<\/h4>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_SetTime-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"384\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_SetTime-1.png\" alt=\"DS3231 Example sketch: Output of SetTime.ino\" class=\"wp-image-10917\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_SetTime-1.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_SetTime-1-300x135.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_SetTime-1-768x347.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of SetTime.ino<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">More functions for reading time and date<\/h3>\n\n<p>Now you&#8217;ll get to know a few more basic functions. With <code>rtc.lostPower();<\/code> you check whether the DS3231 was disconnected from the power. If this was the case, you can automatically re-set the time.<\/p>\r\n<p>The RTCLib allows you to comfortably calculate with dates and times. <code>TimeSpan(days, hours, minutes, seconds);<\/code> or <code>TimeSpan(seconds);<\/code> define a time period that you can add to or deduct from a date.<\/p>\r\n<p>Use <code>now.unixtime();<\/code> to get the seconds that have elapsed between the time &#8220;now&#8221; and 1\/1\/1970 (UTC). This so-called Unix time is often used as a reference. You can query the current Unix time <a href=\"https:\/\/time.is\/Unix\" target=\"_blank\" rel=\"noopener\">here<\/a> on the net. More information about the Unix time can be found <a href=\"https:\/\/de.wikipedia.org\/wiki\/Unixzeit\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\r\n<p>The temperature measured by the integrated sensor in degrees Celsius can be obtained with <code>rtc.getTemperature();<\/code>.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ds3231.ino\" data-enlighter-title=\"ds3231.ino\">\/\/ Date and time functions using a DS3231 RTC connected via I2C and Wire lib\r\n#include \"RTClib.h\"\r\n\r\nRTC_DS3231 rtc;\r\n\r\nchar daysOfTheWeek[7][12] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"};\r\n\r\nvoid setup () {\r\n  Serial.begin(9600);\r\n\r\n#ifndef ESP8266\r\n  while (!Serial); \/\/ wait for serial port to connect. Needed for native USB\r\n#endif\r\n\r\n  if (! rtc.begin()) {\r\n    Serial.println(\"Couldn't find RTC\");\r\n    Serial.flush();\r\n    abort();\r\n  }\r\n\r\n  if (rtc.lostPower()) {\r\n    Serial.println(\"RTC lost power, let's set the time!\");\r\n    \/\/ When time needs to be set on a new device, or after a power loss, the\r\n    \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n    \/\/ rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n    \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n    \/\/ January 21, 2014 at 3am you would call:\r\n    \/\/ rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));\r\n  }\r\n\r\n  \/\/ When time needs to be re-set on a previously configured device, the\r\n  \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n  \/\/ rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n  \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n  \/\/ January 21, 2014 at 3am you would call:\r\n  \/\/ rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));\r\n}\r\n\r\nvoid loop () {\r\n    DateTime now = rtc.now();\r\n\r\n    Serial.print(now.year(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(now.month(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(now.day(), DEC);\r\n    Serial.print(\" (\");\r\n    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);\r\n    Serial.print(\") \");\r\n    Serial.print(now.hour(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(now.minute(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(now.second(), DEC);\r\n    Serial.println();\r\n\r\n    Serial.print(\" since midnight 1\/1\/1970 = \");\r\n    Serial.print(now.unixtime());\r\n    Serial.print(\"s = \");\r\n    Serial.print(now.unixtime() \/ 86400L);\r\n    Serial.println(\"d\");\r\n\r\n    \/\/ calculate a date which is 7 days, 12 hours, 30 minutes, 6 seconds into the future\r\n    DateTime future (now + TimeSpan(7,12,30,6));\r\n\r\n    Serial.print(\" now + 7d + 12h + 30m + 6s: \");\r\n    Serial.print(future.year(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(future.month(), DEC);\r\n    Serial.print('\/');\r\n    Serial.print(future.day(), DEC);\r\n    Serial.print(' ');\r\n    Serial.print(future.hour(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(future.minute(), DEC);\r\n    Serial.print(':');\r\n    Serial.print(future.second(), DEC);\r\n    Serial.println();\r\n\r\n    Serial.print(\"Temperature: \");\r\n    Serial.print(rtc.getTemperature());\r\n    Serial.println(\" C\");\r\n\r\n    Serial.println();\r\n    delay(3000);\r\n}<\/pre>\r\n<p> <\/p>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of ds3231.ino<\/h4>\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"365\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231-1.png\" alt=\"Output of ds3231.ino\" class=\"wp-image-10919\" style=\"width:580px;height:248px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231-1.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231-1-300x129.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231-1-768x329.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of ds3231.ino<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">Formatting date and time conveniently<\/h3>\n\n<p>Perhaps it also bothered you that the last two sketches output the time without preceding zeros. A time formatted like 1:2:3 looks ugly. 01:02:03 would be better. With the RTCLib, you can easily do this and other formatting of the time and date. I think the principle becomes clear through the following example sketch and I don&#8217;t have to write anything more about it.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"toString.ino\" data-enlighter-title=\"toString.ino\">#include &lt;Wire.h&gt;\r\n#include &lt;RTClib.h&gt;\r\n\r\nRTC_DS1307 rtc;\r\n\r\n\r\nvoid setup () {\r\n  Serial.begin(9600);\r\n\r\n#ifndef ESP8266\r\n  while (!Serial); \/\/ wait for serial port to connect. Needed for native USB\r\n#endif\r\n\r\n  if (! rtc.begin()) {\r\n    Serial.println(\"Couldn't find RTC\");\r\n    Serial.flush();\r\n    abort();\r\n  }\r\n\r\n  if (! rtc.isrunning()) {\r\n    Serial.println(\"RTC is NOT running, let's set the time!\");\r\n    \/\/ When time needs to be set on a new device, or after a power loss, the\r\n    \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n    \/\/ rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n    \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n    \/\/ January 21, 2014 at 3am you would call:\r\n    \/\/ rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));\r\n  }\r\n\r\n  \/\/ When time needs to be re-set on a previously configured device, the\r\n  \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n  \/\/ rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n  \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n  \/\/ January 21, 2014 at 3am you would call:\r\n  \/\/ rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));\r\n}\r\n\r\nvoid loop() {\r\n\r\n   DateTime now = rtc.now();\r\n\r\n  \/\/buffer can be defined using following combinations:\r\n  \/\/hh - the hour with a leading zero (00 to 23)\r\n  \/\/mm - the minute with a leading zero (00 to 59)\r\n  \/\/ss - the whole second with a leading zero where applicable (00 to 59)\r\n  \/\/YYYY - the year as four digit number\r\n  \/\/YY - the year as two digit number (00-99)\r\n  \/\/MM - the month as number with a leading zero (01-12)\r\n  \/\/MMM - the abbreviated English month name ('Jan' to 'Dec')\r\n  \/\/DD - the day as number with a leading zero (01 to 31)\r\n  \/\/DDD - the abbreviated English day name ('Mon' to 'Sun')\r\n\r\n   char buf1[] = \"hh:mm\";\r\n   Serial.println(now.toString(buf1));\r\n\r\n   char buf2[] = \"YYMMDD-hh:mm:ss\";\r\n   Serial.println(now.toString(buf2));\r\n\r\n   char buf3[] = \"Today is DDD, MMM DD YYYY\";\r\n   Serial.println(now.toString(buf3));\r\n\r\n   char buf4[] = \"DD.MM.YYYY\";\r\n   Serial.println(now.toString(buf4));\r\n\r\n   char buf5[] = \"MM\/DD\/YYYY\";\r\n   Serial.println(now.toString(buf5));\r\n\r\n   Serial.println();\r\n\r\n   delay(2000);\r\n}<\/pre>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of toString.ino <\/h4>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_toString.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"349\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_toString.png\" alt=\"DS3231 Example sketch: Output of toString.ino\" class=\"wp-image-10930\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_toString.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_toString-300x123.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_toString-768x315.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of toString.ino<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">Setting the time via the serial monitor<\/h3>\n\n<p>Based on the functions presented so far, you can conveniently set the time via the serial monitor:<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"setTime.ino\" data-enlighter-title=\"setTime.ino\">#include \"RTClib.h\"\r\n\r\nRTC_DS3231 rtc;\r\n\r\nvoid setup () {\r\n  Serial.begin(9600);\r\n\r\n#ifndef ESP8266\r\n  while (!Serial); \/\/ wait for serial port to connect. Needed for native USB\r\n#endif\r\n\r\n  if (! rtc.begin()) {\r\n    Serial.println(\"Couldn't find RTC\");\r\n    Serial.flush();\r\n    abort();\r\n  }\r\n\r\n  if (rtc.lostPower()) {\r\n    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n  }\r\n  Serial.println(\"Enter the new time as hh:mm:ss\");\r\n}\r\n\r\nvoid loop () {\r\n  DateTime now = rtc.now();\r\n  static int currentSecond = 61; \/\/ currentSecond to be different from first nextSecond\r\n  int nextSecond = now.second();\r\n  \r\n  if(nextSecond != currentSecond){\r\n    char buf1[] = \"hh:mm:ss\";\r\n    Serial.println(now.toString(buf1));\r\n    currentSecond = nextSecond;\r\n  }\r\n\r\n  if(Serial.available()){\r\n    int newHour = Serial.parseInt();\r\n    int newMinute = Serial.parseInt();\r\n    int newSecond = Serial.parseInt();\r\n    rtc.adjust(DateTime(now.year(),now.month(),now.day(),newHour, newMinute, newSecond));\r\n    while(Serial.available()){\r\n      Serial.read();\r\n    }\r\n  }\r\n}<\/pre>\r\n<div>\u00a0<\/div>\r\n<\/div>\r\n\n<p>You enter the current hour, minute and second in the serial monitor. The year, month and day are taken from the currently set time.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Setting up an alarm with the DS3231<\/h3>\n\n<p>You can use the DS3231 as an alarm clock or a timer. There are two alarms available, but we will start by setting up one. You can use an interrupt to be informed about the alarm, or you actively ask regularly whether an alarm has been triggered.<\/p>\r\n<p>But first you get to know the new <code>rtc.disable32K();<\/code> function. This turns off the 32 kHz signal at pin &#8220;32K&#8221;.<\/p>\r\n<p>With <code>rtc.setAlarm1();<\/code> or <code>rtc.setAlarm2();<\/code> you set up an alarm. The functions expect two arguments. The first argument is a time in the form of a DateTime object. In this sketch <code>rtc.now(); + TimeSpan();<\/code> is used, i.e. the DS3231 acts as a timer. The second argument is best explained by examples:<\/p>\r\n<ul>\r\n<li><code>DS3231_A1_Hour<\/code> is the common alarm setting. The alarm is triggered when the hour, minute and second match the specified alarm time. One alarm is triggered per day.<\/li>\r\n<li><code>DS3231_A1_Second<\/code> triggers an alarm each time the current second matches the second which was set in the alarm time. The alarm is triggered once per minute.<\/li>\r\n<\/ul>\r\n<p>There are even more options and confusingly the allowed parameters for Alarm1 and Alarm2 are different:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib-1024x435.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"435\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib-1024x435.png\" alt=\"Alarm parameters for the DS3231\" class=\"wp-image-10974\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib-1024x435.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib-300x127.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib-768x326.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/alarm_parameter_ds3231_rtclib.png 1258w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Alarm parameters for the DS3231<\/figcaption><\/figure>\n\n<h4 class=\"wp-block-heading\">More functions for the DS3231 alarms<\/h4>\n\n<ul>\r\n<li><code>rtc.clearAlarm(1\/2);<\/code> clears the alarm. An alarm remains active until it is cleared.<\/li>\r\n<li><code>rtc.writeSqwPinMode(DS3231_OFF);<\/code> deactivates the square wave signal at SQW so that the pin can be used as an interrupt pin.<\/li>\r\n<li><code>rtc.disableAlarm(1\/2);<\/code> deactivates the alarm function 1 or 2.<\/li>\r\n<li><code>rtc.alarmFired(1\/2);<\/code> checks whether Alarm1 or Alarm2 has been triggered (register check).<\/li>\r\n<\/ul>\r\n<p>The following sketch triggers an alarm in 10 seconds.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ds3231_alarm_10s.ino\" data-enlighter-title=\"ds3231_alarm_10s.ino\">\/* Example implementation of an alarm using DS3231\r\n *\r\n * VCC and GND of RTC should be connected to some power source\r\n * SDA, SCL of RTC should be connected to SDA, SCL of arduino\r\n * SQW should be connected to CLOCK_INTERRUPT_PIN\r\n * CLOCK_INTERRUPT_PIN needs to work with interrupts\r\n *\/\r\n\r\n#include &lt;RTClib.h&gt;\r\n\/\/ #include &lt;Wire.h&gt;\r\n\r\nRTC_DS3231 rtc;\r\n\r\n\/\/ the pin that is connected to SQW\r\n#define CLOCK_INTERRUPT_PIN 2\r\n\r\nvoid setup() {\r\n    Serial.begin(9600);\r\n    \/\/ initializing the rtc\r\n    if(!rtc.begin()) {\r\n        Serial.println(\"Couldn't find RTC!\");\r\n        Serial.flush();\r\n        abort();\r\n    }\r\n    \r\n\/\/    if(rtc.lostPower()) {\r\n\/\/        \/\/ this will adjust to the date and time at compilation\r\n\/\/        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n\/\/    }\r\n    \r\n    \/\/we don't need the 32K Pin, so disable it\r\n    rtc.disable32K();\r\n    \r\n    \/\/ Making it so, that the alarm will trigger an interrupt\r\n    pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);\r\n    attachInterrupt(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm, FALLING);\r\n    \r\n    \/\/ set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)\r\n    \/\/ if not done, this easily leads to problems, as both register aren't reset on reboot\/recompile\r\n    rtc.clearAlarm(1);\r\n    rtc.clearAlarm(2);\r\n    \r\n    \/\/ stop oscillating signals at SQW Pin\r\n    \/\/ otherwise setAlarm1 will fail\r\n    rtc.writeSqwPinMode(DS3231_OFF);\r\n    \r\n    \/\/ turn off alarm 2 (in case it isn't off already)\r\n    \/\/ again, this isn't done at reboot, so a previously set alarm could easily go overlooked\r\n    rtc.disableAlarm(2);\r\n    \r\n    \/\/ schedule an alarm 10 seconds in the future\r\n    if(!rtc.setAlarm1(\r\n            rtc.now() + TimeSpan(10),\r\n            DS3231_A1_Second \/\/ this mode triggers the alarm when the seconds match. See Doxygen for other options\r\n    )) {\r\n        Serial.println(\"Error, alarm wasn't set!\");\r\n    }else {\r\n        Serial.println(\"Alarm will happen in 10 seconds!\");  \r\n    }\r\n}\r\n\r\nvoid loop() {\r\n    \/\/ print current time\r\n    char date[10] = \"hh:mm:ss\";\r\n    rtc.now().toString(date);\r\n    Serial.println(date);\r\n    \/\/ resetting SQW and alarm 1 flag\r\n    \/\/ using setAlarm1, the next alarm could now be configurated\r\n    if(rtc.alarmFired(1)) {\r\n        rtc.clearAlarm(1);\r\n        Serial.println(\"Alarm cleared\");\r\n    }\r\n    \r\n    delay(2000);\r\n}\r\n\r\nvoid onAlarm() {\r\n    Serial.println(\"Alarm occured!\");\r\n}<\/pre>\r\n<p> <\/p>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of ds3231_alarm_10s.ino<\/h4>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_alarm_10s.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"349\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_alarm_10s.png\" alt=\"DS3231 Example sketch: Output of ds3231_alarm_10s.ino\" class=\"wp-image-10921\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_alarm_10s.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_alarm_10s-300x123.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_alarm_10s-768x315.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of ds3231_alarm_10s.ino<\/figcaption><\/figure>\n\n<p>The alarm is retriggered every minute when the seconds match the alarm time.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Setting up two alarms<\/h3>\n\n<p>If you have understood how to set one alarm, then two alarms are not a problem either. I am not introducing any new functions here, and I think the sketch is self-explanatory along with the output on the serial monitor.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ds3231_2_alarms.ino\" data-enlighter-title=\"ds3231_2_alarms.ino\">\/* Example implementation of an alarm using DS3231\r\n *\r\n * VCC and GND of RTC should be connected to some power source\r\n * SDA, SCL of RTC should be connected to SDA, SCL of arduino\r\n * SQW should be connected to CLOCK_INTERRUPT_PIN\r\n * CLOCK_INTERRUPT_PIN needs to work with interrupts\r\n *\/\r\n\r\n#include &lt;RTClib.h&gt;\r\n\/\/ #include &lt;Wire.h&gt;\r\n\r\nRTC_DS3231 rtc;\r\n\r\n\/\/ the pin that is connected to SQW\r\n#define CLOCK_INTERRUPT_PIN 2\r\n\r\nvoid setup() {\r\n    Serial.begin(9600);\r\n    \/\/ initializing the rtc\r\n    if(!rtc.begin()) {\r\n        Serial.println(\"Couldn't find RTC!\");\r\n        Serial.flush();\r\n        abort();\r\n    }\r\n    \r\n\/\/    if(rtc.lostPower()) {\r\n\/\/        \/\/ this will adjust to the date and time at compilation\r\n\/\/        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n\/\/    }\r\n    \r\n    \/\/we don't need the 32K Pin, so disable it\r\n    rtc.disable32K();\r\n    \r\n    \/\/ Making it so, that the alarm will trigger an interrupt\r\n    pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);\r\n    attachInterrupt(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm, FALLING);\r\n    \r\n    \/\/ set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)\r\n    \/\/ if not done, this easily leads to problems, as both register aren't reset on reboot\/recompile\r\n    rtc.clearAlarm(1);\r\n    rtc.clearAlarm(2);\r\n    \r\n    \/\/ stop oscillating signals at SQW Pin\r\n    \/\/ otherwise setAlarm1 will fail\r\n    rtc.writeSqwPinMode(DS3231_OFF);\r\n    \r\n    \/\/ turn off alarm 2 (in case it isn't off already)\r\n    \/\/ again, this isn't done at reboot, so a previously set alarm could easily go overlooked\r\n    rtc.disableAlarm(2);\r\n\r\n    Serial.print(\"Start time: \");\r\n    printTime();\r\n    \r\n    \/\/ schedule an alarm 30 seconds in the future\r\n    rtc.setAlarm1(rtc.now() + TimeSpan(10), DS3231_A1_Second); \/\/ this mode triggers the alarm when the seconds match. See Doxygen for other options\r\n    Serial.println(\"Alarm 1 will happen in 10 seconds!\");  \r\n\r\n    \/\/ schedule an alarm 2 minutes in the future   \r\n    rtc.setAlarm2(rtc.now() + TimeSpan(0,0,2,0), DS3231_A2_Minute); \/\/ this mode triggers the alarm when the minutes match. See Doxygen for other options\r\n    Serial.println(\"Alarm 2 will happen in 2 minutes (when full minutes match)!\");\r\n    Serial.println();  \r\n   \r\n}\r\n\r\nvoid loop() {\r\n    \/\/ resetting SQW and alarm 1 flag\r\n    \/\/ using setAlarm1, the next alarm could now be configurated\r\n    if(rtc.alarmFired(1)) {\r\n        printTime();\r\n        rtc.clearAlarm(1);\r\n        Serial.println(\"Alarm 1 cleared\");\r\n        Serial.println();\r\n    }\r\n\r\n    \/\/ resetting SQW and alarm 1 flag\r\n    \/\/ using setAlarm1, the next alarm could now be configurated\r\n    if(rtc.alarmFired(2)) {\r\n        printTime();\r\n        rtc.clearAlarm(2);\r\n        Serial.println(\"Alarm 2 cleared\");\r\n        Serial.println();\r\n    }\r\n}\r\n\r\nvoid printTime(){\r\n     \/\/ print current time\r\n    char date[10] = \"hh:mm:ss\";\r\n    rtc.now().toString(date);\r\n    Serial.println(date);\r\n}\r\n\r\nvoid onAlarm() {\r\n    Serial.println(\"Alarm occured!\");\r\n}<\/pre>\r\n<p> <\/p>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of ds3231_2_alarms.ino<\/h4>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_2_alarms.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"453\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_2_alarms.png\" alt=\"DS3231 Example sketch: Output of ds3231_2_alarms.ino\" class=\"wp-image-10924\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_2_alarms.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_2_alarms-300x160.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_ds3231_2_alarms-768x409.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of ds3231_2_alarms.ino<\/figcaption><\/figure>\n\n<p>Here you can see the effect of the parameter D3231_A2_Minute.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Setting an alarm for a specific date<\/h3>\n\n<p>Again, no new functions are introduced in this sketch. It is only for deepening your knowledge.<\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"DS3231_alarm_fixed_time_and_date.ino\" data-enlighter-title=\"DS3231_alarm_fixed_time_and_date.ino\">#include &lt;RTClib.h&gt;\r\n\/\/ #include &lt;Wire.h&gt;\r\n\r\nRTC_DS3231 rtc;\r\n\r\n\/\/ the pin that is connected to SQW\r\n#define CLOCK_INTERRUPT_PIN 2\r\nvolatile bool alarm = false;\r\n\r\nvoid setup() {\r\n    Serial.begin(9600);\r\n    if(!rtc.begin()) {\r\n        Serial.println(\"Couldn't find RTC!\");\r\n        Serial.flush();\r\n        abort();\r\n    }\r\n    \r\n\/\/    if(rtc.lostPower()) {\r\n\/\/        \/\/ this will adjust to the date and time at compilation\r\n\/\/        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n\/\/    }\r\n    \r\n    \/\/we don't need the 32K Pin, so disable it\r\n    rtc.disable32K();\r\n    \r\n    \/\/ Making it so, that the alarm will trigger an interrupt\r\n    pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);\r\n    attachInterrupt(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm, FALLING);\r\n    \r\n    \/\/ set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)\r\n    \/\/ if not done, this easily leads to problems, as both register aren't reset on reboot\/recompile\r\n    rtc.clearAlarm(1);\r\n    rtc.clearAlarm(2);\r\n    \r\n    \/\/ stop oscillating signals at SQW Pin\r\n    \/\/ otherwise setAlarm1 will fail\r\n    rtc.writeSqwPinMode(DS3231_OFF);\r\n    \r\n    \/\/ turn off alarm 2 (in case it isn't off already)\r\n    \/\/ again, this isn't done at reboot, so a previously set alarm could easily go overlooked\r\n    rtc.disableAlarm(2);\r\n    \r\n    \/\/ schedule an Alarm for a certain date (day of month), hour, minute, and second\r\n    DateTime alarmTime (2021, 1, 24, 21, 33, 0);\r\n    rtc.setAlarm1(alarmTime, DS3231_A1_Date); \r\n    Serial.print(\"Current time: \");\r\n    printTime();\r\n    Serial.println();\r\n}\r\n\r\nvoid loop() {\r\n    if(alarm){\r\n        if(rtc.alarmFired(1)) {\r\n            Serial.println(\"Alarm occured, current time: \");\r\n            printTime();\r\n            rtc.clearAlarm(1);\r\n            Serial.println(\"Alarm 1 cleared\");\r\n        }\r\n    }\r\n}\r\n\r\nvoid printTime(){\r\n    \/\/ print current time\r\n    DateTime now = rtc.now();\r\n    char date[] = \"DD.MM.YYYY, \";\r\n    Serial.print(now.toString(date));\r\n    char time[] = \"hh:mm:ss\";\r\n    rtc.now().toString(time);\r\n    Serial.println(time);\r\n}\r\n\r\nvoid onAlarm() {\r\n    alarm = true;\r\n}<\/pre>\r\n<p> <\/p>\r\n<\/div>\r\n\n<h4 class=\"wp-block-heading\">Output of DS3231_alarm_fixed_time_and_date.ino<\/h4>\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_alarm_fixed_time_and_date.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"349\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_alarm_fixed_time_and_date.png\" alt=\"DS3231 Example sketch: Output of DS3231_alarm_fixed_time_and_date.ino\" class=\"wp-image-10927\" style=\"width:580px;height:237px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_alarm_fixed_time_and_date.png 851w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_alarm_fixed_time_and_date-300x123.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/output_alarm_fixed_time_and_date-768x315.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><figcaption class=\"wp-element-caption\">Output of DS3231_alarm_fixed_time_and_date.ino<\/figcaption><\/figure>\n\n<h2 class=\"wp-block-heading\" id=\"set_ds3231_with_dcf77\">Setting date and time with a DCF77 module<\/h2>\n\n<p>Perhaps you want to set the DS3231 automatically via a <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/dcf77-radio-controlled-clock\" target=\"_blank\" rel=\"noopener\">DCF77 module<\/a>? This has the advantage that you wouldn&#8217;t have to worry about changing the summer and winter times. Here is the circuit with a DCF77 module from Canaduino:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231-1024x578.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"578\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231-1024x578.png\" alt=\"\" class=\"wp-image-21330\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231-1024x578.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231-300x169.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231-768x434.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2024\/05\/DCF77_DS3231.png 1310w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">DCF77 and DS3231 connected to an Arduino Nano<\/figcaption><\/figure>\n\n<p>In my example sketch, I set the DS3231 every five minutes. Of course, this makes no sense in practice, but you can use it to check that it actually works in a few minutes. The setting period can be easily adjusted.<\/p>\r\n\n<div class=\"scroll-paragraph\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"set_ds3231_with_dcf77.ino\" data-enlighter-title=\"set_ds3231_with_dcf77.ino\">#include &lt;util\/parity.h&gt; \/\/comment out if you don't use an AVR MCU\r\n#include \"RTClib.h\"\r\n#define DISPLAY_FQY 3000\r\n#define ALARM_1 1\r\n#define ALARM_2 2\r\n#define TIME_ADJUST_PERIOD 300 \/\/ adjusment every 5 mins\r\nint dcf77InterruptPin = 2;\r\nint pcnPin = 7; \/\/ for Canaduino DCF77\r\n\r\nvolatile unsigned long lastDisplay = 0;\r\nvolatile unsigned long lastInt = 0;\r\nvolatile unsigned long long currentBuf = 0;\r\nvolatile unsigned long long nextBuf = 0;\r\nvolatile bool timeUpdateAvailable = false;\r\nvolatile byte bufCounter;\r\n\r\nRTC_DS3231 rtc;\r\n\r\nvoid setup(){\r\n  Serial.begin(115200);\r\n  pinMode(pcnPin, OUTPUT); \/\/ only for Canaduino DCF77\r\n  if (! rtc.begin()) {\r\n    Serial.println(\"Couldn't find RTC\");\r\n    Serial.flush();\r\n    abort();\r\n  }\r\n  \r\n  rtc.adjust(DateTime(2000, 1, 1, 0, 0, 0));\r\n  rtc.disable32K();\r\n\r\n  pinMode(dcf77InterruptPin, INPUT);\r\n  attachInterrupt(digitalPinToInterrupt(dcf77InterruptPin), DCF77_ISR, CHANGE);\r\n  rtc.clearAlarm(ALARM_1);\r\n  rtc.clearAlarm(ALARM_2);\r\n  rtc.disableAlarm(ALARM_2);\r\n  rtc.writeSqwPinMode(DS3231_OFF);\r\n}\r\n\r\nvoid loop(){\r\n  static DateTime now = rtc.now();\r\n  \r\n  if(timeUpdateAvailable){\r\n    evaluateSequence();\r\n    detachInterrupt(digitalPinToInterrupt(dcf77InterruptPin));\r\n    Serial.println(\"Time Updated\");\r\n    \/\/ if you change TIME_ADJUST_PERIOD, you might also need to change DS3231_A1_Minute\r\n    rtc.setAlarm1(rtc.now() + TimeSpan(TIME_ADJUST_PERIOD), DS3231_A1_Minute);\r\n    rtc.clearAlarm(ALARM_1);\r\n    timeUpdateAvailable = false;\r\n  }\r\n\r\n  if(rtc.alarmFired(ALARM_1)){\r\n    rtc.clearAlarm(ALARM_1);\r\n    attachInterrupt(digitalPinToInterrupt(dcf77InterruptPin), DCF77_ISR, CHANGE);\r\n    Serial.println(\"Next time adjustment started...\");\r\n  }\r\n  \r\n  if (millis() - lastDisplay &gt; DISPLAY_FQY){\r\n    displayDateTime(&amp;now);\r\n  }\r\n\r\n}\r\n\r\nvoid displayDateTime(DateTime now){\r\n  lastDisplay = millis();\r\n  now = rtc.now();\r\n  char buf1[] = \"Today is DDD, MMM DD YYYY\";\r\n  Serial.println(now.toString(buf1));\r\n  char buf2[] = \"Current time is hh:mm:ss\";\r\n  Serial.println(now.toString(buf2));\r\n  Serial.println();  \r\n}\r\n\r\nvoid DCF77_ISR(){\r\n  unsigned int dur = 0;\r\n  dur = millis() - lastInt; \r\n  \r\n  if(digitalRead(dcf77InterruptPin)){\r\n    if(dur&gt;1500){\r\n      if(bufCounter==59){\r\n        timeUpdateAvailable = true;\r\n        currentBuf = nextBuf;\r\n      }\r\n      bufCounter = 0;\r\n      nextBuf = 0;\r\n    }\r\n  }\r\n  else{\r\n    if(dur&gt;150){\r\n      nextBuf |= ((unsigned long long)1&lt;&lt;bufCounter);\r\n    }\r\n    bufCounter++;\r\n  }\r\n  lastInt = millis();\r\n}\r\n\r\nvoid evaluateSequence(){\r\n  byte dcf77Year = (currentBuf&gt;&gt;50) &amp; 0xFF;    \/\/ year = bit 50-57\r\n  byte dcf77Month = (currentBuf&gt;&gt;45) &amp; 0x1F;       \/\/ month = bit 45-49\r\n  byte dcf77DayOfWeek = (currentBuf&gt;&gt;42) &amp; 0x07;   \/\/ day of the week = bit 42-44\r\n  byte dcf77DayOfMonth = (currentBuf&gt;&gt;36) &amp; 0x3F;  \/\/ day of the month = bit 36-41\r\n  byte dcf77Hour = (currentBuf&gt;&gt;29) &amp; 0x3F;       \/\/ hour = bit 29-34\r\n  byte dcf77Minute = (currentBuf&gt;&gt;21) &amp; 0x7F;     \/\/ minute = 21-27 \r\n  bool parityBitMinute = (currentBuf&gt;&gt;28) &amp; 1;\r\n  bool parityBitHour = (currentBuf&gt;&gt;35) &amp; 1;\r\n  bool parityBitDate = (currentBuf&gt;&gt;58) &amp; 1;\r\n\r\n  if((parity_even_bit(dcf77Minute)) == parityBitMinute){\r\n    if((parity_even_bit(dcf77Hour)) == parityBitHour){\r\n      if(((parity_even_bit(dcf77DayOfMonth) + parity_even_bit(dcf77DayOfWeek) \r\n           + parity_even_bit(dcf77Month) + parity_even_bit(dcf77Year))%2) == parityBitDate){\r\n        rtc.adjust(DateTime(rawByteToInt(dcf77Year) + 2000, rawByteToInt(dcf77Month), \r\n            rawByteToInt(dcf77DayOfMonth), rawByteToInt(dcf77Hour), rawByteToInt(dcf77Minute), 0));\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nunsigned int rawByteToInt(byte raw){\r\n  return ((raw&gt;&gt;4)*10 + (raw &amp; 0x0F));\r\n}\r\n\r\n\/\/uncomment the following lines if you don't use an AVR MCU\r\n\/\/bool parity_even_bit(byte val){\r\n\/\/  val ^= val &gt;&gt; 4;\r\n\/\/  val ^= val &gt;&gt; 2;\r\n\/\/  val ^= val &gt;&gt; 1;\r\n\/\/  val &amp;= 0x01;\r\n\/\/  return val;\r\n\/\/}<\/pre>\r\n<p>\u00a0<\/p>\r\n<\/div>\r\n\n<p>I won&#8217;t go into the details here. Everything related to the DS3231 should be understandable with the help of this article. For the DCF77 related code, take at <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/dcf77-radio-controlled-clock\" target=\"_blank\" rel=\"noopener\">this article<\/a>.<\/p>\r\n\n<h3 class=\"wp-block-heading\">PCF8523, PCF8563 and DS1307<\/h3>\n\n<p>With the RTCLib, you can also control the alternative real-time clocks PCF8523, PCF8563 and DS1307. I tried the PCF8523 and the DS1307. The RTCLib example sketches for these RTCs ran without any problems. The setting and reading of the time and date works as with the DS3231. The same applies to the pleasant computing functions using TimeSpan and the numerous formatting options for the output.<\/p>\r\n<p>The PCF8523 (data sheet <a href=\"https:\/\/www.nxp.com\/docs\/en\/data-sheet\/PCF8523.pdf\" target=\"_blank\" rel=\"noopener\">here<\/a>) and the PCF8563 (data sheet <a href=\"https:\/\/www.nxp.com\/docs\/en\/data-sheet\/PCF8563.pdf\" target=\"_blank\" rel=\"noopener\">here<\/a>) are quite similar to the DS3231. At least I had the impression when flying over the registers in the data sheet. Unfortunately, the RTCLib does not seem to have implemented all available features. There is a countdown timer example sketch, but no classic alarm function.<\/p>\r\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-1024x553.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"553\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-1024x553.jpg\" alt=\"Alternative to the DS3231: the PCF8523\" class=\"wp-image-10982\" style=\"width:512px;height:277px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-1024x553.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-300x162.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-768x415.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-1536x829.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-2048x1105.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/PCF8523_front_back-1320x712.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Alternative to the DS3231: the PCF8523<\/figcaption><\/figure>\n\n<p>The DS1307 is a bit simpler. It has no alarm function in itself. Like the DS3231, it has integrated an EEPROM and a battery charging function.<\/p>\r\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-1024x508.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"508\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-1024x508.jpg\" alt=\"\" class=\"wp-image-10980\" style=\"width:512px;height:254px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-1024x508.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-300x149.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-768x381.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-1536x762.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-2048x1017.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/ds1307_front_back_small-1320x655.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Alternative to the DS3231: the DS1307<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">Software RTC<\/h3>\n\n<p>You can also use the time and date functions of the RTCLib without the RTC module. To do this, the current time is taken once from the computer&#8217;s system time during compilation and then updated with the <code>millis()<\/code> function. The example sketch softrtc.ino (which I don&#8217;t reprint here) shows you how to do it. The method has two drawbacks:<\/p>\r\n<ul>\r\n<li>The millis() method is much less accurate.<\/li>\r\n<li>Every time you reset or break the current power, the current time is lost.<\/li>\r\n<\/ul>\r\n<p>For the advanced: The AVR based Arduino boards use the <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/timer-and-pwm-part-1-8-bit-timer0-2\" target=\"_blank\" rel=\"noopener\">Timer0<\/a> and the associated Timer0 overflow interrupt for <code>millis()<\/code>. You can find the definitions in Arduino\\hardware\\arduino\\avr\\cores\\arduino\\wiring.c.<\/p>\r\n\n<h2 class=\"wp-block-heading\">DS3231 Libraries: Alternatives to RTCLib<\/h2>\n\n<p>I also looked at a number of other libraries for the DS3132 on GitHub. If you find the RTCLib too big and complex, you could consider trying the <a href=\"https:\/\/github.com\/sleemanj\/DS3231_Simple\" target=\"_blank\" rel=\"noopener\">DS3231_Simple<\/a> library. The name says it: it&#8217;s simple. It has all the basic functions for reading and setting the time, including alarm programming. What it lacks (as of February 2020) are the alarm interrupts at the SQW pin. So, you have to check regularly if an alarm has been triggered. A clear advantage, however, is that the DS3231 also has functions for using the EEPROM.<\/p>\r\n<p>The <a href=\"https:\/\/github.com\/JChristensen\/DS3232RTC\" target=\"_blank\" rel=\"noopener\">DS3132RTC<\/a> library is very accurate and very complete. But it may be a bit hard to digest for the not-so-experienced Arduino fan. Look at the example sketches, then you know what I mean.<\/p>\r\n\n<h2 class=\"wp-block-heading\">Acknowledgement<\/h2>\n\n<p>I would like to thank <a href=\"https:\/\/www.adafruit.com\/\" target=\"_blank\" rel=\"noopener\">Adafruit<\/a> for publishing their nice library.<\/p>\r\n<p>The basis of my post picture, into which I inserted the DS3231, comes from <a href=\"https:\/\/pixabay.com\/de\/users\/domeckopol-610494\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=943399\" target=\"_blank\" rel=\"noopener\">andreas N<\/a> (domeckopol) on <a href=\"https:\/\/pixabay.com\/de\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=943399\">Pixabay<\/a>.<\/p>\r\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library. <\/p>\n","protected":false},"author":1,"featured_media":10943,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565],"tags":[1377,1372,1388,1376,1371,691,1374,1375,1373,2503,1378],"class_list":["post-11013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other-parts","tag-alarm-en","tag-clock","tag-dcf77-en-2","tag-ds1307-en","tag-ds3231-en","tag-interrupt-en-2","tag-pcf8523-en","tag-pcf8563-en","tag-rtclib-en","tag-set-the-time","tag-two-alarms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DS3231 - Real-time clock &#8226; Wolles Elektronikkiste<\/title>\n<meta name=\"description\" content=\"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DS3231 - Real-time clock &#8226; Wolles Elektronikkiste\" \/>\n<meta property=\"og:description\" content=\"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock\" \/>\n<meta property=\"og:site_name\" content=\"Wolles Elektronikkiste\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-04T21:40:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-30T13:59:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Wolfgang Ewald\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wolfgang Ewald\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"24 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock\"},\"author\":{\"name\":\"Wolfgang Ewald\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"headline\":\"DS3231 &#8211; Real-time clock\",\"datePublished\":\"2021-02-04T21:40:20+00:00\",\"dateModified\":\"2024-05-30T13:59:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock\"},\"wordCount\":2282,\"commentCount\":14,\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Beitragsbild.jpg\",\"keywords\":[\"alarm\",\"clock\",\"DCF77\",\"DS1307\",\"DS3231\",\"Interrupt\",\"PCF8523\",\"PCF8563\",\"RTCLib\",\"set the time\",\"two alarms\"],\"articleSection\":[\"Other parts\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock\",\"name\":\"DS3231 - Real-time clock &#8226; Wolles Elektronikkiste\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Beitragsbild.jpg\",\"datePublished\":\"2021-02-04T21:40:20+00:00\",\"dateModified\":\"2024-05-30T13:59:26+00:00\",\"description\":\"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#primaryimage\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Beitragsbild.jpg\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Beitragsbild.jpg\",\"width\":1280,\"height\":1280},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/ds3231-real-time-clock#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DS3231 &#8211; Real-time clock\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\",\"name\":\"Wolles Elektronikkiste\",\"description\":\"Die wunderbare Welt der Elektronik\",\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\",\"name\":\"Wolfgang Ewald\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"width\":512,\"height\":512,\"caption\":\"Wolfgang Ewald\"},\"logo\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DS3231 - Real-time clock &#8226; Wolles Elektronikkiste","description":"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock","og_locale":"en_US","og_type":"article","og_title":"DS3231 - Real-time clock &#8226; Wolles Elektronikkiste","og_description":"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.","og_url":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock","og_site_name":"Wolles Elektronikkiste","article_published_time":"2021-02-04T21:40:20+00:00","article_modified_time":"2024-05-30T13:59:26+00:00","og_image":[{"width":1280,"height":1280,"url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg","type":"image\/jpeg"}],"author":"Wolfgang Ewald","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wolfgang Ewald","Est. reading time":"24 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#article","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock"},"author":{"name":"Wolfgang Ewald","@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"headline":"DS3231 &#8211; Real-time clock","datePublished":"2021-02-04T21:40:20+00:00","dateModified":"2024-05-30T13:59:26+00:00","mainEntityOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock"},"wordCount":2282,"commentCount":14,"publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg","keywords":["alarm","clock","DCF77","DS1307","DS3231","Interrupt","PCF8523","PCF8563","RTCLib","set the time","two alarms"],"articleSection":["Other parts"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock","url":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock","name":"DS3231 - Real-time clock &#8226; Wolles Elektronikkiste","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#website"},"primaryImageOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#primaryimage"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg","datePublished":"2021-02-04T21:40:20+00:00","dateModified":"2024-05-30T13:59:26+00:00","description":"In this article I will present the features of the real-time clock (RTC) DS3231 and how you can use it with the RTCLib library.","breadcrumb":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#primaryimage","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/01\/Beitragsbild.jpg","width":1280,"height":1280},{"@type":"BreadcrumbList","@id":"https:\/\/wolles-elektronikkiste.de\/en\/ds3231-real-time-clock#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/wolles-elektronikkiste.de\/en"},{"@type":"ListItem","position":2,"name":"DS3231 &#8211; Real-time clock"}]},{"@type":"WebSite","@id":"https:\/\/wolles-elektronikkiste.de\/en#website","url":"https:\/\/wolles-elektronikkiste.de\/en","name":"Wolles Elektronikkiste","description":"Die wunderbare Welt der Elektronik","publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wolles-elektronikkiste.de\/en?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46","name":"Wolfgang Ewald","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","width":512,"height":512,"caption":"Wolfgang Ewald"},"logo":{"@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png"}}]}},"_links":{"self":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/11013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/comments?post=11013"}],"version-history":[{"count":0,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/11013\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media\/10943"}],"wp:attachment":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media?parent=11013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/categories?post=11013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/tags?post=11013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}