Temperature Monitoring and Display System

The Temperature Monitoring and Display System is a specially created project in order to carry out the function of real time monitoring purposes of environmental temperatures followed by displaying this information in form of real images. The mixture of highly-precise sensors and advanced display tech allows for visual temperature readings even with the promises of prompt reporting of the highest as well as lowest temperature of the day in addition. The all- in-one sensor is designed for versatility and used in home environment, educational establishment, laboratories, and everywhere admit the need for accurate thermal surveillance.

This project gives a practical course where not only students observe, but get an experience, and as a usefull tool for quality control when specific conditions maintenance is compulsory. Carrying both usefulness and educational values, the “Real-Time Temperature Monitoring and Display System” is composed of several commonly available electronic components that can be combined to put to use in a variety of monitoring needs. The system’s proper foundation is provided with ample room for customization and expansion for future adventurous explorations.

Components:

Connections:

  • Display (ILI9341) to Arduino: You need to connect the defined pins for the display (TFT_DC, TFT_CS, TFT_RST, TFT_MISO, TFT_MOSI, TFT_CLK) to the corresponding pins on the Arduino. The exact pin numbers are defined in your code and should match the physical connections.
  • RTC Module (DS3231) to Arduino: The DS3231 uses an I2C interface, which typically uses the SDA (data line) and SCL (clock line) pins on the Arduino. These are not explicitly defined in your code because the Wire.begin() call initializes the default I2C pins on your Arduino board. Ensure the SDA and SCL pins of the RTC module are connected to the corresponding I2C pins on your Arduino.
  • Power Connections: Both the display and the RTC module need to be powered. Make sure to connect the VCC and GND pins of these modules to the 5V and GND pins on your Arduino, respectively.
See also  Location GPS Tracker Meeo IoT

Additional Notes

Download the library

  • Adafruit GFX Library
  • Adafruit ILI9341 Library
  • Sodaq_DS3231

Code:

#include "Adafruit_GFX.h"     
#include "Adafruit_ILI9341.h" 
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include  <SPI.h>

#define TFT_DC 9              
#define TFT_CS 10             
#define TFT_RST 8             
#define TFT_MISO 12           
#define TFT_MOSI 11           
#define TFT_CLK 13          

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

float maxTemperature=0;
float minTemperature=200;
char charMinTemperature[10];
char charMaxTemperature[10];
char timeChar[100];
char dateChar[50];
char temperatureChar[10];

float temperature = 0;
float previousTemperature = 0;

uint32_t old_ts;

String dateString;
int minuteNow=0;
int minutePrevious=0;
  
void setup(){
  
  Serial.begin(9600);
  tft.begin();                      
  tft.setRotation(0);            
  tft.fillScreen(ILI9341_BLACK);

  Wire.begin();
  rtc.begin();

  printText("TEMPERATURE", ILI9341_GREEN,20,130,3);
  printText("MAX", ILI9341_RED,37,260,2);
  printText("MIN", ILI9341_BLUE,173,260,2);
 
  //setRTCTime();
}
 
void loop()
{
  float temperature = rtc.getTemperature();
  DateTime now = rtc.now(); //get the current date-time
  uint32_t ts = now.getEpoch();

    if (old_ts == 0 || old_ts != ts) {
  old_ts = ts;
  
  minuteNow = now.minute();
  if(minuteNow!=minutePrevious)
  {
    dateString = getDayOfWeek(now.dayOfWeek())+", ";
    dateString = dateString+String(now.date())+"/"+String(now.month());
    dateString= dateString+"/"+ String(now.year()); 
    minutePrevious = minuteNow;
    String hours = String(now.hour());
    if(now.minute()<10)
    {
      hours = hours+":0"+String(now.minute());
    }else
    {
      hours = hours+":"+String(now.minute());
    }
    
    hours.toCharArray(timeChar,100);
    tft.fillRect(50,50,135,40,ILI9341_BLACK);
    printText(timeChar, ILI9341_WHITE,55,55,4);
    dateString.toCharArray(dateChar,50);
    printText(dateChar, ILI9341_GREEN,8,5,2);
  }
  
  if(temperature != previousTemperature)
  {
    previousTemperature = temperature;
    String temperatureString = String(temperature,1);
    temperatureString.toCharArray(temperatureChar,10);
    tft.fillRect(50,175,150,40,ILI9341_BLACK);
    printText(temperatureChar, ILI9341_WHITE,50,180,4);
    printText("o", ILI9341_WHITE,158,175,3);
    printText("C", ILI9341_WHITE,180,180,4);

if(temperature>maxTemperature)
    {
      maxTemperature = temperature;
      dtostrf(maxTemperature,5, 1, charMaxTemperature); 
      tft.fillRect(8,280,90,28,ILI9341_BLACK);
      printText(charMaxTemperature, ILI9341_WHITE,8,290,2);
      printText("o", ILI9341_WHITE,70,280,2);
      printText("C", ILI9341_WHITE,85,290,2);
    }
if(temperature  < minTemperature) 

 {
      minTemperature = temperature;
      dtostrf(minTemperature,5, 1, charMinTemperature); 
      tft.fillRect(145,280,90,28,ILI9341_BLACK);
      printText(charMinTemperature, ILI9341_WHITE,145,290,2);
      printText("o", ILI9341_WHITE,207,280,2);
      printText("C", ILI9341_WHITE,222,290,2);
    }
  }
}
    delay(1000);
}

void setRTCTime()
{
  DateTime dt(2018, 4, 2, 13, 13, 30, 1); // Year, Month, Day, Hour, Minutes, Seconds, Day of Week
  rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above 
}

void printText(char *text, uint16_t color, int x, int y,int textSize)
{
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextSize(textSize);
  tft.setTextWrap(true);
  tft.print(text);
}

String getDayOfWeek(int i)
{
  switch(i)
  {
    case 1: return "Monday";break;
    case 2: return "Tuesday";break;
    case 3: return "Wednesday";break;
    case 4: return "Thursday";break;
    case 5: return "Friday";break;
    case 6: return "Saturday";break;
    case 7: return "Sunday";break;
    default: return "Monday";break;
  }
}

QUICK LINKS