#include <LiquidCrystal.h> // include the LiquidCrystal library
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
const int RELAY_PIN = 4; // the pin connected to the relay
LiquidCrystal lcd(13, 14, 21, 19, 18, 5); // initialize the LiquidCrystal library with the appropriate pins
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT); // set the relay pin as an output
digitalWrite(RELAY_PIN, HIGH); // turn off the relay initially
lcd.begin(16, 2); // initialize the LCD with 16 columns and 2 rows
}
void loop() {
int analogValue = analogRead(34);
float celsius = 1 / (log(1 / (4095.0 / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
lcd.clear(); // clear the display
lcd.setCursor(0, 0); // set the cursor to the first column of the first row
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print(" C"); // display the temperature reading on the LCD
if (celsius > 30) {
digitalWrite(RELAY_PIN, HIGH); // turn off the relay
lcd.setCursor(0, 1); // set the cursor to the first column of the second row
lcd.print("Relay: ON"); // display the relay status on the LCD
} else {
digitalWrite(RELAY_PIN, LOW); // turn on the relay
lcd.setCursor(0, 1); // set the cursor to the first column of the second row
lcd.print("Relay: OFF "); // display the relay status on the LCD
}
delay(1000);
}