// Include the LiquidCrystal library for controlling the LCD display
#include <LiquidCrystal.h>
// Initialize the library with the pins used to connect to the LCD (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the Beta Coefficient for the thermistor, used for temperature calculations
const float BETA = 3950;
// The setup function runs once when you press reset or power the board
void setup() {
// Set up the LCD's number of columns and rows (16 columns and 2 rows)
lcd.begin(16, 2);
// Set the analog reference voltage to the default (typically 5V)
analogReference(DEFAULT);
}
// The loop function runs continuously after setup
void loop() {
// Read the analog value from A0, which is connected to the thermistor
int analogValue = analogRead(A0);
// Convert the analog reading to a temperature in Celsius
// Using the formula for the thermistor based on the Beta parameter
float celsius = 1 / (log(1 / (1023.0 / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Clear the previous content on the LCD
lcd.clear();
// Set the cursor to the first column, first row of the LCD
lcd.setCursor(0, 0);
// Print "Temp: " on the LCD
lcd.print("Temp: ");
// Print the calculated Celsius temperature with one decimal place
lcd.print(celsius, 1);
// Print the Celsius unit symbol " C"
lcd.print(" C");
// Wait for 1 second before updating the temperature reading again
delay(1000);
}