const float BETA = 3950;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(12, OUTPUT);
}
void loop() {
int analogValue = analogRead(35);
float celsius = 1 / (log(1 / (4096. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15; //ESP 32
//float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15; //Arduino
// ESP 32 has ADC with 12 bit resolution. Range(0 - 4096). Resolution = (2^12 - 1)
// Arduino has ADC with 10 bit resolution. Range(0 - 1023). Resolution = (2^10 - 1)
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
if(celsius > 35)
{
digitalWrite(12, HIGH);
}
else{
digitalWrite(12, LOW);
}
delay(500);
}