#include <LiquidCrystal.h>
// Initialize the LCD with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Define the analog pin connected to the NTC sensor
const int sensorPin = A0;
// Constants for the temperature calculation
const float BETA = 3950; // Beta coefficient of the thermistor (change according to your thermistor)
const float ROOM_TEMP = 298.15; // Room temperature in Kelvin (25 degrees Celsius)
const float RESISTOR = 10000; // Value of the fixed resistor in ohms (10k ohms)
void setup() {
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Print a message to the LCD
lcd.print("Temp: ");
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the value from the sensor
int sensorValue = analogRead(sensorPin);
// Convert the analog value to resistance
float resistance = (1023.0 / sensorValue - 1) * RESISTOR;
// Calculate temperature in Kelvin
float temperatureK = 1 / (1 / ROOM_TEMP + log(resistance / RESISTOR) / BETA);
// Convert temperature to Celsius
float temperatureC = temperatureK - 273.15;
// Print the temperature on the LCD
lcd.setCursor(6, 0); // Move the cursor to the right of "Temp: "
lcd.print(temperatureC);
lcd.print((char)223); // Degree symbol
lcd.print("C ");
// Print the temperature to the serial monitor for debugging
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" *C");
// Wait 1 second before taking another reading
delay(1000);
}