#include <LiquidCrystal.h>
// Create An LCD Object. Signals: [ RS, EN, D4, D5, D6, D7 ]
LiquidCrystal My_LCD(13, 12, 14, 27, 26, 25);
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
const int NTC_PIN = 15;
const int BUZZER_PIN = 2;
int freq = 2000;
int channel = 0;
int resolution = 8;
void setup()
{
Serial.begin(115200);
ledcSetup(channel, freq, resolution);
ledcAttachPin(BUZZER_PIN, channel);
}
void loop()
{
int analogValue = analogRead(NTC_PIN);
float celsius = 1 / (log(1 / (1023. / (analogValue / (465/115)) - 1)) / BETA + 1.0 / 298.15) - 273.15;
My_LCD.begin(16, 2);
My_LCD.clear();
if (celsius > 20)
{
My_LCD.print("High temperature");
tone(BUZZER_PIN, 800);
}
else
{
if (celsius < -5)
{
My_LCD.print("Low temperature");
tone(BUZZER_PIN, 800);
}
else
{
My_LCD.print("OK");
noTone(BUZZER_PIN);
}
}
My_LCD.setCursor(0, 1);
My_LCD.print("Temp: " + String(celsius) + char(223) + "C");
delay(1000);
}