#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16x2 display
const int lm35Pin = A0; // LM35 sensor pin
const int ledPin = 9; // LED pin
const int buzzerPin = 10; // Buzzer pin
const int resetButtonPin = 7; // Reset button pin
bool alarmActive = false; // Flag to track if the alarm is active
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(resetButtonPin, INPUT_PULLUP);
}
void loop() {
float tempC = analogRead(lm35Pin) * 0.488; // Convert analog reading to Celsius
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC);
lcd.print(" C");
if (tempC > 35.0 && !alarmActive) {
lcd.setCursor(0, 1);
lcd.print("WARNING: High Temp");
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000); // Sound the buzzer
alarmActive = true;
} else if (tempC <= 35.0 && alarmActive) {
lcd.setCursor(0, 1);
lcd.print(" "); // Clear the warning message
digitalWrite(ledPin, LOW);
noTone(buzzerPin); // Stop buzzer
alarmActive = false;
}
if (digitalRead(resetButtonPin) == LOW) {
digitalWrite(ledPin, LOW);
noTone(buzzerPin); // Stop buzzer
}
delay(1000); // Update temperature reading every second
}