#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define pinDATA 5
#define pirsensor 13
#define ledpin 10


DHT dht(pinDATA, DHT22);
LiquidCrystal_I2C lcd1(0x27, 16, 2);
LiquidCrystal_I2C lcd2(0x33, 16, 2);

void setup() {
  pinMode(pirsensor, INPUT);
  pinMode(ledpin, OUTPUT);
  lcd1.init();
  lcd1.backlight();
  lcd2.init();
  lcd2.backlight();
  dht.begin();
}

void loop() {
  digitalWrite(ledpin, LOW); // Turn off the LED initially

  // Read PIR sensor
  int pirValue = digitalRead(pirsensor);

  if (pirValue == HIGH) {
    // Motion detected
    lcd1.setCursor(0, 0);
    lcd1.print("Motion detected");
    lcd2.clear();
    digitalWrite(ledpin, HIGH);
    delay(2000);
  } else {
    float t = dht.readTemperature();
    float h = dht.readHumidity();

    lcd1.clear();
    lcd2.clear(); // Clear the second display

    lcd1.setCursor(0, 0);
    lcd1.print("Temp: ");
    lcd1.print(t);
    lcd1.print(" C");

    lcd1.setCursor(0, 1);
    lcd1.print("Hum: ");
    lcd1.print(h);
    lcd1.print(" %");

   lcd2.setCursor(0,0);
   lcd2.print("Second Display");

    delay(2000);
  }
}