Arduino real time clock with temperature monitor using DS3231 and SSD1306

In the last post I built an Arduino based real time clock using DS1307 RTC and SSD1306 OLED and in this project I’m going to show how to build a real time clock with temperature monitor using Arduino, DS3231 RTC chip and SSD1306 OLED (128×64 pixel).

The DS3231 is more accurate than the DS1307 due to its built-in temperature sensor. It also (the DS3231) keeps the time running if the main power source is down. It also uses I2C interface to communicate with the master device which is in this case the Arduino. That means the DS3231 and the SSD1306 OLED screen share the same I2C bus. Even they share the same bus but at any time the microcontroller ‘speaks’ with 1 device only depending on the address sent. The DS3231 RTC address is 0x68 (the same address with the DS1307) and the SSD1306 OLED address is 0x3D.
In the circuit there are two push buttons for setting time and date of the real time clock.

Related Projects:
Arduino and DS3231 real time clock
Interfacing Arduino with SSD1306 OLED display
Arduino real time clock using DS1307 and SSD1306 OLED

Hardware Required:

  • Arduino board
  • DS3231 board  —  DS3231 RTC datasheet
  • SSD1306 OLED (I2C mode)
  • 2 x push button
  • 3V coin cell battery
  • Breadboard
  • Jumper wires

Arduino with SSD1306 OLED and DS3231 RTC circuit

The SSD1306 OLED used in this project is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode or I2C mode) such as soldering, placing jumpers …

In this project I used Adafruit SSD1306 OLED driver and Adafruit GFX library. Both libraries can be downloaded through Arduino IDE Library Manager of manually from the links below (after downloading, unzip the folders and place them in Arduino libraries folder, for example C:\Program Files\Arduino\libraries)
Adafruit SSD1306 OLED library   —   direct link
Adafruit GFX library                  —   direct link

Project circuit:
Project circuit diagram is shown below.

Arduino SSD1306 OLED DS3231 RTC with set buttons

(All grounded terminals are connected together)

The two push buttons B1 and B2 are for setting time and date.

Arduino Code:
SSD1306 OLED and DS3231 RTC share the same I2C bus and the Arduino communicates only with 1 device at a time depending on the address (sent by the Arduino), the SSD1306 address is 0x3D and the DS3231 address is 0x68.

The Arduino code below uses Adafruit SSD1306 OLED driver and Adafruit GFX library. It doesn’t use any library for the DS3231 RTC.

The small video below shows a simple hardware circuit of the project:

and the one below shows the simulation of the project with Proteus (the simulation circuit is not the same as the hardware circuit, the hardware circuit diagram is shown above).

Proteus simulation file download (for version 8.6 or higher):
Arduino + SSD1306 OLED + DS3231

13 comments

  1. Hi tired this out but i get warnings “warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings”
    and I see only the day (which is small) .and dd/mm/yyyy which is very large I do not see time or TEMPERATURE.
    I’m using the same pcs but my OLED is only blue.
    I can chage the day Monday etc and the dd/mm/yyyy.
    I’m looking but cann’t find the answer ( i’m new to arduino)
    Thanks for any help

  2. Hi everyone, I have a big question, can it works with a ds1302 instead a ds1306? And if the case is correct, how can I do it?
    I’m new in all these and I don’t know how to do it, or change it.
    Thanks in advice.

    1. If you mean DS1302 instead of DS3231 (not DS1306 or SSD1306), no you can’t, because the DS3231 uses I2C protocol (2-wire interface) whereas the DS1302 does use 3-wire interface.

  3. I am going to build this real time clock and temperature monitor maybe this weekend (with or without the Chicken sound effects) but I can not read the metrics is there a way to convert them to American English?

    1. If you mean mm-dd-yyyy arrangement of the calendar, yes you can do that, few modifications to the code are required.

  4. Thank You Simple Project for providing the code i just needed the blink_parameter part which is now perfectly working for my project.

  5. Hello, This is a very beautiful project and I must have it, I have plans on placing several of these throughout my little world but I built this project today and there is no display showing on the oled, nothing shows up. I have changed the display 3 times, I have tried 4 different Arduino Uno’s, I have replaced the hookup wiring with each different Arduino, I tried 3 different DS3231’s. I have even tried 4 different breadboards with each different Arduino. I noticed that the video shows a different hookup than the Fritzig and I hooked it up both ways still nothing showing up on the display. I am wondering if there is anything missing from the code. I am relatively new to these Arduino devices so I would not recognize anything missing. Can you offer any advice that might help because I believe this to be the perfect clock for my needs. Thank you

  6. ArduinoNano+DS3231clock modul+DHT22 temperature modul+0.96OLED I2C display with 4 pins +2 buttons use. Code how to modifyed? How it use plese?! Can you help me?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.