I will make a project on DS3231 RTC Module ESP8266 OLED SSD1306with Temperature
The DS3231 RTC Module 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. Now let’s start DS3231 RTC Module ESP8266 OLED SSD1306with Temperature.
Components Used:(Click to Buy)

If you do not know how to set present clock time you can follow this Post.
Set Time on DS3231 Real Time Clock With ESP8266
SSD1306 is a very popular OLED display. In this tutorial, we will use 128 by 64-pixel display.
DS3231 RTC Module ESP8266 setup
First, you have to go to this link where you will find the DS3231 library in GitHub. There are many DS3231 libraries. But I only found this one working with getting the temperature from the sensor.
SSD1306 OLED Display Setup
Most useful & easy library of SSD1306 OLED display is provided by Adafruit. You have to use the following two libraries to set your display perfectly working.
Adafruit SSD1306 OLED library
Adafruit GFX library
You can also search these libraries inside Arduino IDE to install it.
Connect DS3231 RTC Module ESP8266 NodeMCU
Connect all the wires according to the following diagram.

Code Explain DS3231 RTC Module ESP8266
The code is a very simple one. It will display the present date time with temperature in the display. The library function will return integer values of the day of the week from 1 to 7 where 1 is for Sunday and 7 for Saturday. To display it as Sunday, Monday we are saving all the texts in an array. This is the same for the months too where we have saved 12 months in the array.
But in the array, the indexing starts from 0. So when we will display data we will index the previous index. For example, if DS3231 gives us index 5, we will print the value of index 4 of the array. We have done this in the code line no 32 & 34. We will use the century variable as false. If you are using this after the year 2099 you have to use it as true.
In line 47, we are sending parameter 1 to the function getTemperature() to get floating value with one digit after the decimal point. All the temperature is in the Celcius format.
In
Arduino Sketch for DS3231 RTC Module 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /* https://somtips.com https://youtube.com/somtips */ #include <Wire.h> #include <DS3231.h> #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> #define OLED_ADDR 0x3C DS3231 Clock; bool Century=false,h12,pm; char week[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; char mon[12][4] = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"}; Adafruit_SSD1306 display(-1); void setup() { Serial.begin(9600); Wire.begin(); delay(3000); display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR); display.clearDisplay(); display.display(); } void loop() { display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(30,0); display.println("Som Tips"); display.print(week[Clock.getDoW()-1]); display.print(" "); display.print(mon[Clock.getMonth(Century)-1]); display.print(" "); display.print(Clock.getDate()); display.print(" 20"); display.println(Clock.getYear()); display.print(" "); display.print(Clock.getHour(h12, pm)); display.print(" : "); display.print(Clock.getMinute()); display.print(" : "); display.print(Clock.getSecond()); display.println(" HRS"); display.print(" Temp: "); display.print(Clock.getTemperature(), 1); display.println(" C"); display.display(); delay(1000); } |
Output DS3231 RTC Module ESP8266
Here you can see the output in the display.

Final Thought on DS3231 RTC Module OLED
DS3231 RTC Module is a very good module for real-time clock. This needs a coin size battery. But the temperature is not so accurate. To get very accurate temperature & humidity you should have to use the DHT22 sensor. The price is a little high. If you cant afford, they go for DHT11. This will better the RTC module. But never use LM35. This is a very poor accuracy & analog sensor.
So for Date time DS3231 RTC Module is very good. For weather information go for DHT22/11. You can use both sensors with Raspberry Pi.