int tempSensor = A0; // temperature sensor connected to A0
int motionSensor = 2; // motion sensor connected to pin 2
int ledPin = 3; // LED connected to pin 3
int buzzerPin = 4; // Buzzer connected to pin 4
void setup() {
pinMode(tempSensor, INPUT);
pinMode(motionSensor, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int temperature = analogRead(tempSensor); // read the temperature sensor value
int motion = digitalRead(motionSensor); // read the motion sensor value
if (temperature > 25) { // if temperature is higher than 25 degrees Celsius
digitalWrite(ledPin, HIGH); // turn on the LED
tone(buzzerPin, 1000, 500); // play a tone on the buzzer for 500ms
Serial.println("Temperature is too high!");
} else {
digitalWrite(ledPin, LOW); // turn off the LED
noTone(buzzerPin); // stop playing the tone on the buzzer
}
if (motion == HIGH) { // if motion is detected
Serial.println("Motion detected!");
delay(1000); // wait for a second before detecting motion again
}
}