This project demonstrates how to interface a TMP36 analog temperature sensor with an STM32F103C6 microcontroller using low-level register access for optimal control and efficiency. The system reads the analog voltage output from the sensor, converts it into a precise temperature reading, and outputs the result in real-time via UART. Visual feedback is provided through LEDs based on temperature thresholds. A full Proteus simulation setup is included for validation.
The TMP36 provides a linear voltage output directly proportional to temperature (+10 mV/°C), requiring no external calibration. By processing the analog signal through the STM32's internal ADC, this solution offers an efficient and cost-effective temperature monitoring system.
STM32CubeMX Setup- MCU Selection: STM32F103C6
- Clock Source: 8 MHz HSI
- ADC1 Configuration:
-
Channel: IN4 (PA4)
-
Resolution: 12-bit
-
Continuous Conversion Mode: Enabled
- GPIO Configuration:
-
PB0, PB1, PB2 configured as Digital Output (for LED indicators)
- UART1 Configuration:
-
Baud Rate: 115200
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE.
Key Functions
- ADC Initialization & Reading
-
MX_ADC1_Init(void);
→ Initializes the ADC1 peripheral with 12-bit resolution on channel 4 (PA4).-
HAL_ADC_Start(&hadc1);
→ Starts the ADC conversion process.
- Temperature Data Acquisition
-
float Read_Temperature(void);
→ Reads the raw ADC value, converts it to voltage, and calculates the temperature in Celsius using the TMP36's formula.
- UART Communication
-
Send_Temperature_UART(float temp);
→ Formats the temperature value into a string and transmits it via UART1 for monitoring.
- Visual Alert Management
Required Components:
- STM32F103C6 microcontroller
- TMP36 Analog Temperature Sensor
- Virtual Terminal (UART)
- LEDs (optional, for visual alert simulation)
Connections:
- TMP36: VCC → 3.3V, GND → GND, VOUT → PA4
- UART1: PA9 (TX) → Virtual Terminal RX
- LEDs: PB0, PB1, PB2 → LEDs → Resistors → GND
Steps:
- Load the.hex file compiled from CubeIDE.
- Run the simulation.
- Observe the real-time temperature readings on the Virtual Terminal.
- Adjust the TMP36 temperature value in Proteus to simulate different environments and observe the LED states change accordingly.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments