This mission demonstrates how one can construct a real-time clock (RTC) with a temperature show utilizing Arduino, DS3231 RTC chip, and SSD1306 OLED show (128×64 pixel).

DS3231 RTC chip is extra correct than DS1307 and likewise has a built-in temperature sensor. It retains the time operating even when the primary energy supply is down. It makes use of the I2C interface to speak with the grasp gadget (microcontroller), on this case the Arduino.

DS3231 and SSD1306 OLED share the identical I2C bus, however the microcontroller can talk with solely considered one of them at a time, relying on the handle despatched. The DS3231 RTC handle is 0×68, and the SSD1306 OLED handle is 0×3C.

Fig. 1 reveals the writer’s prototype, and Fig. 2 reveals the circuit’s block diagram.

Circuit diagram of the Arduino real-time clock with temperature show is proven in Fig. 3. It’s constructed round Arduino Uno (Board1), 5V regulator 7805 (IC1), 2.4cm SSD1306 OLED show (DIS1), DS3231 RTC module (RTC1), and some different parts.

OLED (natural light-emitting diode) is a flat mild emitting gadget developed with natural skinny movies which can be related in collection between two electrical conductors. The OLED show used on this mission is proven in Fig. 4. It has improved picture high quality, full viewing angle, excessive brightness, higher distinction, huge color vary, and low energy consumption. It’s extra environment friendly and dependable as in comparison with a easy LCD show.

SSD1306 OLED display module
Fig. 4: SSD1306 OLED show module

It’s primarily utilized in such digital show gadgets as pc displays, cell phones, hand-held video video games, and tv screens. It’s simply accessible out there in addition to on-line shops.

The show module connects to Arduino utilizing 4 wires—two for energy and one other two for knowledge— making the wiring quite simple. The info connection relies on the I2C (inter-integrated circuit) interface, which is also referred to as TWI (two wire interface).

DS3231 RTC module

The DS3231 module is a low-cost, extremely correct real-time clock that may keep time in hours, minutes, and seconds in addition to the day, month, and yr data. It has automated compensation for leap years for and months with lower than 31 days.

The module can work on both 3.3V or 5V, which makes it appropriate for a lot of improvement platforms or microcontrollers. The battery enter is 3V, and a typical CR2032 3V battery can energy the module and keep the knowledge for greater than a yr. The DS3231 module (back and front) used on this mission is proven in Fig. 5.

DS3231 RTC module
Fig. 5: DS3231 RTC module

The I2C communication protocol used within the module makes connections to the Arduino board very simple. All we want are 4 pins: VCC and GND pins for powering the module, and SDA and SCL pins for I2C communication.

Energy provide

The regulated energy provide is designed with a full-wave rectifier constructed round 1N4007 diodes (D1 and D2), two capacitors (C1 and C2), 5V voltage regulator 7805 (IC1) and 230V AC major to 12V-0-12V, 500mA secondary step-down transformer (X1). Within the mission, two energy provides are required: 12V DC for Arduino Uno energy jack, and 5V for DS3231 RTC and SSD1306 OLED module.

Arduino Uno

The guts of the mission is the Arduino Uno R3 board, which relies on ATmega328/ATmega328P microcontroller. It has 14 digital enter/output (I/O) pins, six analogue inputs, 32k flash reminiscence, 16MHz crystal oscillator, USB connection, an influence jack, an ICSP header, a reset button, amongst others. It may be programmed utilizing Arduino IDE software program.

Within the circuit, there are two push buttons: S1 for setting and S2 for mode change. These are used for setting the time and date of the real-time clock. The bottom connection of Arduino must be related to floor connections of RTC1 module and show DIS1 module.

Building and testing

After making all of the connections, take a look at the working of the circuit by urgent the mode button (S2), after which launch it. The cursor on show will flash on the day-of-week area. Press and maintain the set button (S1) to advance the day of the week to the subsequent day at 5Hz fee, or do a brief press to advance to the subsequent setting.

