const int analogPin = A0; // Analog pin connected to voltage divider
const float R_fixed = 10000.0; // Fixed resistor value (10kΩ)
const float Beta = 3950.0; // Beta coefficient of thermistor
const float T0 = 298.15; // Reference temperature in Kelvin (25°C)
const float R0 = 10000.0; // Thermistor resistance at T0
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial monitor
}
void loop() {
// put your main code here, to run repeatedly:
int ADC_Value = analogRead(analogPin); // Read analog value (0-1023)
float Vout = ADC_Value * 5.0 / 1023.0; // Convert ADC value to voltage
float R_thermistor = (R_fixed * Vout) / (5.0 - Vout); // Calculate resistance
// Calculate temperature using Beta equation
float T_kelvin = (Beta * T0) / (Beta + (T0 * log(R_thermistor / R0)));
float T_celsius = T_kelvin - 273.15; // Convert Kelvin to Celsius
Serial.print("Temperature: ");
Serial.print(T_celsius);
Serial.println(" °C");
delay(1000); // Wait 1 second before next reading
}