#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define l1 6
#define l2 5
#define l3 4
#define l4 3
#include<Wire.h>
//#include<SPI.h>
//#include<Adafruit_SH1106.h>
//Adafruit_SH1106 OLED(-1);
#include<Adafruit_GFX.h>//Wokwi
#include<Adafruit_SSD1306.h>//Wokwi
Adafruit_SSD1306 OLED(128,64,&Wire,-1);//Wokwi
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
OLED.begin(SSD1306_SWITCHCAPVCC,0x3c);//Wokwi
}
void loop() {
OLED.clearDisplay();
OLED.setTextColor(WHITE,BLACK);
OLED.drawRect(2,2,126,62,WHITE);
OLED.drawLine(2,32,126,32,WHITE);
OLED.drawLine(2,48,126,48,WHITE);
OLED.drawLine(2,18,126,18,WHITE);
OLED.drawLine(63,2,63,62,WHITE);
OLED.setCursor(6,7);
OLED.setTextSize(1);
OLED.print("Temp");
OLED.setCursor(6,22);
OLED.setTextSize(1);
OLED.print("Humunity");
OLED.setCursor(6,38);
OLED.setTextSize(1);
OLED.print("HeatIndex");
OLED.setCursor(6,52);
OLED.setTextSize(1);
OLED.print("Alarm");
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
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"));
OLED.setCursor(70,7);
OLED.setTextSize(1);
OLED.print(t);
OLED.print(" C");
OLED.setCursor(70,22);
OLED.setTextSize(1);
OLED.print(h);
OLED.print(" %");
OLED.setCursor(70,38);
OLED.setTextSize(1);
OLED.print(hic);
OLED.print(" C");
if(hic<=27){
digitalWrite(l4,1);
digitalWrite(l3,0);
digitalWrite(l2,0);
digitalWrite(l1,0);
OLED.setCursor(70,52);
OLED.setTextSize(1);
OLED.print("OK");
OLED.display();
}
else if(hic<=32){
digitalWrite(l4,0);
digitalWrite(l3,1);
digitalWrite(l2,0);
digitalWrite(l1,0);
OLED.setCursor(70,52);
OLED.setTextSize(1);
OLED.print("Caution");
OLED.display();
}
else if(hic<=41){
digitalWrite(l4,0);
digitalWrite(l3,0);
digitalWrite(l2,1);
digitalWrite(l1,0);
OLED.setCursor(70,52);
OLED.setTextSize(1);
OLED.print("Extreme");
OLED.display();
}
else if(hic>41){
digitalWrite(l4,0);
digitalWrite(l3,0);
digitalWrite(l2,0);
digitalWrite(l1,1);
OLED.setCursor(70,52);
OLED.setTextSize(1);
OLED.print("Danger");
OLED.display();
}
delay(2000);
}