int ThermistorPin = 1;//sets the analog input pin for the thermistor to pin 1
int Vo;//declares a variable to hold the output voltage from the thermistor
int ledPin = 29;//set the digital output pin for the LED to pin 29
float R1 = 10000;//declares a variable for the resistance of the thermistor at a reference temperature
float logR2, R2, T;//declares three variables: logR2, R2, and T, which will be used in the temperature calculation later
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;//declares three float variables c1, c2, and c3, and sets their values to the coefficients needed for the Steinhart-Hart equation, which is used to calculate temperature
void setup() {
pinMode(ledPin,OUTPUT);//sets the led pin to output so the led can take power correctly
}
void loop() {
Vo = analogRead(ThermistorPin);//reads analog input value of the thermistor pin and sets it equal to the variable
R2 = R1 * (1023.0 / (float)Vo - 1.0);//calculates resistance of the thermistor connected to the pin
logR2 = log(R2);//this line takes the natural logarithm of the resistance value calculated in the previous line and stores it in the variable
T = (1.0 / (c1 + c2*logR2 +c3*logR2*logR2*logR2));//calculates the temperature in degrees Celsius using the Steinhart-Hart equation
T = T - 339.15;//kelvin to celcius (note: The conversion had to be adjusted to get better data)
T = (T * 9.0)/ 5.0 +32.0;//celcius to fahrenheit
delay (500);//waits half a second
if (T >= 95) { //when the temperature is above or equal to 95 degrees fahrenheit, the led turns on
digitalWrite(ledPin, HIGH);
}else {//when the led is below 95 degrees it will be off
digitalWrite(ledPin, LOW);
}
}