#include <DHT.h>
#include <LiquidCrystal.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
float temp = 0;
float sum = 0;
int count = 0;
void setup() {
Serial.begin(9600);
dht.begin();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Temp:");
lcd.setCursor(7,0);
lcd.print("0.0C");
}
void loop() {
sum += dht.readTemperature();
count++;
if (count == 10) { // tính trung bình nhiệt độ sau khi đã lấy 10 giá trị
temp = sum / count;
lcd.setCursor(7,0);
lcd.print(temp);
lcd.print("C");
sum = 0;
count = 0;
}
delay(2000); // đợi 2 giây trước khi lấy giá trị tiếp theo
}