const float BETA = 3950; // should match the Beta Coefficient of the thermistor
const int sensorPin = A0;
const int ledPin = 8;
int analogValue;
float celsius;
void setup()
{
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
analogValue = analogRead(A0);
celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
if(celsius > 45)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}