const int lm35Pin = A0;
const int buzzerPin = 2;
const int ledPin = 3;
void setup()
{
pinMode(lm35Pin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// Read the temperature from the LM35 sensor
int sensorValue = analogRead(lm35Pin);
// Convert the analog reading to temperature in degrees Celsius
float temperature = (sensorValue * 0.48876);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Set a threshold temperature value for detecting fire (adjust as needed)
if (temperature > 30.0) {
// Activate the buzzer and LED
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(2000); // Alert for 2 seconds
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}
delay(2000); // Read temperature every 5 seconds
}