const int thermistorPin = A0; // Thermistor Pin
const int ledPin = 8; // LED out pin
const float R1 = 100000.0; // R1 resistance in series with thermistor
const float Vcc = 5.0; // Vcc voltage
const float beta = 4250.0; // Beta of the thermistor
const float T0 = 298.2; // Thermal difference from Kelvin to Celcius
const float R0 = 100000.0; // Thermistor resistance at 25°C
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Define LED as output
}
void loop() {
int analogValue = analogRead(thermistorPin); // Read analog value from thermistor
float voltage = Vcc * ((analogValue)/ 1023.0); // Convert to 0-5 volts
float Rt = (voltage*R1)/(Vcc - voltage);
float Tc = (1/((log(Rt/R0)/beta)+(1/T0))) - 273.2; // Calculate the thermistor resistance
if (Tc > 30) { // Change LED state if
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
// Print the values
Serial.print(analogValue);
Serial.print(";");
Serial.print(voltage, 2);
Serial.print(";");
Serial.print(Rt, 2);
Serial.print(";");
Serial.println(Tc, 2);
delay(random(500, 2500)); // Delay for 0.5-2.5 seconds
}