Hey guys, welcome to today’s tutorial. The need to measure time, to constantly know what the time of the day is, is something that will never get old, that’s why for today’s tutorial, we will be building an Arduino Real Time clock and temperature monitor using the big 3.2″ Color TFT display, the DS3231 Real time clock module, and the Arduino Due.

 

 

At the heart of today’s project is the DS3231 real time clock module which is being used to obtain the current time, date and the temperature of the environment. The DS3231 real time clock module has been used in several projects on this website mostly due to its accuracy and it’s low power requirement which means it can keep time accurately for a longer period than most of the other real-time clock (RTC) module. some of the features of the DS3231 RTC module are listed below.

One of the important things when designing electronic systems that have displays is ensuring that there is no flicker or lag when uploading information to the screen and one of the best ways to ensure that is to use a fast enough micro-controller, that’s why, for this project, we will be using the very fast Arduino Due development board. The Arduino Due has one of the fastest CPU speed in the family of Arduino development boards. The Due runs on an 84MHz CPU speed compared to the 16MHz CPU speed of the Arduino and as such, it is able to update the screen without any visible flickering.

Our goal for this project is to build a real-time clock with a user-friendly interface capable of displaying (without lag or Flickering) the current time, date, temperature including the minimum and maximum temperature measured over time.

Required Components/Parts and Where to Buy

The following components are needed to build this project, and as usual, they can be bought through the links in front of them.

  1. Arduino Due: https://educ8s.tv/part/ArduinoDue
  2. Arduino Mega: https://educ8s.tv/part/ArduinoMega
  3. 3.2″ Color TFT: https://educ8s.tv/part/32TFT
  4. DS3231 module: https://educ8s.tv/part/DS3231
  5. Header Pins: https://educ8s.tv`/part/HeaderPins
  6. Female Wires: https://educ8s.tv/part/Wires

The total cost for this project is around 24$. You need around 14$ for the Arduino Due, 8$ for the display and about 2$ for the RTC module.

[adsense]

Schematics

The 3.2″ TFT like most TFT displays comes as a shield which can be easily mounted on the Arduino Due thus male headers will be used (after bending them as shown in the video) to connect the RTC module to the Arduino as the Screen will cover all the GPIOs of the board when it is plugged in and this may make connecting jumper wires to the board difficult.

Connect the DS3231 to the Arduino as shown in the schematics below.

Schematics

The DS3231 is an I2C based device and needs to be connected to the SPI pins of the Arduino Due.

The connection between the Arduino and DS3231 RTC module is highlighted below.

DS3231 ▶ Arduino

VCC ▶ 3.3v

GND ▶ GND

SDA ▶ SDA

SCL ▶ SCL

Code

To program the Arduino to display time and temperature data alongside the GUI on the 3.2″ TFT display we will require two libraries. The first library is the Bodmer TFT HX8537 Arduino Due library for the TFT display which is a modified version of UTFT library because this display does not work directly with the UTFT library due to driver compatibility Issues, but the code should work for any other version of the display that supports the UTFT library. The second library that we will be using is the Sodaq DS3231 library to enable the Arduino interface easily with the DS3231. These libraries can be downloaded via the links below.

Libraries

Display library: https://github.com/Bodmer/TFT_HX8357_Due

DS3231 Library: https://github.com/SodaqMoja/Sodaq_DS3231

Install these libraries before launching the Arduino IDE to write the Code.

As usual, the first thing we do in the code is to include all the libraries that will be used which in this case are the two libraries mentioned above.

#include <TFT_HX8357_Due.h> // https://github.com/Bodmer/TFT_HX8357_Due
#include <Sodaq_DS3231.h>  //RTC Library https://github.com/SodaqMoja/Sodaq_DS3231

Next, we create some of the variables which will be used to store information in our code and create an instance of the HX8357 library.

float minTemperature = 100;
float maxTemperature = -40;
String dateString;
String hours;
int minuteNow=0;
int minutePrevious=0;

TFT_HX8357_Due tft = TFT_HX8357_Due();       // Invoke custom library

Next is the void setup function. We initiate communication with the RTC module then Intitalze the display setting our preferred orientation for the display and Displaying the UI.

void setup()
{  
  rtc.begin();

  tft.init();
  tft.setRotation(1);
  tft.fillScreen(0xC618);
  delay(100);
  printUI();
  
}

With this done, we then move to the void loop function. Under this function, we write the code to update all the parameters on the display including the min temperature, the max temperature, the time and the date.

void loop()
{
   float temperature = rtc.getTemperature();
   getAndPrintTime();
   printTemperature(temperature);
   if(temperature>maxTemperature)
  {
    maxTemperature = temperature;
    updateMaxTemperature();
  }
  if(temperature<minTemperature)
  {
    minTemperature = temperature;
    updateMinTemperature();
  }

 delay(1000);

}

 

——————–

CODE OF THE PROJECT
——————–

 

 

 

Upload the code to the Arduino, and you should see the screen come up with the time and temperature as shown in the image below.

That’s it for today’s Arduino Real Time clock tutorial, thanks for reading/watching. If you get stuck at any point while building this project, feel free to reach out to me, will be glad to answer whatever questions you might have. Don’t forget to share, like and subscribe on youtube. Thanks!

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv