<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.cognifront.com/docs/index.php?action=history&amp;feed=atom&amp;title=RTC_Module_DS3231</id>
	<title>RTC Module DS3231 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.cognifront.com/docs/index.php?action=history&amp;feed=atom&amp;title=RTC_Module_DS3231"/>
	<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=RTC_Module_DS3231&amp;action=history"/>
	<updated>2026-11-13T00:07:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://www.cognifront.com/docs/index.php?title=RTC_Module_DS3231&amp;diff=1212&amp;oldid=prev</id>
		<title>CogWikiEditor: /* I²C Communication */</title>
		<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=RTC_Module_DS3231&amp;diff=1212&amp;oldid=prev"/>
		<updated>2026-09-04T04:38:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;I²C Communication&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:38, 4 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l75&quot;&gt;Line 75:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 75:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;&amp;#039;SCL&amp;#039;&amp;#039;&amp;#039; line provides the clock signal required for I²C communication.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The &amp;#039;&amp;#039;&amp;#039;SCL&amp;#039;&amp;#039;&amp;#039; line provides the clock signal required for I²C communication.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[File:Rtc-esp32.jpg | thumb | center | 700px | RTC Module with attached cell CR2032 connected to ESP32]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Connections ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Connections ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>CogWikiEditor</name></author>
	</entry>
	<entry>
		<id>https://www.cognifront.com/docs/index.php?title=RTC_Module_DS3231&amp;diff=1210&amp;oldid=prev</id>
		<title>CogWikiEditor: Created page with &quot;===Interfacing DS3231 RTC Module with ESP32===  &#039;&#039;&#039;Interfacing DS3231 RTC Module with ESP32&#039;&#039;&#039; demonstrates how a DS3231 Real-Time Clock (RTC) module can be interfaced with an ESP32 board using the I²C communication protocol to read and display the current date and time.  The DS3231 is a highly accurate real-time clock module that keeps track of date and time information.  &lt;center&gt; &#039;&#039;&#039;DS3231 RTC → I²C → ESP32 → Serial Monitor&#039;&#039;&#039; &lt;/center&gt;  == Objectives ==  * To...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.cognifront.com/docs/index.php?title=RTC_Module_DS3231&amp;diff=1210&amp;oldid=prev"/>
		<updated>2026-09-04T04:36:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;===Interfacing DS3231 RTC Module with ESP32===  &amp;#039;&amp;#039;&amp;#039;Interfacing DS3231 RTC Module with ESP32&amp;#039;&amp;#039;&amp;#039; demonstrates how a DS3231 Real-Time Clock (RTC) module can be interfaced with an ESP32 board using the I²C communication protocol to read and display the current date and time.  The DS3231 is a highly accurate real-time clock module that keeps track of date and time information.  &amp;lt;center&amp;gt; &amp;#039;&amp;#039;&amp;#039;DS3231 RTC → I²C → ESP32 → Serial Monitor&amp;#039;&amp;#039;&amp;#039; &amp;lt;/center&amp;gt;  == Objectives ==  * To...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===Interfacing DS3231 RTC Module with ESP32===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Interfacing DS3231 RTC Module with ESP32&amp;#039;&amp;#039;&amp;#039; demonstrates how a DS3231 Real-Time Clock (RTC) module can be interfaced with an ESP32 board using the I²C communication protocol to read and display the current date and time.&lt;br /&gt;
