#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
hd44780_I2Cexp lcd;
const int pirPin = 33;
const int ldrPin = 34;
const int tempPin = 32;
const int buzzerPin = 26;
const int ledPin = 2;
const float tempHighThreshold = 80;
const int ldrLightThreshold = 800;
void setup() {
lcd.begin(16, 2, 0x27);
lcd.init();
lcd.backlight();
pinMode(pirPin, INPUT);
pinMode(ldrPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int pirState = digitalRead(pirPin);
int ldrValue = analogRead(ldrPin);
int tempValue = analogRead(tempPin);
float temperature = map(tempValue, 0, 1023, -20, 100);
if (pirState == HIGH) {
lcd.setCursor(0, 1);
lcd.print("object detected");
tone(buzzerPin, 1000, 500);
}
else {
lcd.setCursor(0, 1);
lcd.print(" ");
noTone(buzzerPin);
}
if (ldrValue > ldrLightThreshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
if (temperature < tempHighThreshold) {
lcd.setCursor(0, 0);
lcd.print("High Temperature");
tone(buzzerPin, 2000, 500);
}
else {
lcd.setCursor(0, 0);
lcd.print("Temperature Ok ");
}
Serial.print("LDR Value: ");
Serial.print(ldrValue);
Serial.print("\tTemperature: ");
Serial.print(temperature);
Serial.print(" C\tPIR State: ");
Serial.println(pirState);
delay(1000);
}