Here I will say DS3231 Time Set ESP8266 Real-Time Clock With Serial Monitor Easily.
The DS3231 is a very accurate & widely used Real-Time Clock (RTC) module. This module is used in Arduino based projects. This module also works with Raspberry Pi. So let’s start DS3231 Time Set ESP8266 Real-Time Clock With Serial Monitor Easily.

Before connecting DS3231 with NodeMCU, make sure you have inserted the CR2032 battery into DS3231. It is recommended to use a Rechargeable cell. But you can also use
Components Used:(Click to Buy)
Library for DS3231 Time Set ESP8266
Now open your Arduino IDE and go to the Library manager from the menu bar.
Now search for RTCLib and select the latest version to download. This library is provided by Adafruit as you see in the image below.

Connect DS3231 with ESP8266 NodeMCU
After adding the library we have to connect DS3231 with ESP8266 NodeMCThe connection is very simple as you can see the diagram below.

Clock with Temperature using DS3231 & SSD1306 in ESP8266
DS3231 Time Set ESP8266 With Serial Monitor
After all the connection done we have to write a simple code to update the current into DS3231 module.
Remember only write time once after installing the CR2032 coin battery. As long as there is power in the battery, you will not get any error in the time.
You can use the following code to update time.

Code Explain for DS3231 Time Set ESP8266
The code is a very simple one. It will set the time & then display the time in serial monitor from DS3231.
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
In line 18, the the rtc object is setting the time according to your computer time. It will set present clock time of your system.
rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
In line 19, you can set the time manually just sending the date-time value to the function in the order of year, month, date, hour, min, second.
In the following code, we are setting time if system. So we commented the line 19.
Arduino Sketch of DS3231 Time Set ESP8266
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /* https://somtips.com https://youtube.com/somtips */ #include <RTClib.h> #include <Wire.h> RTC_DS3231 rtc; char t[32]; void setup() { Serial.begin(9600); Wire.begin(); rtc.begin(); rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } void loop() { DateTime now = rtc.now(); sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year()); Serial.print(F("Date/Time: ")); Serial.println(t); delay(1000); } |
Output
After opening serial monitor in 9600 baud rate you can see the following output i.e. Time fetched from DS3231.
