#include <LiquidCrystal_I2C.h>
#include <math.h>
const int RedLed = 23;
const int GreenLed = 16;
const int NTC = 34;
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
void setup()
{
Serial.begin(115200);
pinMode(RedLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(NTC, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, RE23176");
delay(3000);
lcd.clear();
}
void loop()
{
const float BETA = 3950;
int analogValue = analogRead(NTC);
float celsius = 1 / (log(1 / (4095. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println("°C");
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, LOW);
if (celsius >= 27)
{
digitalWrite(RedLed, HIGH);
delay(350);
digitalWrite(RedLed, LOW);
delay(350);
digitalWrite(GreenLed, LOW);
}
else
{
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, HIGH);
}
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print(celsius, 1);
lcd.print(" C");
delay(500);
}