int ledPin = 8; // Digital pin connected to the LED
float temperatureThreshold = 30.0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Simulate temperature (replace this with real sensor data)
float temperature = random(20, 35); // Random temperature between 20°C and 34.9°C
// Check if the temperature exceeds the threshold
if (temperature >= temperatureThreshold) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
// Print temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(2000); // Delay for 2 seconds between readings
}