#include <LiquidCrystal.h>
const int tempPin = A0;
const int lightPin = A1;
const int buttonPin = 2;
const int ledPin = 13;
float tempThreshold = 30.0;
int lightThreshold = 500;
volatile bool interruptFlag = false;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), handleInterrupt, FALLING);
lcd.begin(16, 2);
lcd.print("Temp: ");
lcd.setCursor(0, 1);
lcd.print("Light: ");
}
void loop() {
int tempValue = analogRead(tempPin);
int lightValue = analogRead(lightPin);
float temperature = (tempValue * 5.0 * 100.0) / 1024.0;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Light Level: ");
Serial.println(lightValue);
// Update LCD display
lcd.setCursor(6, 0);
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(7, 1);
lcd.print(lightValue);
// Check if temperature exceeds threshold
if (temperature > tempThreshold) {
Serial.println("Temperature threshold exceeded!");
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
// Check if light level exceeds threshold
if (lightValue > lightThreshold) {
Serial.println("Light threshold exceeded!");
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
if (interruptFlag) {
Serial.println("Interrupt detected!");
lcd.setCursor(0, 0);
lcd.print("Interrupt! ");
interruptFlag = false;
}
delay(1000);
}
void handleInterrupt() {
interruptFlag = true;
}