#include <DHT.h>//Adafruits lib
#include <LiquidCrystal.h>
DHT dht(22, DHT22); //D7
// LiquidCrystal lcd(D0,D1,D2,D3,D4,D5);
LiquidCrystal lcd(12, 14, 27, 26, 25, 33); // LCD pins: RS, E, D4, D5, D6, D7
void setup() {
Serial.begin(9600);
pinMode(23, OUTPUT); //D8
dht.begin();
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.clear(); // Clear the LCD screen
}
void loop() {
delay(2000); // Delay to allow sensor to stabilize
float temp = dht.readTemperature(); // Read temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println("°C");
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0); // Set cursor to first column, first row
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" °C");
if (temp >= 20) {
digitalWrite(23, HIGH); // Turn on the LED
lcd.setCursor(0, 1); // Set cursor to first column, second row
lcd.print("Alert!");
} else {
digitalWrite(23, LOW); // Turn off the LED D8
}
}