#include <LiquidCrystal.h>
#include <ArduinoJson.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const float BETA = 3950; // should match the Beta
// Coefficient of the thermistor
float celsiusOld = 0.0;
int analogValue = 0;
float celsius = 0.0;
const int LED_ALARM_HIGH = 6;
const int LED_ALARM_LOW = 5;
const int LCD_PIN = 4;
int value = LOW;
int valueOld = LOW;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
analogValue = analogRead(A0);
celsius = 1 / (log(1 / (1023. / analogValue - 1)) /
BETA + 1.0 / 298.15) - 273.15;
lcd.print(celsius);
pinMode(LED_ALARM_HIGH, OUTPUT);
pinMode(LED_ALARM_LOW, OUTPUT);
pinMode(LCD_PIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
analogValue = analogRead(A0);
celsius = 1 / (log(1 / (1023. / analogValue - 1)) /
BETA + 1.0 / 298.15) - 273.15;
shouldDisplay();
tempCheck();
}
void shouldDisplay() {
float diff = celsius - celsiusOld;
if (diff < 0) {diff = -diff;}
if (diff > 2.8) {
lcd.clear();
lcd.print(celsius);
}
celsiusOld = celsius;
}
void greet() {
value = digitalRead(LCD_PIN);
valueOld = LOW;
if (value == HIGH && valueOld == LOW) {
lcd.clear();
lcd.print("Good Morning!");
}
valueOld = value;
}
void tempCheck() {
if (celsius > 40) {
digitalWrite(LED_ALARM_HIGH, HIGH);
} else {
digitalWrite(LED_ALARM_HIGH, LOW);
}
if (celsius < 10) {
digitalWrite(LED_ALARM_LOW, HIGH);
} else {
digitalWrite(LED_ALARM_LOW, LOW);
}
}