CCCPaste

Single Threshold Code

const int sensorPin = A0;
const int outputPin = 9;

const float threshold = 75.0; // Single threshold in degrees Celsius

void setup() {
  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin, LOW);
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(sensorPin);  
  float temperature = (sensorValue * 5.0 / 1023.0) * 100.0;
  
  Serial.print("Temperature: ");
  Serial.println(temperature);

  if (temperature >= threshold) {
    digitalWrite(outputPin, HIGH);  // Turn on fan/LED
  } else {
    digitalWrite(outputPin, LOW);   // Turn off fan/LED
  }

  delay(500); 
}