1. Introduction
1.1 Project Development Background
In various fields such as industrial production, medical diagnosis, and home safety, temperature monitoring is a crucial foundational task. Traditional contact temperature measurement methods suffer from slow response times, susceptibility to environmental interference, potential damage to the measured object (e.g., contact measurement of high-temperature objects can damage instruments), and risks of cross-infection, making them inadequate for modern scenarios that demand fast, safe, and accurate temperature measurement.
Non-contact infrared temperature measurement technology, with its advantages of not requiring contact with the measured object, fast response times, and wide measurement range, has become an ideal solution to these problems. Infrared temperature measurement devices based on embedded systems can achieve real-time temperature collection, display, threshold judgment, and alarm functions, significantly improving measurement efficiency and safety.
This project designs and implements an infrared thermometer based on the STM32 microcontroller, which collects the temperature of objects using a non-contact infrared sensor, combined with local display, threshold setting, and alarm functions, providing a convenient and reliable temperature monitoring solution for industrial inspections, equipment monitoring, and daily body temperature checks, with strong practical value and application prospects.

1.2 Functions of the Design Implementation
(1) Temperature Detection: Accurate collection of object temperature data using the GY-906 non-contact infrared sensor.
(2) Temperature Display: Real-time display of the current measured object temperature value on a 1.8-inch TFT-LCD screen.
(3) Threshold Setting: Users can set the temperature alarm threshold through independent buttons to meet monitoring needs in different scenarios.
(4) Sound and Light Alarm: When the detected object temperature exceeds the set threshold, the sound and light alarm automatically issues a warning.
1.3 Project Hardware Module Composition
(1) Main Control Chip: STM32F103RCT6
The STM32F103RCT6 is based on the ARM Cortex-M3 architecture, featuring powerful processing capabilities and a rich set of peripheral interfaces (such as I2C, GPIO, timers, etc.), enabling efficient processing of sensor data, driving display devices, responding to button inputs, and controlling alarm modules. It serves as the core control unit of the entire system, responsible for coordinating the orderly operation of the entire system.
(2) Infrared Sensor: GY-906
The GY-906 is a non-contact infrared temperature sensor that uses the SMBus communication protocol to achieve non-contact measurement of the surface temperature of objects. This sensor features high measurement accuracy, fast response time, wide measurement range, and low power consumption, making it suitable for the non-contact temperature measurement needs of this project.
(3) Display: 1.8-inch TFT-LCD Screen
The 1.8-inch TFT-LCD screen is used to display the measured temperature value and the currently set temperature threshold in real-time. It offers clear display effects, low cost, and simple interfaces, making it easy to connect with the STM32 microcontroller, allowing users to intuitively access temperature data and system status.
(4) Sound and Light Alarm
The sound and light alarm consists of a buzzer and an LED light. The buzzer can be activated by outputting a high level through GPIO; the LED light is controlled by GPIO, lighting up at high level and turning off at low level, and can be made to flash during an alarm.
(5) Independent Buttons
Independent buttons are used to set the temperature threshold, including operations for increasing and decreasing the threshold, providing users with a convenient interaction method.
1.4 Design Concept
This project focuses on non-contact temperature monitoring, aiming to build an intelligent temperature measurement platform that integrates temperature collection, display, threshold setting, and alarm functions.
In terms of hardware selection, the STM32F103RCT6 is chosen as the main control chip due to its powerful processing capabilities and rich peripherals that meet the system’s needs for data processing, device driving, and interaction control. The GY-906 infrared sensor is used for non-contact temperature measurement, ensuring safety and accuracy; the 1.8-inch TFT-LCD screen is used for intuitive display of temperature information; the sound and light alarm is responsible for threshold alarm prompts; and independent buttons provide user interaction interfaces.
The system workflow is as follows: First, the main control chip initializes each hardware module; the GY-906 sensor collects object temperature data in real-time and transmits it to the STM32; the STM32 processes the temperature data and displays the current temperature on the TFT-LCD screen; users can set and save the temperature threshold through independent buttons; the STM32 compares the real-time measured temperature with the set threshold, and when the measured temperature exceeds the threshold, it controls the sound and light alarm to issue a warning.

