This project demonstrates how to interface an NTC (Negative Temperature Coefficient) thermistor with an STM32F103C6 microcontroller for precise temperature measurement. The system uses a voltage divider circuit to convert the thermistor's resistance into a measurable voltage, which is then digitized by the internal ADC. The converted value is processed using the Steinhart-Hart equation to calculate accurate temperature readings, which are output in real-time via UART. A full Proteus simulation setup is included for validation.
NTC thermistors are ideal for this application due to their high sensitivity, fast response time, and cost-effectiveness, making them perfect for monitoring applications within their operational temperature range.
STM32CubeMX Setup- MCU Selection: STM32F103C6
- Clock Source: 8 MHz HSI
- ADC1 Configuration:
-
Channel: IN5 (PA5)
-
Resolution: 12-bit, Right Alignment
-
Continuous Conversion Mode: Enabled
- UART1 Configuration:
-
Baud Rate: 115200
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE.
Key Functions
- ADC & Thermistor Initialization
-
MX_ADC1_Init(void);
→ Configures the ADC1 peripheral on channel 5 (PA5) for reading the voltage divider output.
- Temperature Data Acquisition
-
float Read_Thermistor_Voltage(void);
→ Reads the raw ADC value and converts it to the actual voltage across the thermistor.-
void Send_Temperature_UART(float temperature);
→ Applies the Steinhart-Hart equation to the measured voltage to calculate the precise temperature in Celsius.
- UART Data Output
-
void Send_Temperature_UART(float temperature);
→ Formats the calculated temperature value and transmits it via UART1.
- Main Loop Logic
while (1)
{
// Read voltage and calculate temperature
float voltage = Read_Thermistor_Voltage();
float temperature = Calculate_Temperature(voltage);
// Send data via UART
Send_Temperature_UART(temperature);
HAL_Delay(1000); // Update every second
}
Required Components:
- STM32F103C6 microcontroller
- NTC Thermistor (e.g., 10kΩ at 25°C)
- 10kΩ Reference Resistor (for voltage divider)
- Virtual Terminal (UART)
Connections:
- Voltage Divider: 3.3V → NTC Thermistor → PA5 → 10kΩ Resistor → GND
- UART1: PA9 (TX) → Virtual Terminal RX
Steps:
- Load the.hex file compiled from CubeIDE.
- Run the simulation.
- Adjust the NTC thermistor's resistance value in Proteus to simulate different temperatures.
- Observe the real-time temperature calculations on the Virtual Terminal.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments