#include "DHTesp.h"
#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include the library for the LCD2004 I2C display
const int DHT_PIN = 15;
DHTesp dhtSensor;
// Set the LCD address and dimensions (in this case, 20x4)
LiquidCrystal_I2C lcd(0x27, 20, 4); // Change the address to match your LCD's address
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the backlight
lcd.clear(); // Clear the LCD screen
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
String temperatureStr = "Temp: " + String(data.temperature, 2) + "°C";
String humidityStr = "Humidity: " + String(data.humidity, 1) + "%";
// Display temperature and humidity on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(temperatureStr);
lcd.setCursor(0, 1);
lcd.print(humidityStr);
lcd.setCursor(0, 2);
lcd.print("by arvind Patil");
lcd.setCursor(0, 3);
lcd.print("nandurbar india");
// Output to Serial for debugging
Serial.println(temperatureStr);
Serial.println(humidityStr);
Serial.println("---");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}