Arbin fipel
Published

Air Quality & Temperature Monitoring

A DIY project with simply modules , this device can be seen as an indicator for measurement of the temperature and air quality indoor .

IntermediateWork in progress1,451
Air Quality & Temperature Monitoring

Things used in this project

Hardware components

DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Gas Sensors MQ135
×1
RTC DS3231
×1
Buzzer
Buzzer
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
LCD TFT HX8357
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Source Code

I would be happy if you can give some crtitics , or any rekomendation for developing my project

Code

Source Code

Arduino
I would be happy if you can give some crtitics , or any rekomendation for developing my project
   //////////////////////////////////////////////
  //        3.2" Color RTC PROJECT            //
 //                                          //
//           http://www.educ8s.tv           //
/////////////////////////////////////////////

#include <TFT_HX8357.h>     // https://github.com/Bodmer/TFT_HX8357_Due
#include <Sodaq_DS3231.h>   // RTC Library https://github.com/SodaqMoja/Sodaq_DS3231
#include <DHT.h>            // Tempreature & Humidity Sensor

#define DHTPIN    A0
#define DHTTYPE   DHT22
#define TFT_LIGHTGREY   0xC618
#define TFT_COLOR1      0x0640
#define TFT_YELLOW      0x001C
#define TFT_BLUE        0xDB20

DHT dht(DHTPIN, DHTTYPE);
TFT_HX8357 tft = TFT_HX8357();

int airTemperature = 100;
int airHumidity = -40;
int airQuality = 0;
String dateString;
String hours;
int minuteNow=0;
int minutePrevious=0;
const int buzzer = 8;

void setup()
{  
  rtc.begin();
  Serial.begin(9600);
  tft.init();
  tft.setRotation(3);
  tft.fillScreen(TFT_LIGHTGREY);
  printUI();
  pinMode(buzzer, OUTPUT);
}
void loop()
{
   float temperature_value = dht.readTemperature();
   float humidity_value = dht.readHumidity();
   float quality_value = analogRead(A1);

   airTemperature = (int) temperature_value;
   airHumidity    = (int) humidity_value;   
   airQuality     = (int) quality_value;

   getAndPrintTime();
   printAirQuality(airQuality);
   printAirHumidity(airHumidity);
   printAirTemperature(airTemperature);

   if( airQuality > 300 ) buzz( (int) airQuality/100 );
   delay(1000);
}
void buzz(int num) {
  int i;
  for(i = 0; i < num; i++) {
    tone(buzzer, 5000);
    delay(100);
    noTone(buzzer);
    delay(100);
  }
}

void printUI()
{ 
 printDateRectangle(); 
 printAirQualityRectangle();
 printTemperatureRectangle();
 printAirHumidityRectangle();
}

void printDateRectangle()
{
  tft.fillRect(40, 7, 400,60, 0xA000);
  tft.fillRect(40, 5, 400,53, TFT_RED);
}
void printAirQualityRectangle()
{
  tft.fillRect(80, 90, 320, 125, 0x03C0);
  tft.fillRect(80, 90, 320, 120, 0x0640);
  tft.setCursor(250,130);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(10);
  tft.print("PPM");

  // tft.setCursor(300,130);
  // tft.setTextColor(TFT_WHITE);
  // tft.setTextSize(3);
  // tft.print("o");
  }
void printTemperatureRectangle()
{
  tft.fillRect(40, 251, 160, 59, 0x0015);
  tft.fillRect(40, 251, 160, 55, TFT_YELLOW);

  tft.setCursor(165,265);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(4);
  tft.print("C");
  tft.setCursor(150,258);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.print("o");
}
void printAirHumidityRectangle()
{
  tft.fillRect(280, 251, 160, 59, 0x8200);
  tft.fillRect(280, 251, 160, 55, TFT_BLUE);

  tft.setCursor(400,265);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(4);
  tft.print('%');
}
void getAndPrintTime()
{
   DateTime now = rtc.now(); //get the current date-time
   Serial.print(now.year(), DEC);
   minuteNow = now.minute();
   if(minuteNow!=minutePrevious)
   {
      dateString = getDayOfWeek(now.dayOfWeek())+" ";
      dateString = dateString+String(now.date())+"/"+String(now.month());
      minutePrevious = minuteNow;
      hours = String(now.hour());
    if(now.minute()<10)
    { hours = hours+":0"+String(now.minute());
    } else
    { hours = hours+":"+String(now.minute());
    } printTime();
    }
}
void printTime()
{
  String dateAndTime = dateString+" "+hours;
  tft.setTextSize(2);
  char charBuf[25];
  dateAndTime.toCharArray(charBuf, 25);
  
  tft.setTextColor(TFT_WHITE, TFT_RED);
  tft.drawCentreString(charBuf,240,15,2);
}
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;
  }
}
void printAirQuality(float value)
{
  String Temperature;
  Temperature = String(value,0); 
  tft.setTextSize(6);
  tft.setCursor(110,130);
  tft.setTextColor(TFT_WHITE, TFT_COLOR1);
  tft.print(Temperature);
}
void printAirTemperature(float value)
{
  String Temperature;
  Temperature = String(value,0); 
  tft.setTextSize(3);
  tft.setCursor(80,270);
  tft.setTextColor(TFT_WHITE, TFT_YELLOW);
  tft.print(Temperature); 
}
void printAirHumidity(float value)
{
  String Temperature;
  Temperature = String(value,0); 
  tft.setTextSize(3);
  tft.setCursor(320,270);
  tft.setTextColor(TFT_WHITE, TFT_BLUE);
  tft.print(Temperature);
}

Credits

Arbin fipel

Arbin fipel

1 project • 1 follower
Computer Science , Tech geek , Quick adapting with IoT developing

Comments