#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT22
#define BUZZER_PIN 15
#define TEMP_THRESHOLD 30
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
float temperature = 0;
float humidity = 0;
void readSensorTask(void *pvParameters) {
while (1) {
temperature = dht.readTemperature();
humidity = dht.readHumidity();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
void displayAndBuzzerTask(void *pvParameters) {
while (1) {
lcd.clear();
if (temperature > TEMP_THRESHOLD) {
digitalWrite(BUZZER_PIN, HIGH);
lcd.setCursor(0, 0);
lcd.print("High Priority");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
} else {
digitalWrite(BUZZER_PIN, LOW);
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(temperature);
lcd.setCursor(0, 1);
lcd.print("Hum:");
lcd.print(humidity);
}
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
void setup() {
dht.begin();
lcd.init();
lcd.backlight();
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
xTaskCreate(readSensorTask, "ReadSensor", 2048, NULL, 1, NULL);
xTaskCreate(displayAndBuzzerTask, "DisplayBuzzer", 2048, NULL, 1, NULL);
}
void loop() {
}