#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHT_PIN 2
#define DHT_TYPE DHT22 // Type of the DHT sensor
#define TEMP_LED_PIN 12 // Pin connected to the LED for temperature control
#define LDR_LED_PIN 13 // Pin connected to the LED for light level control
#define LDR_PIN 34 // Pin connected to the LDR
DHT dht(DHT_PIN, DHT_TYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns, 2 rows
void setup() {
Serial.begin(115200);
dht.begin();
lcd.init(); // Initialize the LCD
lcd.begin(16, 2);
lcd.backlight(); // Uncomment if your LCD has backlight control
pinMode(TEMP_LED_PIN, OUTPUT);
pinMode(LDR_LED_PIN, OUTPUT);
pinMode(LDR_PIN, INPUT);
}
void loop() {
delay(2000); // Wait for 2 seconds between readings
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int lightLevel = analogRead(LDR_PIN);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Light Level: ");
Serial.println(lightLevel);
// Control the LEDs based on the temperature and light level
if (temperature > 34.0) {
digitalWrite(TEMP_LED_PIN, HIGH); // Turn on the temperature control LED
} else {
digitalWrite(TEMP_LED_PIN, LOW); // Turn off the temperature control LED
}
if (lightLevel > 1300) {
digitalWrite(LDR_LED_PIN, HIGH); // Turn on the light level control LED
} else {
digitalWrite(LDR_LED_PIN, LOW); // Turn off the light level control LED
}
}