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.
- Arduino Due:Â https://educ8s.tv/part/ArduinoDue
- Arduino Mega:Â https://educ8s.tv/part/ArduinoMega
- 3.2″ Color TFT:Â https://educ8s.tv/part/32TFT
- DS3231 module:Â https://educ8s.tv/part/DS3231
- Header Pins:Â https://educ8s.tv`/part/HeaderPins
- 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.
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
Hello Nick,
I have built this project and i’m very pleased with it except that I have noticed a strange issue that I cannot explain : sometimes on the display of the time 59 seconds appear despite it is not foreseen in the code. I’m using your original code except for the name of the day that I translated into french ?
Have you en idea, is that a bug of the library ?
Here is a picture of the screen : http://jmguitard.com/pub/horloge_arduino_issue_sec_1024.jpg
Thanks in advance
Jean-Marie
Hello Jean-Marie,
It’s really nice to see that someone has built my project. That’s why I created the YouTube channel, and it feels great when I see that my videos are somehow helpful.
About your project, it’s really strange, I haven’t noticed it at all. I will take another look at the code, and I will let you know.
Thanks!
Hello Nick
Because I appear this error message when compiling the cadigo!!
exit status 1
‘HX8357C’ was not declared in this scope
Thanks
I have uploaded a new version of the code that uses another library. It should work fine now.
Hi friends
How to make digital thermometer which can creates – 40 degree to +99 degree digital water heater for winter cum cold water for summer…
So we can develop Water Temperature Monitor LED Display Water Flow Shower Thermometer
Can you please provide me Video & its small
Hello friends..
Test the code Because I appear this error message when compiling the code!!
exit status 1
‘HX8357C’ was not declared in this scope
Please replay how to fix this issue..
Thanks & Regards,
Vishwas Mathew
Please download the correct library for the display from Banggood.com. The UTFT library does not support the display, you need a modified version of it that can be downloaded from Banggood.com
Hello Nick,
I compiling this Arduino Real Time Clock and temperature Monitor with 3.2″ Color TFT display code. But this error message appear this when compiling the code!!
exit status 1
‘HX8357C’ was not declared in this scope” Please help and fix the problems
Thanks & Regards,
vishwas Mathew
I have uploaded a new version of the code that uses another library. It should work fine now.
Hello Nick
In banggood.com,no find driver for this LCD
Could here to download
Thanks & Regards,
You are right, banggood has removed the driver file. You can download another library for this display here: https://github.com/Bodmer/TFT_HX8357
I will re-write the code to support this library soon.
Thank you Nick
Wait for updating the code, I already tried with the current and not working
No it won’t work out of the box. The new library works with the display. But I have to re-write the code for the new library.
Thank you, I’m waiting
I have uploaded a new version of the code that uses another library. It should work fine now.
Anyou update on the code
I have uploaded a new version of the code that uses another library. It should work fine now.
I cannot compile it. I get a error with “no such file or directory” what could i do? can you upload a zip with the ready files to upload it to a Arduino?
Hi.how can I change the time and date
What changes should I make in the code to run this with Arduino Mega? Please help.
Thanks to my good friend for this very useful tutorial. I have a problem, when the time changes, the posts overlap. Can you help us?
Thank you for your success
Hi, how to set date and time?
In the line 28-//setRTCTime();—- setRTCTime();