#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <math.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int sensorPin = A0; // Analog input pin for the thermistor
const float BETA = 3950; // Beta coefficient of the thermistor
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Set cursor to column 0, row 0
lcd.print("Temp:"); // Print label
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int analogValue = analogRead(sensorPin);
float resistance = 1023.0 / analogValue - 1.0;
resistance = 10000.0 / resistance;
float temperature = 1.0 / (log(resistance / 10000.0) / BETA + 1.0 / 298.15) - 273.15;
lcd.setCursor(6, 0); // Move cursor to column 6, row 0
lcd.print(temperature); // Print temperature
lcd.print(" C"); // Print unit
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000); // Wait for 1 second before updating
}