int sensorPin = 18; // GPIO connected to the NTC thermistor
const float nominalResistance = 10000; // Resistance at 25 degrees C (in ohms)
const float nominalTemperature = 25; // Temperature for nominal resistance (in Celsius)
const float bCoefficient = 3950; // Beta coefficient of the thermistor
const int seriesResistor = 10000; // Series resistor value (in ohms)
void setup() {
Serial.begin(115200); // Start serial communication
}
void loop() {
int analogValue = analogRead(sensorPin); // Read analog value from the NTC thermistor
float resistance = (1023.0 / analogValue - 1) * seriesResistor; // Calculate resistance
float temperature = 1.0 / (log(resistance / nominalResistance) / bCoefficient + 1.0 / (nominalTemperature + 273.15)) - 273.15; // Convert to Celsius
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000); // Delay for readability
}