1.5 Development Environment Introduction
In this project, the programming language for STM32 is chosen to be C. C language is known for its high execution efficiency and good portability.Development tools used includeKeil5. Keil5 is a leading development tool in the embedded microcontroller field, with enhanced support for ARM architecture microcontrollers. Since the STM32F103 series used in this project is based on the ARM Cortex-M3 core, using Keil for development can fully leverage its optimization support for the chip architecture, facilitating code writing, debugging, and programming.

1.6 Module Technical Details
(1) GY-906 Module
The GY-906 is a non-contact infrared temperature sensor module based on the MLX90614 chip, capable of measuring the surface temperature of objects. It integrates an infrared receiving unit, signal processing circuit, and I2C communication interface, allowing direct data interaction with the microcontroller. The main features of this module include: wide measurement range, typically divided into ambient temperature measurement and object temperature measurement; high measurement accuracy, with an accuracy of ±0.5℃ in the normal temperature range; and support for sleep mode to reduce power consumption. The module pins include VCC, GND, SDA, SCL..

(2) Sound and Light Alarm Module
The sound and light alarm consists of a buzzer and an LED light. The buzzer can be activated by outputting a high level through GPIO; the LED light is controlled by GPIO, lighting up at high level and turning off at low level, and can be made to flash during an alarm..

2. Hardware Selection and Connection Diagram
(1) GY-906-BAA Module
The GY-906-BAA module has stable performance, and its non-contact measurement method is suitable for various scenarios. The I2C communication interface simplifies the connection with the microcontroller, and its measurement accuracy and range meet the project’s temperature monitoring needs, while being cost-effective, making it suitable for small embedded projects. The connection between the module and STM32 is as follows:

(2) Sound and Light Alarm Module
The sound and light alarm uses simple GPIO control, with the buzzer and LED driven by transistors to ensure clear alarm signals. The connection between the module and STM32 is as follows:


