const int ledPin = 6; // Pin where the LED is connected
const int threshold = 25; // Temperature threshold to turn on the LED
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
String input = Serial.readStringUntil('\n'); // Read the incoming string
input.trim(); // Remove extra whitespace
int temp = input.toInt(); // Convert the string to an integer
if (temp >= threshold) { // If temperature is above or equal to threshold
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("LED is ON"); // Print confirmation
} else { // If temperature is below threshold
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.println("LED is OFF"); // Print confirmation
}
}