#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int NTC = A0;
float BETA = 3950;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.begin(16, 2);
}
float lastTemp;
void loop() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(NTC);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
if(lastTemp == celsius) return;
lastTemp = celsius;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(celsius);
lcd.setCursor(14, 0);
lcd.print("*C");
}