#define NTC_PIN PA1
#define SERIES_RESISTOR 10000.0 // 10kΩ
#define NOMINAL_RESISTANCE 10000.0
#define NOMINAL_TEMPERATURE 25.0 // °C
#define BETA_COEFFICIENT 3950.0
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
int adcValue = analogRead(NTC_PIN);
// Convert ADC value to resistance
float voltageRatio = (float)adcValue / 4095.0;
float ntcResistance = SERIES_RESISTOR * voltageRatio / (1.0 - voltageRatio);
// Steinhart–Hart (Beta equation)
float temperature;
temperature = ntcResistance / NOMINAL_RESISTANCE;
temperature = log(temperature);
temperature /= BETA_COEFFICIENT;
temperature += 1.0 / (NOMINAL_TEMPERATURE + 273.15);
temperature = 1.0 / temperature;
temperature -= 273.15;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000);
}Loading
st-nucleo-c031c6
st-nucleo-c031c6