# Thermometer using STM32 Nucleo I will create an application to realize a thermometer using an inexpensive thermistor as a sensor element with an STM32 MCU (Nucleo board). It is a simple program, but it can be developed into various other arithmetic applications using floating point arithmetic with the Cortex-M3 core MCU.

Thermistors are elements whose resistance changes with temperature, and those with NTC characteristics are suitable for thermometers. The NTC thermistor has a resistance value that decreases slowly as the temperature rises, but the change is not linear and is non-linear.

The thermistor used in this project is 103AT-2 with a B constant of 3435K and a thermistor resistance R25 of 10kΩ at the reference temperature T25 (25°C). The equation below shows the relationship between thermistor resistance R and temperature T. The temperature in this equation is absolute temperature (K).

Temperature and resistance are functions of the natural logarithm, and a logarithmic table of the graph shows a gradual decrease in resistance as temperature rises. It can be confirmed that the resistance values in the datasheet and the values calculated by the above formula are almost identical.

To measure temperature with MCU, the resistance of the thermistor must be known. To know the resistance value, MCU reads the analog value converted into a voltage and converts it into a resistance value in MCU program.

In this sample, a thermistor R and a resistor Ro (of the same value as R25 of the thermistor, 10kΩ) are connected in series between MCU voltage Vdd (3.3V) and GND as the upper limit voltage. Since the intermediate voltage V varies with temperature change, this voltage is read by AD conversion and converted to a resistance value using the following formula.

Once the resistance of the thermistor is known, it can be input into an equation to convert it to temperature, but this equation requires arithmetic operations using the natural logarithm. Because of the nonlinear nature of this operation, it is not performed with ordinary integers, but with floating-point variables.

To achieve this operation, you must first include "math.h" to use the natural logarithm log function. Next, calculate the temperature in a floating-point variable. The resulting calculated value is sent to the monitor via serial communication and displayed as a decimal point. The thermistor resistance-temperature relationship is absolute temperature, so subtract 273.15 to convert to Celsius.

In this sample program, the voltage (ADCValue_IN0) corresponding to the resistance value is captured by AD conversion, but since continuous conversion is specified in this sample program, it can be acquired at any timing and is converted to the resistance value in line 141. Line 142 sets the number of digits to be displayed.

Line 143 performs a floating-point operation using the log function to determine the temperature, and line 144 sets the number of digits to be displayed via USART.