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