Press and launch the mode button (S2) to advance the cursor to the month area. Press and maintain the set button (S1) to scroll via the months rapidly, or do a brief press to advance to the subsequent setting. Press and launch the S2 button to advance the cursor to the date area. Press and maintain the S1 button to scroll via the dates rapidly, or do a brief press to advance to the subsequent setting.

Notice that the RTC chip is aware of the right variety of days in every month. Press and launch the S2 button to advance the cursor to the yr area. Press and maintain the S1 button to scroll via the years rapidly, or do a brief press to advance to the subsequent setting. Legitimate ranges are 2000 to 2099. The RTC chip retains observe of leap years mechanically. Once you first energy up the clock, the date shall be January 1, 1900. Simply advance the yr to the right worth.

Press and launch the S2 button to advance the cursor to the hour area. Press and maintain the S1 button to scroll via the hours rapidly, or do a brief press to advance to the subsequent setting. The clock makes use of solely 24-hour mode within the mission. Press and launch the S2 button to advance the cursor to the minutes’ area. Press and maintain the S1 button to scroll via the minutes rapidly, or do a brief press to advance to the subsequent setting. Press and launch the S2 button to advance the cursor to the seconds’ area. Press S2 button momentarily to reset the seconds to zero, or maintain the button to freeze the seconds at zero and launch to synchronise with an exterior time supply. DS3231 RTC chip has an inbuilt temperature sensor.

Thus, it provides time, date, and yr together with temperature readings (refer Fig. 6).

Digital clock with temperature display
Fig. 6: Digital clock with temperature show

Software program

Circuit operation is managed by the software program program (main_code.ino) loaded into the inner reminiscence of Arduino Uno. This system implements all of the required functionalities.

This system/sketch is written within the Arduino programming language. Arduino IDE model 1.8.11 is used to compile and add this system to the Arduino board.

On this mission, the next header information are required within the main_code.ino for programming:

#embrace <wire.h>. This header file is particularly required for I2C protocol gadgets for quicker communication. On this mission, the 2 I2C gadgets are SSD1306 OLED show and DS3231 RTC module. (This header file is already included within the newest Arduino IDE.)

#embrace <Adafruit_GFX.h>. The header file Adafruit Graphical library is used to generate several types of graphics like sq., triangle, black and white color inversions, star symbols, and pictures in .bmp codecs. On this mission, completely different font sizes and particular symbols notation for temperature models (levels centigrade) are used.

#embrace <Adafruit_SSD1306.h>. This header file is used to speak with the SSD1306 show utilizing handle mapping. The SSD1306 show having 128×64 pixel dimension can show the information as much as eight pages alternately. Entry every web page by utilizing three handle traces. The number of handle traces, knowledge and instructions are very simple utilizing Adafruit_SSD1306 header file.

The Arduino code (main_code.ino) requires two exterior libraries: Adafruit-GFX-Library-master.zip and Adafruit_SSD1306-master.zip. You have to embrace them in Arduino IDE earlier than compiling and importing the code to the Arduino board.

A PCB format for Arduino real-time clock with temperature show is proven in Fig. 7 and its parts format in Fig. 8.

PCB layout for real-time clock with temperature display
Fig. 7: PCB format for real-time clock with temperature show
Fig. 8: Parts format of the PCB

Obtain PCB and Element Format PDFs: click here

Obtain Source Code

After assembling the circuit on the PCB, join Arduino Uno pins to PCB utilizing jumper wires. Don’t forget to add the supply code into the Arduino Uno board earlier than wiring. The circuit works with 230V AC mains utilizing the transformer (X1), as proven within the circuit.


Pamarthi Kanakaraja is an assistant professor (R&D cell) at KL College, Vaddeswaram, Guntur district, Andhra Pradesh.

Dr Ok Sarat Kumar is a professor at KL College. He’s additionally one of many technical members from KL College, offering technical assist on RF antenna designs to NARL (Nationwide Atmospheric Analysis Laboratory). He has 22 years of labor expertise in RF antenna designing, testing and simulation in a real-time atmosphere.