// Define the pin where the thermistor is connected
const int thermistorPin = A0;

// Define the fixed resistor value (in ohms)
const int seriesResistor = 100000;

// Steinhart-Hart coefficients for a 100k NTC thermistor
const float A = 0.001129148;
const float B = 0.000234125;
const float C = 0.0000000876741;

void setup() {
  // Start the serial communication
  Serial.begin(9600);
}

void loop() {
  // Read the analog value from the thermistor
  int analogValue = analogRead(thermistorPin);
  
  // Convert the analog value to a voltage
  float voltage = analogValue * (5.0 / 1023.0);
  
  // Calculate the resistance of the thermistor
  float resistance = seriesResistor / ((1023.0 / analogValue) - 1.0);
  
  // Calculate the temperature using the Steinhart-Hart equation
  float logR = log(resistance);
  float temperature = 1.0 / (A + B * logR + C * logR * logR * logR);
  temperature = temperature - 273.15; // Convert from Kelvin to Celsius

  // Print the temperature to the serial monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");
  
  // Wait 1 second before taking another reading
  delay(1000);
}