3. STM32 Code Design
3.1 Related Module Driver Code
(1) GY-906 Module
void SMBus_Init(){ GPIO_InitTypeDef GPIO_InitStructure; /* Enable SMBUS_PORT clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SMBUS_PORT, ENABLE); /* Configure SMBUS_SCK, SMBUS_SDA as open-drain output */ GPIO_InitStructure.GPIO_Pin = SMBUS_SCK | SMBUS_SDA; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(SMBUS_PORT, &GPIO_InitStructure); SMBUS_SCK_H(); SMBUS_SDA_H();}
u16 SMBus_ReadMemory(u8 slaveAddress, u8 command){ u16 data; // Data storage u8 Pec; u8 DataL=0; // Low data byte storage u8 DataH=0; // High data byte storage u8 arr[6]; // Buffer for sending bytes u8 PecReg; // Calculated PEC byte storage u8 ErrorCounter; // Define the number of attempts to communicate with MLX90614ErrorCounter=0x00; // Initialize error counter slaveAddress <<= 1; // 2-7 bits represent slave address do {repeat: SMBus_StopBit(); // If the slave sends NACK, stop communication --ErrorCounter; if(!ErrorCounter) { break; } SMBus_StartBit(); // Start condition if(SMBus_SendByte(slaveAddress))// Send slave address, LSB Wr=0 indicates the next command to write { goto repeat; // Repeat communication } if(SMBus_SendByte(command)) // Send command { goto repeat; // Repeat communication } SMBus_StartBit(); // Repeat start condition if(SMBus_SendByte(slaveAddress+1)) // Send slave address, LSB Rd=1 indicates the next command to read data { goto repeat; // Repeat communication } DataL = SMBus_ReceiveByte(ACK); // Read low byte data, the master must send acknowledgment DataH = SMBus_ReceiveByte(ACK); // Read high byte data, the master must send acknowledgment Pec = SMBus_ReceiveByte(NACK); // Read PEC byte, the master must send acknowledgment SMBus_StopBit(); // Stop condition arr[5] = slaveAddress; arr[4] = command; arr[3] = slaveAddress+1; arr[2] = DataL; arr[1] = DataH; arr[0] = 0; PecReg=PEC_Calculation(arr);// Calculate CRC}while(PecReg != Pec);// If the received CRC and calculated CRC are equal, exit do-while{} loop data = (DataH<<8) | DataL; return data;}
float SMBus_ReadTemp(void){ float temp; temp = SMBus_ReadMemory(SA, RAM_ACCESS|RAM_TOBJ1)*0.02-273.15; return temp;}
(2) Sound and Light Alarm Module
#include "slight.h" void Slight_Config(void){ //PB0 3.3v RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitTypeDef slight_initstruct = {0}; slight_initstruct.GPIO_Mode = GPIO_Mode_Out_PP; slight_initstruct.GPIO_Pin = GPIO_Pin_0; slight_initstruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB,&slight_initstruct); Slight_OFF; }
#ifndef _SLIGHT_H_#define _SLIGHT_H_ #include "stm32f10x.h" #define Slight_ON GPIO_SetBits(GPIOB,GPIO_Pin_0)#define Slight_OFF GPIO_ResetBits(GPIOB,GPIO_Pin_0) void Slight_Config(void); #endif
3.2 Main Function Framework Code
int main(){ JTAG_SWD_Config();// Disable JTAG function, enable SWD function SysTick_Config(72000);// Timer initialization NVIC_SetPriorityGrouping(5);// Interrupt priority grouping USART1_Config(115200);// Serial port initialization Key_Config(); Led_Config(); Slight_Config(); Beep_Config(); SMBus_Init(); LCD_Init();// LCD screen initialization function LCD_Fill(0,0,128,160,WHITE); LCD_ShowChinese(24,20,(u8 *)"Infrared Thermometer",BLUE,WHITE,16,1); LCD_ShowChinese(10,50,(u8 *)"Temperature",BLUE,WHITE,12,1); LCD_ShowChinese(10,65,(u8 *)"Threshold",BLUE,WHITE,12,1); while(1) { if(device_time > 200) { temp = SMBus_ReadTemp(); memset(showbuf,0,sizeof(showbuf)); sprintf((char *)showbuf,"%.2f",temp); LCD_ShowString(50,50,showbuf,BLUE,WHITE,12,0); device_time = 0; } if(key_time > 10) { key_value = KEY_Get_Value(); if(key_value == 1) { num+=5; memset(showbuf,0,sizeof(showbuf)); sprintf((char *)showbuf,"%d",num); LCD_ShowString(50,65,showbuf,BLUE,WHITE,12,0); } if(key_value == 2) { num-=5; memset(showbuf,0,sizeof(showbuf)); sprintf((char *)showbuf,"%d",num); LCD_ShowString(50,65,showbuf,BLUE,WHITE,12,0); } key_time = 0; } if(temp >= num) { Slight_ON; } else{ Slight_OFF; } }
3.3 Operation Results

3.4 Key Code Explanation
System initialization: includes STM32 hardware initialization (timers, interrupt grouping), as well as initialization of modules such as GY-906, LCD screen, alarm, and buttons, ensuring that all hardware devices work properly.
Temperature collection and display: The GY-906 sensor periodically collects object temperature data, which is processed and displayed in real-time on the TFT-LCD screen along with the current temperature value and set threshold.
Threshold setting: Adjust the threshold using the “increase” and “decrease” buttons.
Alarm control: The system compares the real-time measured temperature with the set threshold, and when the measured temperature exceeds the threshold, it controls the sound and light alarm to issue a warning; otherwise, it turns off the alarm.
4. Conclusion
This system, based on the STM32F103RCT6 microcontroller, successfully constructs a complete non-contact infrared temperature measurement platform. The GY-906 infrared sensor achieves precise collection of object temperature, combined with a 1.8-inch TFT-LCD screen to display temperature data and threshold information in real-time; users can conveniently set the temperature threshold through independent buttons, and when the measured temperature exceeds the threshold, the sound and light alarm is automatically triggered, forming a complete functional loop of “collection – display – interaction – alarm.”
This project fully leverages the advantages of embedded technology and sensor technology, addressing many pain points of traditional contact temperature measurement, featuring fast measurement speed, ease of operation, and high safety, making it widely applicable in industrial monitoring, medical assistance, home safety, and other scenarios.
In the future, this project can further expand its functions, such as implementing wireless transmission of temperature data via Bluetooth modules, optimizing sensor algorithms to improve measurement accuracy in complex environments, etc., to better meet diverse practical application needs.

