const int tempPin = A0; // Temperature Sensor connected to A0
const int heaterPin = 13; // Heater simulated with LED on pin 13
const float lowerThreshold = 20.0; // Turn ON heater
const float upperThreshold = 25.0; // Turn OFF heater
bool heaterOn = false;
const float BETA = 3950;
void setup() {
pinMode(heaterPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(tempPin);
float temperature = 1 / (log(1 / (1023. / sensorValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C ");
if (temperature < lowerThreshold && !heaterOn) {
digitalWrite(heaterPin, HIGH);
heaterOn = true;
Serial.println("Heater ON");
} else if (temperature > upperThreshold && heaterOn) {
digitalWrite(heaterPin, LOW);
heaterOn = false;
Serial.println("Heater OFF");
}
delay(1000); // Delay for 1 second
}