#include "DHTesp.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int DHT_PIN = 15;
const int LED_PIN = 2; // Define the pin for the LED
DHTesp dhtSensor;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
lcd.init();
lcd.backlight();
pinMode(LED_PIN, OUTPUT); // Set the LED pin as output
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
// Print data to the serial monitor
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
// Display data on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TEMP: " + String(data.temperature, 2) + "C");
lcd.setCursor(0, 1);
lcd.print("HUM: " + String(data.humidity, 1) + "%");
// Blink the LED
digitalWrite(LED_PIN, HIGH); // Turn the LED on
delay(500); // Wait for 500 milliseconds
digitalWrite(LED_PIN, LOW); // Turn the LED off
delay(500); // Wait for 500 milliseconds
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}