const int irSensorPin = 2; // Pin for the IR sensor output
const int ledPin = 9; // Pin for the LED
const int buzzerPin = 10; // Pin for the Buzzer (optional)
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = digitalRead(irSensorPin); // Read the IR sensor
if (sensorValue == HIGH) { // Fire detected
digitalWrite(ledPin, HIGH); // Turn LED on
digitalWrite(buzzerPin, HIGH); // Turn Buzzer on
Serial.println("Fire detected!");
} else { // No fire detected
digitalWrite(ledPin, LOW); // Turn LED off
digitalWrite(buzzerPin, LOW); // Turn Buzzer off
Serial.println("No fire detected.");
}
delay(1000); // Delay for stability
}