#include <LiquidCrystal.h>
// Initialize the LCD with the numbers of the interface pins
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Constants for the voltage divider
const int thermistorPin = A0;
const float seriesResistor = 10000; // Value of the series resistor in ohms
// Thermistor parameters (for a 10k NTC thermistor)
const float nominalResistance = 10000; // Resistance at 25 degrees C
const float nominalTemperature = 25; // Nominal temperature (usually 25°C)
const float bCoefficient = 3950; // Beta coefficient of the thermistor
const float referenceResistance = 10000; // The value of the reference resistor
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
pinMode(thermistorPin, INPUT);
}
void loop() {
int adcValue = analogRead(thermistorPin); // Read the analog value from pin A0
float voltage = adcValue * (5.0 / 1023.0); // Convert the analog reading to voltage
float resistance = seriesResistor / ((1023.0 / adcValue) - 1); // Calculate the thermistor resistance
// Calculate temperature in Kelvin using the Beta parameter equation
float temperatureK = 1.0 / (1.0 / (nominalTemperature + 273.15) + (1.0 / bCoefficient) * log(resistance / nominalResistance));
float temperatureC = temperatureK - 273.15; // Convert temperature to Celsius
lcd.setCursor(0, 0); // Set the cursor to column 0, row 0
lcd.print("Temp: "); // Print a label
lcd.print(temperatureC); // Print the temperature in Celsius
lcd.print(" C"); // Print the unit
delay(500); // Wait for 500 milliseconds before updating the value
}