int tempSensorPin = A0;
int lightSensorPin = A1;
int ledPin = 7;
int buzzerPin = 8;
int pirState=LOW;
int inputPin=2;
int val=0;
int tempThreshold = 25; // change this to the threshold temperature value you want
int lightThreshold = 500; // change this to the threshold light value you want
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
}
void loop() {
int tempValue = analogRead(tempSensorPin);
int lightValue = analogRead(lightSensorPin);
Serial.print("Temperature: ");
Serial.print(tempValue);
Serial.print(" Light: ");
Serial.println(lightValue);
val=digitalRead(inputPin);
if(val==HIGH){
digitalWrite(ledPin, HIGH);
if(pirState==LOW){
Serial.println("Motion detected!");
pirState=HIGH;
}
else{
digitalWrite(ledPin, LOW);
if(pirState==HIGH){
Serial.println("Motion ended!");
pirState=LOW;
}
}
if (tempValue > tempThreshold || lightValue > lightThreshold) {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000, 500);
} else {
digitalWrite(ledPin, LOW);
noTone(buzzerPin);
}
delay(1000);
}
}