&lt;br /&gt;
The DS3231 is a highly accurate real-time clock module that keeps track of date and time information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;DS3231 RTC → I²C → ESP32 → Serial Monitor&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Objectives ==&lt;br /&gt;
&lt;br /&gt;
* To study the working of the DS3231 RTC module.&lt;br /&gt;
* To interface the DS3231 RTC module with the ESP32 board.&lt;br /&gt;
* To communicate with the RTC using the I²C protocol.&lt;br /&gt;
* To read the current date and time from the DS3231.&lt;br /&gt;
* To display the date and time on the Serial Monitor.&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
&lt;br /&gt;
* Arduino IDE&lt;br /&gt;
* RTClib Library&lt;br /&gt;
&lt;br /&gt;
== Hardware Modules ==&lt;br /&gt;
&lt;br /&gt;
* ESP32 Board&lt;br /&gt;
* DS3231 RTC Module&lt;br /&gt;
* PC / Laptop&lt;br /&gt;
* Connecting wires&lt;br /&gt;
&lt;br /&gt;
== Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction to RTC ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;RTC&amp;#039;&amp;#039;&amp;#039; stands for &amp;#039;&amp;#039;&amp;#039;Real-Time Clock&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
A real-time clock is an electronic device used to keep track of the current date and time.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;DS3231&amp;#039;&amp;#039;&amp;#039; is a real-time clock module that provides date and time information including:&lt;br /&gt;
&lt;br /&gt;
* Seconds&lt;br /&gt;
* Minutes&lt;br /&gt;
* Hours&lt;br /&gt;
* Day&lt;br /&gt;
* Month&lt;br /&gt;
* Year&lt;br /&gt;
&lt;br /&gt;
The DS3231 communicates with the ESP32 using the &amp;#039;&amp;#039;&amp;#039;I²C communication protocol&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;DS3231 → Date &amp;amp; Time Data → ESP32&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The RTC module can maintain the date and time even when the main power supply is removed, provided that its backup battery is available.&lt;br /&gt;
&lt;br /&gt;
== I²C Communication ==&lt;br /&gt;
&lt;br /&gt;
The DS3231 communicates with the ESP32 using two I²C signal lines:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Signal&lt;br /&gt;
! ESP32 Pin&lt;br /&gt;
! Function&lt;br /&gt;
|-&lt;br /&gt;
| SDA&lt;br /&gt;
| GPIO 21&lt;br /&gt;
| Serial Data&lt;br /&gt;
|-&lt;br /&gt;
| SCL&lt;br /&gt;
| GPIO 22&lt;br /&gt;
| Serial Clock&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;SDA&amp;#039;&amp;#039;&amp;#039; line is used to transfer data between the ESP32 and DS3231.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;SCL&amp;#039;&amp;#039;&amp;#039; line provides the clock signal required for I²C communication.&lt;br /&gt;
&lt;br /&gt;
== Connections ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! DS3231 Pin&lt;br /&gt;
! ESP32&lt;br /&gt;
! Function&lt;br /&gt;
|-&lt;br /&gt;
| SDA&lt;br /&gt;
| GPIO 21&lt;br /&gt;
| I²C Data&lt;br /&gt;
|-&lt;br /&gt;
| SCL&lt;br /&gt;
| GPIO 22&lt;br /&gt;
| I²C Clock&lt;br /&gt;
|-&lt;br /&gt;
| VCC&lt;br /&gt;
| 3.3V&lt;br /&gt;
| Power supply&lt;br /&gt;
|-&lt;br /&gt;
| GND&lt;br /&gt;
| GND&lt;br /&gt;
| Ground&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== RTClib Library ==&lt;br /&gt;
&lt;br /&gt;
The program uses the &amp;#039;&amp;#039;&amp;#039;RTClib&amp;#039;&amp;#039;&amp;#039; library to communicate with the DS3231 RTC module.&lt;br /&gt;
&lt;br /&gt;
The following header file is included:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;RTClib.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DS3231 RTC object is created using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RTC_DS3231 rtc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The library provides functions for initializing the RTC and reading the current date and time.&lt;br /&gt;
&lt;br /&gt;
== RTC Initialization ==&lt;br /&gt;
&lt;br /&gt;
The ESP32 initializes the I²C communication using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Wire.begin(SDA_PIN, SCL_PIN);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Parameter&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| SDA&lt;br /&gt;
| GPIO 21&lt;br /&gt;
|-&lt;br /&gt;
| SCL&lt;br /&gt;
| GPIO 22&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The program then checks whether the DS3231 RTC is detected.&lt;br /&gt;
&lt;br /&gt;
If the RTC is not detected, the following message is displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DS3231 NOT FOUND!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the RTC is detected successfully, the following message is displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DS3231 Ready&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RTC Lost Power ==&lt;br /&gt;
&lt;br /&gt;
The program checks whether the RTC has lost its power using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rtc.lostPower()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the RTC has lost power, the program displays:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RTC lost power!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The RTC is then adjusted using the date and time obtained during program compilation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the RTC to the date and time available when the program is compiled.&lt;br /&gt;
&lt;br /&gt;
== Reading Date and Time ==&lt;br /&gt;
&lt;br /&gt;
The current date and time are obtained using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DateTime now = rtc.now();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program reads the following values:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Function&lt;br /&gt;
! Information&lt;br /&gt;
|-&lt;br /&gt;
| now.day()&lt;br /&gt;
| Day&lt;br /&gt;
|-&lt;br /&gt;
| now.month()&lt;br /&gt;
| Month&lt;br /&gt;
|-&lt;br /&gt;
| now.year()&lt;br /&gt;
| Year&lt;br /&gt;
|-&lt;br /&gt;
| now.hour()&lt;br /&gt;
| Hour&lt;br /&gt;
|-&lt;br /&gt;
| now.minute()&lt;br /&gt;
| Minute&lt;br /&gt;
|-&lt;br /&gt;
| now.second()&lt;br /&gt;
| Second&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Algorithm ==&lt;br /&gt;
&lt;br /&gt;
The following algorithm is used to interface the DS3231 RTC module with the ESP32:&lt;br /&gt;
&lt;br /&gt;
# Start the Arduino IDE.&lt;br /&gt;
# Include the &amp;#039;&amp;#039;&amp;#039;Wire&amp;#039;&amp;#039;&amp;#039; library for I²C communication.&lt;br /&gt;
# Include the &amp;#039;&amp;#039;&amp;#039;RTClib&amp;#039;&amp;#039;&amp;#039; library.&lt;br /&gt;
# Define GPIO 21 as the SDA pin.&lt;br /&gt;
# Define GPIO 22 as the SCL pin.&lt;br /&gt;
# Create the DS3231 RTC object.&lt;br /&gt;
# In the &amp;#039;&amp;#039;&amp;#039;void setup()&amp;#039;&amp;#039;&amp;#039; function, start Serial communication at &amp;#039;&amp;#039;&amp;#039;115200 baud&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
# Initialize I²C communication using GPIO 21 and GPIO 22.&lt;br /&gt;
# Check whether the DS3231 RTC is detected.&lt;br /&gt;
# If the RTC is not detected, display an error message and stop execution.&lt;br /&gt;
# Check whether the RTC has lost power.&lt;br /&gt;
# If the RTC has lost power, adjust the RTC using the compilation date and time.&lt;br /&gt;
# Display the &amp;#039;&amp;#039;&amp;#039;DS3231 Ready&amp;#039;&amp;#039;&amp;#039; message.&lt;br /&gt;
# In the &amp;#039;&amp;#039;&amp;#039;void loop()&amp;#039;&amp;#039;&amp;#039; function, read the current date and time using &amp;#039;&amp;#039;&amp;#039;rtc.now()&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
# Display the date on the Serial Monitor.&lt;br /&gt;
# Display the time on the Serial Monitor.&lt;br /&gt;
# Wait for &amp;#039;&amp;#039;&amp;#039;1000 ms&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
# Repeat the process continuously.&lt;br /&gt;
&lt;br /&gt;
The overall operation is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;DS3231 → I²C → ESP32 → Date &amp;amp; Time → Serial Monitor&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Working ==&lt;br /&gt;
&lt;br /&gt;
The ESP32 communicates with the DS3231 RTC module through the I²C interface.&lt;br /&gt;
&lt;br /&gt;
The I²C pins used in this practical are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SDA = GPIO 21&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SCL = GPIO 22&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After initialization, the ESP32 checks whether the DS3231 is available.&lt;br /&gt;
&lt;br /&gt;
If the RTC is detected, the program reads the current date and time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;DS3231 → Current Date &amp;amp; Time → ESP32&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ESP32 then displays the information on the Serial Monitor.&lt;br /&gt;
&lt;br /&gt;
The date is displayed in the following format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Date: DD/MM/YYYY&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The time is displayed in the following format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Time: HH:MM:SS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reading is updated once every second.&lt;br /&gt;
&lt;br /&gt;
== Serial Monitor Output ==&lt;br /&gt;
&lt;br /&gt;
The Serial Monitor operates at &amp;#039;&amp;#039;&amp;#039;115200 baud&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
A typical output format is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DS3231 Ready&lt;br /&gt;
Date: 4/9/2026  Time: 13:25:10&lt;br /&gt;
Date: 4/9/2026  Time: 13:25:11&lt;br /&gt;
Date: 4/9/2026  Time: 13:25:12&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the RTC is not detected, the output is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DS3231 NOT FOUND!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the RTC has lost power, the output includes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RTC lost power!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Timing ==&lt;br /&gt;
&lt;br /&gt;
The program reads and displays the RTC date and time once every &amp;#039;&amp;#039;&amp;#039;1000 ms&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The sequence is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Read RTC → Display Date &amp;amp; Time → 1 Second Delay → Read RTC → Repeat&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Program ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// © 2026, Cognifront&lt;br /&gt;
// DS3231 RTC with ESP32&lt;br /&gt;
// SDA = GPIO 21, SCL = GPIO 22&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Wire.h&amp;gt;&lt;br /&gt;
#include &amp;lt;RTClib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define SDA_PIN 21&lt;br /&gt;
#define SCL_PIN 22&lt;br /&gt;
&lt;br /&gt;
RTC_DS3231 rtc;&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
  Serial.begin(115200);&lt;br /&gt;
  Wire.begin(SDA_PIN, SCL_PIN);&lt;br /&gt;
