#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the pins
#define DHTPIN 2 // Pin where the DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
float currentTemp = 0.0;
float desiredTemp = 25.0; // Default desired temperature
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Initialize the LCD (address 0x27, 16 columns and 2 rows)
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// Start the DHT sensor
dht.begin();
// Initialize the LCD
lcd.clear();
lcd.init();
lcd.backlight(); // Turn on the backlight
// Print initial message on the LCD
lcd.setCursor(4, 0);
lcd.print("PV");
lcd.setCursor(12, 0);
lcd.print("SV");
//lcd.setCursor(2,03);
//lcd.print("Temp & Humidity");
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read temperature as Celsius
float humidity = dht.readHumidity();
currentTemp = dht.readTemperature(); // Celsius
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(currentTemp)) {
lcd.setCursor(0, 1);
lcd.print("Error reading!");
return;
}
// Display the temperature and humidity on the LCD
lcd.setCursor(0, 1);
lcd.print("T: ");
lcd.print(currentTemp);
lcd.setCursor(17, 1);
lcd.print("'C");
lcd.setCursor(0, 2);
lcd.print("H: ");
lcd.print(humidity);
lcd.setCursor(17, 2);
lcd.print(" %");
}