// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int fan = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(fan, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("temp");
lcd.setCursor(0, 1);
lcd.print("humi");
dht.begin();
}
void loop() {
delay(2000);
// Read temperature in Celsius
float temperature = dht.readTemperature();
// Read humidity
float humidity = dht.readHumidity();
// Check if any reads failed
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if(temperature >= 25){
digitalWrite(fan, HIGH);
}
// Print temperature and humidity to the serial monitor
lcd.setCursor(7, 0);
lcd.print(temperature);
lcd.print("C");
lcd.setCursor(7, 1);
lcd.print(humidity);
lcd.print("%");
}