This project implements a digital thermometer based on the STM32F103C8T6 (Blue Pill) microcontroller. Temperature data is acquired from an LM35 analog temperature sensor and displayed on a 4-digit 7-segment display.
The display is controlled using two daisy-chained 74HC595 shift registers over SPI, minimizing GPIO usage. The ADC operates in single-conversion, software-triggered mode, with conversion results handled via end-of-conversion interrupts. All peripherals are configured directly at the register level, with STM32CubeMX used only for initial clock and pin configuration.
This project focuses on low-level embedded firmware design, real-time data acquisition, and efficient hardware interfacing.
- HAL-Based Version: This repository - CubeMX for initial setup + register-level peripheral configuration
- Bare-Metal Version: STM32_Digital_Thermometer_BareMetal - Complete register-level implementation (no CubeMX/HAL)
For a more advanced version of this project with multiple temperature sensors, Direct Memory Access (DMA), and data logging capabilities check out: 🔗 STM32_Thermometer_DataLogger
- MCU: STM32F103C8T6 (Blue Pill)
- Temperature Sensor: LM35 (10 mV/°C)
- Display: 4-digit common-cathode 7-segment display
- Display Driver: 2 × 74HC595 shift registers (daisy-chained)
- Interface: SPI1 (data) + GPIO (latch control)
The system is configured for deterministic timing and stable ADC sampling.
- System Clock: 64 MHz (HSI PLL)
- SPI1:
- Data Size: 16-bit mode
- Baud Rate: 16 MBits/s (derived from APB2 prescaler)
- Mode: Master, Full-Duplex
- Clock Polarity: Low, Phase: 1 Edge
- First Bit: MSB
- ADC1:
- ADC Clock: 10.667 MHz
- Resolution: 12-bit
- Sampling Time: 28.5 cycles
- Channel: PA0 (ADC1_IN0)
- Firmware developed in
Keil MDK-ARM 5 - Circuit simulation and validation in
Proteus 8
Complete_Proteus_Demo.mp4
Demonstration of the digital thermometer:
- Starts at 1.0 °C, demonstrating basic temperature display functionality
- Both positive and negative temperature readings
- Voltage divider circuit for negative temperature measurement
- Measurement accuracy within ±0.1°C tolerance
*Schematic designed using EasyEDA*
The schematic shows the complete STM32F103C8T6 implementation including:
- Core Blue Pill circuits: Power supply, 8MHz and RTC clock, reset circuit, decoupling and BOOT circuit
- Display driver: Two daisy-chained 74HC595 shift registers controlling the 4-digit 7-segment display
- Temperature sensing: LM35 sensor with voltage divider for negative temperature measurement
| STM32 Pin | Function | Connected To | Purpose |
|---|---|---|---|
PA5 |
SPI1_SCK |
Both 74HC595 SH_CP (Pin 11) | Shift Clock - data synchronization |
PA7 |
SPI1_MOSI |
First 74HC595 DS (Pin 14) | Serial Data - segment/digit data |
PA4 |
GPIO Output |
Both 74HC595 ST_CP (Pin 12) | Latch Control - update outputs |
PA0 |
ADC1_IN0 |
LM35 Output | Temperature sensor reading |
| 74HC595 Pin | Connection | Purpose |
|---|---|---|
Q0 |
Segment A | Display segment A |
Q1 |
Segment B | Display segment B |
Q2 |
Segment C | Display segment C |
Q3 |
Segment D | Display segment D |
Q4 |
Segment E | Display segment E |
Q5 |
Segment F | Display segment F |
Q6 |
Segment G | Display segment G |
Q7 |
Decimal Point | Display decimal point |
Q7'/QH' |
Second 74HC595 DS (Pin 14) | Daisy-chain connection |
| 74HC595 Pin | Connection | Purpose |
|---|---|---|
Q0 |
Digit 1 Cathode | Activate Digit 1 |
Q1 |
Digit 2 Cathode | Activate Digit 2 |
Q2 |
Digit 3 Cathode | Activate Digit 3 |
Q3 |
Digit 4 Cathode | Activate Digit 4 |
Q4-Q7 |
Not Connected | Unused outputs |
| Component | Connection Points | Purpose |
|---|---|---|
R1 (10kΩ) |
3.3V → R1 → R2 | Creates voltage divider for 1.65V reference |
R2 (10kΩ) |
R1 → R2 → GND | Sets midpoint voltage at 1.65V |
LM35 GND |
R1-R2 junction → LM35 GND | Shifts LM35 ground to 1.65V for negative readings |
- STM32F103C8T6 (Blue Pill) Microcontroller
- STM32CubeF1 Firmware Package (includes HAL drivers)
- Keil MDK-ARM 5 with STM32 support
- STM32CubeMX for initial project setup
- Proteus 8 to run the simulation file
- ST-Link Programmer/Debugger
- Clone this repository
git clone https://github.com/rubin-khadka/STM32_Digital_Thermometer.git-
Open CubeMX file
STM32_Digital_Thermometer.iocin STM32CubeMX -
Generate codein CubeMX - this will open the project in Keil 5 -
Build the project and test it with:
- Actual hardware, OR
- Proteus 8 simulation
Proteus_Simulation.pdsprj
If you don't have Keil MDK:
- In CubeMX file
STM32_Digital_Thermometer.ioc, configure the project for STM32Cube IDE - Copy files from
Core/SrcandCore/Incfolders - Copy code from
main.cfile - Build in STM32Cube IDE and test
The project should work with either development environment.
- STM32F103 Datasheet
- 74HC595 Shift Register Datasheet
- LM35 Temperature Sensor Datasheet
- EasyEDA Website
- Register-level STM32 peripheral programming without reliance on HAL drivers
- Interrupt-driven ADC data acquisition for real-time temperature measurement
- Efficient GPIO utilization using SPI-based shift registers
- Hardware–software co-design, including analog signal conditioning for negative temperatures
- Status: Complete
- Version: v1.0
- Last Updated: December 2025
Rubin Khadka Chhetri
📧 rubin.robotic@gmail.com
🐙 GitHub: https://github.com/rubin-khadka