#include <DHT.h>
#include <DHT_U.h>
// Digital pin connected to the DHT sensor
const int DHTPIN = 18;
//TYPE of DHT sensor
const char DHTTYPE = DHT22;
//LED lights
const int RedLED = 14;
const int GreenLED =12;
//Threshholds
float hthresh = 70;
float tthresh = 40;
// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(DHTPIN,INPUT);
pinMode(RedLED,OUTPUT);
pinMode(GreenLED, OUTPUT);
dht.begin();
Serial.begin(115200);
delay(2000);
Serial.println("Gooday User");
delay(1);
Serial.println("DHT22 test");
delay(2000);
Serial.print("Humidity Threshold is:");
Serial.print(hthresh);
Serial.println("%");
delay(2000);
Serial.print("Temperature Threshhold is:");
Serial.print(tthresh);
Serial.println("°C");
delay(2000);
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
delay(2000);
Serial.print("Humidity is: ");
Serial.print(h);
Serial.println("%");
delay(2000);
if(h> hthresh) {
digitalWrite(GreenLED,HIGH);
Serial.println("Humidity above threshold");
delay(1000);
}
else{
digitalWrite(GreenLED,LOW);
}
Serial.print("Temperature is: ");
Serial.print(t);
Serial.println("°C ");
delay(2000);
if(t>tthresh) {
digitalWrite(RedLED,HIGH);
Serial.println("Temperature above threshold");
delay(1000);
return;
}
else{
digitalWrite(RedLED,LOW);
}
}