#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
int freq = 2000;
int channel = 0;
int resolution = 8;
const int red = 25;
const int green = 26;
const int blue = 27;
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define DHTPIN1 17
#define DHTPIN2 16
#define DHTPIN3 0
#define DHTPIN4 5
#define DHTPIN5 12
#define DHTTYPE DHT22
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);
DHT dht4(DHTPIN4, DHTTYPE);
DHT dht5(DHTPIN5, DHTTYPE);
void setup() {
Serial.begin(115200);
ledcSetup(channel, freq, resolution);
ledcAttachPin(22, channel);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_WHITE);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(2);
tft.println("");
tft.println("");
tft.println(" fire alarm");
tft.setTextColor(ILI9341_RED );
tft.setTextSize(2);
tft.print(" ssmiet ");
tft.print(" ");
tft.print(" ");
tft.print(" ");
tft.setTextColor(ILI9341_BLUE );
tft.setTextSize(2);
tft.print(" ece 2nd year ");
tft.print(" ");
tft.print(" ");
tft.print(" ");
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.print(" diso ");
delay(1000);
}
void loop() {
tft.setCursor(0, 0);
float h1 = dht1.readHumidity();
float t1= dht1.readTemperature();
float f1 = dht1.readTemperature(true);
if (isnan(h1) || isnan(t1) || isnan(f1))
float hif1 = dht1.computeHeatIndex(f1, h1);
float hic1 = dht1.computeHeatIndex(t1, h1, false);
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
float f2 = dht2.readTemperature(true);
if (isnan(h2) || isnan(t2) || isnan(f2))
float hif2 = dht2.computeHeatIndex(f2, h2);
float hic2= dht2.computeHeatIndex(t2, h2, false);
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature();
float f3 = dht3.readTemperature(true);
if (isnan(h3) || isnan(t3) || isnan(f3))
float hif3 = dht3.computeHeatIndex(f3, h3);
float hic3 = dht3.computeHeatIndex(t3, h3, false);
float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature();
float f4 = dht4.readTemperature(true);
if (isnan(h4) || isnan(t4) || isnan(f4))
float hif4 = dht4.computeHeatIndex(f4, h4);
float hic4 = dht4.computeHeatIndex(t4, h4, false);
float h5 = dht5.readHumidity();
float t5 = dht5.readTemperature();
float f5 = dht5.readTemperature(true);
if (isnan(h5) || isnan(t5) || isnan(f5))
float hif5 = dht5.computeHeatIndex(f5, h5);
float hic5 = dht5.computeHeatIndex(t5, h5, false);
if((t1<25)&&(t2<25)&&(t3<25)&&(t4<25)&&(t5<25))
{
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(4);
tft.setCursor(0,0);
tft.println(" Temperature is Normal");
digitalWrite(blue, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(10000);
}
if(((t1>25)&&(t2>25)&&(t3>25)&&(t4>25)&&(t5>25))&&((t1<40)&&(t2<40)&&(t3<40)&&(t4<40)&&t5<40)){
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.setCursor(0,0);
tft.println(" Tempertaure is Moderate");
digitalWrite(blue, HIGH);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
delay(10000);
}
if(t1>40||t2>40||t3>40||t4>40||t5>40){
for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle=dutyCycle+10){
Serial.println(dutyCycle);
ledcWrite(channel, dutyCycle);
tft.fillScreen(ILI9341_WHITE);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(4);
tft.setCursor(0,0);
tft.println(" Fire Detected");
digitalWrite(blue, LOW);
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
delay(1000);
}
}
}