&lt;br /&gt;
  if (!rtc.begin()) {&lt;br /&gt;
    Serial.println(&amp;quot;DS3231 NOT FOUND!&amp;quot;);&lt;br /&gt;
    while (1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  if (rtc.lostPower()) {&lt;br /&gt;
    Serial.println(&amp;quot;RTC lost power!&amp;quot;);&lt;br /&gt;
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  Serial.println(&amp;quot;DS3231 Ready&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
  DateTime now = rtc.now();&lt;br /&gt;
&lt;br /&gt;
  Serial.print(&amp;quot;Date: &amp;quot;);&lt;br /&gt;
  Serial.print(now.day());&lt;br /&gt;
  Serial.print(&amp;quot;/&amp;quot;);&lt;br /&gt;
  Serial.print(now.month());&lt;br /&gt;
  Serial.print(&amp;quot;/&amp;quot;);&lt;br /&gt;
  Serial.print(now.year());&lt;br /&gt;
&lt;br /&gt;
  Serial.print(&amp;quot;  Time: &amp;quot;);&lt;br /&gt;
  Serial.print(now.hour());&lt;br /&gt;
  Serial.print(&amp;quot;:&amp;quot;);&lt;br /&gt;
  Serial.print(now.minute());&lt;br /&gt;
  Serial.print(&amp;quot;:&amp;quot;);&lt;br /&gt;
  Serial.println(now.second());&lt;br /&gt;
&lt;br /&gt;
  delay(1000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Observation ==&lt;br /&gt;
&lt;br /&gt;
Observe the output on the Serial Monitor at a baud rate of &amp;#039;&amp;#039;&amp;#039;115200&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The current date and time obtained from the DS3231 RTC are displayed.&lt;br /&gt;
&lt;br /&gt;
The time values change continuously, with the output being updated once every second.&lt;br /&gt;
&lt;br /&gt;
The date is displayed in the format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Day / Month / Year&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The time is displayed in the format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Hour : Minute : Second&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Result ==&lt;br /&gt;
&lt;br /&gt;
The ESP32 successfully interfaces with the &amp;#039;&amp;#039;&amp;#039;DS3231 Real-Time Clock module&amp;#039;&amp;#039;&amp;#039; using I²C communication.&lt;br /&gt;
&lt;br /&gt;
The ESP32 reads the current date and time from the RTC and displays the information on the Serial Monitor.&lt;/div&gt;</summary>
		<author><name>CogWikiEditor</name></author>
	</entry>
</feed>