Clock with Temperature using DS3231 & SSD1306 in ESP8266

Clock with Temperature using DS3231 & SSD1306 in ESP8266

Share it

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. In this post, I will share how to make Real-time clock with temperature using the DS3231 RTC module & SSD1306 OLED display in ESP8266 NodeMCU.

Components Used:(Click to Buy)

ds3231 rtc module with cr2032 coin battery

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 Module 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 & SSD1306 with NodeMCU

Connect all the wires according to the following diagram.

Clock with Temperature using DS3231 & SSD1306 in ESP8266

Code Explain

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 the line 40, Clock.getHour(h12, pm) passing two variable for the 12 hour format. But I found it only supports 24 hour format with this library.

Arduino Sketch


Here you can see the output in the display.

Clock with Temperature using DS3231 & SSD1306 in ESP8266

Watch Video Tutorial

Share it

Leave Comment