#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "DHT.h"
#define DHTPIN 16
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define TFT_DC 2
#define TFT_CS 27
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
dht.begin();
tft.begin();
tft.setRotation(0);
}
void loop() {
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
tft.fillScreen(ILI9341_WHITE);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("DHT SENSOR");
tft.setTextColor(ILI9341_RED);
tft.setTextSize(2);
tft.println(" ");
tft.println(" ");
tft.print(F("Humidity: "));
tft.print(h);
tft.print(F("%"));
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(2);
tft.println(" ");
tft.println(" ");
tft.print(F("Temp: "));
tft.print(t);
tft.print((char)223);
tft.print("C");
// tft.setTextColor(ILI9341_GREEN);
// tft.setTextSize(2);
// tft.println(" ");
// tft.println(" ");
// tft.println(" ");
// tft.println(" ");
// tft.print("ECE-2024");
delay(1000);
}