#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
const int DHT_PIN = 15;
const int buzzer_pin= 32;
DHTesp dhtSensor;
void temperature(void * parameter){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
if(data.temperature>43){
tone(buzzer_pin,1030);
delay(500);
noTone(32);
delay(200);
}
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(buzzer_pin, OUTPUT);
xTaskCreate(
temperature,
"check temperature",
1000,
NULL,
1,
NULL
);
}
void loop() {
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(3, 0);
lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Wokwi Online IoT");
}