2020 Shenzhen University Electronic Design Competition Work Report
Title: Design of automatic human body temperature detection system based on STM32
Summary
[Abstract] Design and implement a human body tracking temperature detection system based on STM32. Combining circuit design requirements with economy and real-time performance, STM32F103C8T6 microcontroller is selected as the main control chip and AMG8833 thermal imaging temperature sensor to detect human body temperature. Based on OpenMV image processing, the face and forehead tracking is realized, and the automatic non-contact body temperature measurement is realized. It is displayed on the Oled LCD screen in real time, and audible and visual alarms are activated when the predetermined temperature is exceeded. The report introduces the system's software and hardware architecture block diagram, hardware circuit design schematic diagram, main external modules, and debugging results.
[Keywords] Infrared temperature sensor, non-contact human body temperature measurement, face and forehead tracking, STM32F103C8T6
Team name: Bald Squad
Team members:
School of Electronic and Information Engineering Zhou Rundong
School of Electronics and Information Engineering Li Jitong
School of Electronic and Information Engineering Yan Hao
School of Mechanical, Electrical and Control Engineering Xu Duoteng
Table of contents
1 . demand analysis ................................................ ................................................................. ................... 1
1.1 Functional requirements ................................................ ................................................................. ............ 1
1.2 Main technical performance indicators ........................................ ................................................................. 1
1.3 Required knowledge and materials ...................................... ............................................. 1
2. Plan selection and demonstration ........................................ ................................................................. ............. 1
2.1Module selection ................................................ ................................................................. ............. 2
2.2 Specific scheme design ................................................ ................................................................. ....... 2
2.3 Plan argumentation and selection ...................................... ................................................................. ... 3
3. System architecture and function description ........................................ ................................................................. ....... 4
3.1 Overview of overall system functions ................................................ ................................................................. 4
3.2 Overall system hardware architecture ................................................ ................................................................. 4
3.3 System software design process ................................................ ................................................................. .4
4.Theoretical analysis and calculation ................................ ................................................................. ............. 5
4.1 Calculation of target temperature of AMG8833 temperature sensor [11] .................................. ......................... 5
4.2 Steering gear control of gimbal ...................................... ................................................................. ..... 6
4.3 特征算法的选择分析........................................................................................... 7
5.电路图和PCB............................................................................................................. 8
6.调试与测试结果........................................................................................................ 10
7.结束语...................................................................................................................... 11
【参考文献】................................................................................................................. 11
1.1****功能要求
新型冠状病毒肆虐,体温检测是疫情防控的重要环节,运用非接触的测温技术,不仅能避免大面积人员滞留、交叉感染的隐患,还具有精度高,效率高,安全系数高的优点。现设计一个微型人体自动测温仪器,能够摆放在建筑物入口,检测到有人进入便启动测温电路,同步移动测温传感器追踪人体头部,在短时间内精确测温,当检测温度超过37.8摄氏度时发出报警声,从而达到被测者无需停顿即可测温报警的目的。
1.2****主要技术性能指标
1:温度测量精度±0.5℃ ;
2:温度测量的分辨率0.02℃:
3:电源:DC 5V±10%;
4: 响应时间: < 0.5s;
4:工作环境温度≤60℃ 工作环境湿度≤90%;
1.3****需要准备的知识与材料
①STM32单片机相关模块,通讯方式的知识储备
②设计电路图,画PCB的相关知识
③红外测温基本原理,红外传感器基本知识储备
④人脸识别相关的特征检测算法
⑤各个硬件使用说明,参数
按照系统设计功能要求,本自动人体追踪测温系统的设计采用电路设计结合单片机嵌入系统实现。设计系统由主控电路模块、测温模块、声光报警模块、显示模块、云台模块、图像获取与处理模块、键盘模块共七个模块(电源模块在PCB及硬件设计上加入)组成,系统框图如图 1 所示。
图1 系统模块框图
2.1模块选择
(1)控制模块
方案一:51单片机 51单片机价格低廉,使用广泛,操作简单。但其内部资源相对不足。
方案二:STM32单片机 STM32单片机片内资源丰富,而且低功耗,接口强大,运算速度快。
基于内容分析以及电路设计要求,我们决定使用STM32F103C8T6。
(2)显示模块
方案一:TFTLCD彩屏显示器 方案二:Oled液晶显示模块
TFT彩屏模块屏幕大,但引脚较多,且不好控制,大大增加了软件和硬件的难度。Oled液晶显示器占用I/O口较少,价格低廉,便于控制。OLED显示屏幕可视角度大,并且能够节省电能。LCD都需要背光,而OLED不需要,因为它是自发光的。这样同样的显示,OLED效果要来得好一些[1]。
基于以上内容综合题目要求,我们决定使用Oled液晶显示模块。
(3)测温模块
方案一:模拟红外温度传感器 方案二:数字红外成像温度传感器
由于论证需要结合放大,滤波电路,A/D转换电路,篇幅较长在具体方案中进行讨论。
(4)图像获取与处理模块
方案一:普通摄像头+STM32做图像处理 方案二: OpenMV
方案一采用普通摄像头获取图像,传输给STM32单片机进行图像处理,人脸检测跟踪,但STM32做图像处理可利用的内置训练算法少,不利于做图像识别分析,并且STM32芯片做图像处理运行速度慢,不能满足本系统所要求的实时性。方案二采用的OpenMV是一个开源,低成本,功能强大的机器视觉模块。集成了OV7725摄像头芯片,内接图像降噪及稳定模块,在小巧的硬件模块上,用C语言高效地实现了核心机器视觉算法,搭载<span class="colour" style="color: windowtext;">MicroPython</span>解释器,这允许你在嵌入式上使用Python来编程,内置图像处理算法以及网络训练模型,集成硬件方便直接编程运作,速度与效率更高,能够满足本系统的实时性要求。
基于以上内容综合题目要求,我们决定使用OpenMv模块。
2.2具体方案设计
在该方案中,系统可以分为模拟红外温度传感器(内含环境温度测量)模块、放大电路模块、**AD转换电路模块、MCU*主控模块、声光报警模块、显示模块和电源模块****,*图像获取和处理模块**。如下图1所示。所谓的模拟传感器就是传感器的输出是模拟量,而不是可以直接进行数据处理的数字量,所以他需要通过信号放大和AD转换等处理才能传输给单片机进行相关的处理。
首先模拟红外温度传感器接收人体发出的红外线,然后经过转换后输出对应的电压值,传感器同时通过片上温度传感器测量环境温度/传感器温度[1]。这两个红外温度传感器的输出量通过放大电路和AD转换电路处理后传输到MCU模块进行相关的处理(软件滤波、黑体校定等),然后通过LED模块显示相应的人体温度。
图像处理模块:采用摄像头获取图像信息,结合Opencv对图像进行分析处理,包括人脸检测,额头坐标获取结合,传输回单片机再调整云台,从而实现追踪。
图2方案一的系统框图
方案二中与第一个方案的最大区别是:在本方案中采用数字红外成像温度传感器代替模拟红外温度传感器。由于数字红外成像温度传感器内部集成了红外光学处理系统,热辐信号-电信号转换电路实现热辐射信号转电信号,运放电路、A/D转换电路、滤波电路和数字信号处理器,,所以只需通过传感器的数据接口就可以把传感器所测量的人体温度数据直接传输给MCU主控模块处理并显示。系统框图如下图
图3 方案二的系统框图
2.3方案论证与选择
方案一采用模拟传感器的成本比较低,整个系统设计更灵活,但是也使系统电路设计更加复杂。电路设计上需要额外的放大电路,A/D转换电路,滤波电路。集成运放电路需要双电源供电,电源模块的设计更复杂,并且功耗与效率低。软件上还需要结合软件滤波,温度校准算法,对于软件设计的负担更重,开发时间更长,运维成本更高。由于硬件的本质区别,并模拟红外温度传感器在距离稍大时,温度测量精度也远不如数字传感器。
方案二里采用的红外热成像传感器,整个系统的设计相对简单,数字红外成像温度传感器内部集成了红外光学处理器,热辐射信号处理,运放电路、A/D转换电路、滤波电路和热辐信号-电信号转换电路,实现热辐射信号转电信号,结合数字信号处理器进行温度计算,我们只需从温度寄存器中读出相应的温度即可完成测温,无需额外运放电路,电源模块的设计简化,利用效率更高。由于该方案的电路简单且集成度高,所以功耗更低。而且相比第一个方案,运维成本更低,开发时间要比方案一少。实际总体成本低于方案一。
基于上述分析,采用方案二更合理。
3.1系统总体功能概述
本系统是基于STM32F103RCT6所设计的自动温度测量系统,主控电路由 STM32微处理器及其外围电路组成,是系统的核心部分,主要完成数据的传输和处理工作。整个系统由单片机主控模块、测温模块、声光报警模块、显示模块、键盘模块、云台模块、图像获取与处理模块共七个模块。当检测到有人进入便启动测温电路,同步移动测温传感器追踪人体头部,通过温度芯片AMG8833测量温度,在短时间内精确测温,微控制器驱动液晶模块显示当前测得的温度,当温度大于37.8℃驱动报警电路,。 整个系统模块分为单片机主控模块、测温模块、声光报警模块、显示模块、键盘模块、云台模块、图像获取与处理模块共七个模块。
3.2系统硬件总体架构
图4 系统硬件框图
3.3系统软件设计流程
软件设计主程序是云台处于循环扫描状态,搭载在云台上的OpenMV集成摄像头能够获取实时图像信息,返回给OpenMV主芯片,经过图像降噪和滤波,转化为灰度图,提取有效特征等预处理操作,导入网络训练模型进行目标特征识别,检测到有行人时,同步导入人脸关键点特征库,使用Openmv内置的Haar Cascade级联特征检测器实现人脸特征点检测,获取到额头的坐标信息返回给单片机,检测到串口传输信息,单片机进入串口中断,计算云台的更新信息,实时更新云台,搭载在云台上的温度传感器获取额头的温度,当温度超过37.8℃时,启动声光报警。通过键盘模块可以复位系统。
图5 系统软件设计流程图
4.1 AMG8833**温度传感器的目标温度的计算**
AMG8833是一种检测红外辐射量的热电堆型红外传感器。64个像素点将测量0°C至80°C(32°F至176°F)的温度,精度为+2.5°C(4.5°F)。它能在7米(23)英尺的距离内探测到一个人。最大帧频为10Hz,非常适合创建人体探测器或微型热相机。在Arduino或stm32(传感器通过I2C通信)上或在Raspberry Pi和Python上使用此代码。在PY上,借助于SciPy python库的一些图像处理帮助,我们能够插值8x8网格并获得一些非常好的结果,但本项目使用的是stm32由c语言编程,且由于并不打算制作热成像,故没有采用液晶显示屏。
该传感器只支持I2C通信,并有一个可配置的中断引脚,当任何单个像素超过或低于设置的阈值时,可以触发。
为了便于使用,我们小组挑选单片机的3.3V和GND引脚对其进行供电。采用oled值输出人体温度值。由于不需要实现报警功能,故不进行中断配置,只连接VIN、GND、SCL、SDA和拉低AD0地址选择引脚,将7位地址配置为0x68.
目标温度的计算:
Amg8833通过128个TEMPERATURE寄存器(8位寄存器,由高地址寄存器和低地址寄存器共同构成一个单位像素点温度的存储寄存器)一次性读取64个像素点的温度,存储在用户自定义数组中(例如a[64]),64个温度值中有部分受环境影响而导致测温不准确,由于环境的温度低于人体温度,故软件设计中采取设置阈值比较算法,取64个温度值中最大温度的10个温度取平均(如果大于44℃会被视为异常点舍弃),即代表了人体体温。
图6 测量温度值寄存器表
除此之外,该模块自带热敏电阻,用于修正因模块电路长时间工作产生的内能影响,可以在软件设计中读取THERMISTOR寄存器热敏电阻温度值,用于测量温度修正的修正。
图7 热敏电阻温度值寄存器表
4.2 云台的舵机控制
由图像获取及目标坐标获取可以得到人脸关键点的坐标(X_Real , Y_Real )
如果要将目标控制在图像的中点,可以计算得到坐标偏移量:
Offset = Real - Target偏移量 = 实际值 - 目标值
我们仅仅知道偏移量还不够,我们最终的控制量是舵机角度的增量(变化幅度), 所以需要在偏移量与舵机角度的增量之间建立某种联系,这里涉及到二自由度舵机云台球面角度与坐标转换,需要借助四元数姿态解算,欧拉角旋转矩阵法,考虑到时间不足无法完成学习以及代码编写,我们直接调用OpenMV中的姿态解算算法,这里不再深入研究。
云台舵机**PID**控制
一种调节器控制规律为比例、积分、微分的控制。其中:P:比例(proportion)、I:积分(integral)、D:导数(derivative)[9]
基本公式如下: Kp为比例系数,Ti为积分时间参数,Td为微分时间常数
具体应用到单片机中的云台舵机控制公式(位置PID):
Pwm=Kp*e(k)+Ki*∑e(k)+Kd*[e(k)-e(k-1)][9] (5)
e(k):本次偏差
e(k-1):上一次的偏差
∑e(k):e(k)以及之前的偏差的累积和;其中k为1,2,,k;
Pwm代表输出到舵机的脉冲
4.3特征算法的选择分析
4.3.1 Haar** feature matching **+Adaboost cascade classifier
The Haar cascade detector in OpenCV supports face detection, smile, eye and mouth detection, etc. Related object detection can be achieved by loading these pre-trained Haar model data. The Haar feature was first proposed by Paul Viola and others, and was later extended by Rainer Lienhart and others to introduce the 45° tilt feature, which has become what OpenCV is now using. Figure 2 shows a total of 14 Haar features currently used by OpenCV, including 5 Basic features, 3 Core features and 6 Titled (i.e. 45° rotation) features.
Figure 8 Harr14 basic characteristics
The Haar feature value reflects the grayscale changes of the image, can be used at any position in the image, and the size can be changed at will. Therefore, the rectangle feature value is a function of the three factors of the rectangle template category, the rectangle position and the rectangle size. Therefore, changes in category, size and position make a small detection window contain a lot of rectangular features [10] . After obtaining the characteristics of the input image, train an adaboost cascade decision maker built by a decision tree to identify whether it is a face.
Figure 9 adaboost cascade decision block diagram
In Opencv, pre-trained Haar model data has been stored. By loading these pre-trained Haar model data and calling the relevant classification algorithm, the detection of related objects can be achieved.
The main control circuit is imitated and designed based on the architecture of the STM32F103C8T6 minimum system core board. The temperature measurement module circuit is added. According to the actual situation, the St-link download circuit and Oled display interface circuit are added. The temperature measurement results are displayed through the Oled LCD screen. The following are the various parts and modules. circuit schematic diagram.
Main control core circuit :
The main control circuit is designed after imitating STM32F103C8T6. STM32F103C8T6 is an embedded microcontroller integrated circuit (IC). It is one of the STM32F1 series developed by ST. The core size is 32 bits and the speed is 72MHz. The program memory capacity is 256KB, the program memory type is FLASH, and the RAM capacity is 48K.
Communication - download interface circuit and power conversion circuit :
Serial port access circuit : St-link download circuit and reset circuit**:
OLED display interface circuit : reset circuit :
Crystal oscillator circuit and ** LED ** circuit :
The final ** PCB ** diagram is as follows :
1. Debugging of temperature measurement module :
Figure 10 Temperature measurement module debugging
(** Note : Because the Oled was accidentally burned out during debugging yesterday , the serial port output is temporarily used . **Oled will be used when the finished product is displayed )
As shown in Figure 10, 24~25 is the ambient temperature; around 36 is the body temperature measured by a healthy experimenter within 30cm. The temperature deviations of the environment and human body are small, and the temperature measurement effect is excellent.
So far, the code is being further transplanted to the PCB production board, and the temperature value is output through the OLED. All functions have been implemented and the code has been written. However, the OLED was accidentally burned due to improper operation during use, so the OLED was not used to record the demonstration.
3.** Openmv ** Debugging and test results:
The camera resolution of Xingtong Technology Openmv module is suitable for the use of this project. This project uses grayscale face recognition. It first recognizes the face, and then uses the face as the recognition area to further identify the eyes, and through the center of the two eyes After the coordinates and attitude are solved, the PID algorithm is input to output the motor PWM wave to drive the servo to rotate the corresponding degree. Openmv measurement takes a lot of time, and the algorithm is still being improved. The offline driver can follow the human face up and down at a medium speed. Move left and right, but because the face moves too fast, it may not be recognized and may break away from following. Generally speaking, the tracking function can basically be realized. The sensitivity of the pid algorithm drive motor and the face recognition calculation algorithm still need to be continuously improved. Make improvements.
The final combined debugging video will be displayed on the 13th.
经过本次电赛,我们获得了非常大的能力提升:获取资料的能力、理解前人思路的能力、系统设计能力、动手能力、分析排除故障能力、表达能力。团队中每个队员都积极地参与其中,我们充分地体会到动手实践的乐趣,获得哪怕是前进一小步时那种成功的喜悦。我们已经全心全意投入紧张激烈的比赛并且良好地完成了任务,以一颗平常心来最终的结果就好啦!<span></span>
调试过程印象深刻的事:由于在开发板调试,i2c通信协议基础代码部分直接借用了网上例程的代码,自己再对照amg8833手册补齐了发送/接受字节数据的函数。紧接着编写amg8833功能函数,期间遇到困难较多,主要是没有注重数据类型的严格要求,一开始总会收到乱码或者是明显错误的数据,调试了很多次,检查了i2c、驱动时钟的频率、GPIO寄存器初始化是否错误等等问题,花费了三四天时间,在信心遭受打击的时候,突然想到了可能是数据类型的问题,于是大部分改成float数据类型之后,情况开始有所好转,由于amg8833是一次性读取长度为64的数组数据,需要对用户定义的数组进行指针操作,在此之前使用i2c协议根本没有遇到过这个问题。经过本次项目,我也更加熟练的运用c语言的数组操作,结合目前所学的微机原理课程,我觉得单片机和主课知识都加深了许多。<span></span>
# 【参考文献】<span></span>
[1] 阳红玉.《无线红外人体测温系统的研发》[D].湖南长沙:中南林业科技大学,2015.
[2] 乌云.《基于STM32的温度检测设计与实现》[J].电子制作,2017年,13:20.
[3] 赵飞翔 车彦洁.《基于OPENMV的室内扫地小车》[J].《魅力中国》,2017,51:14.
[4] 互联网资源库.《基于stm32的温度控制毕业设计》[EB/OL].[https://max.book118.com/,2018-4-28](https://max.book118.com/,2018-4-28).
[5] 王酉祥 . 《监控视频中基于深度学习的人脸检测与识别算法研究》[ D]. 成都:电子科技大学,
2018.
[6] 官大衍.《可见光与长波红外图像融合的行人检测方法研究》[D].浙江杭州:浙江大学,2019.
[7] 赵晓东.《基于人脸识别的目标检测与跟踪算法研究与实现》[D].山西太原:中北大学,2018.
[8] 陈杰.《具有室内定位功能的智能手环系统设计》[D].山西太原:太原理工大学,2019.
[9] 互联网资源库.《增量式与位置式PID算法的C语言实现与电机控制经验总结_C
C++》[EB/OL].[https://blog.csdn.net/ki,2017-11-24](https://blog.csdn.net/ki,2017-11-24).
[10] 互联网资源库.《OpenCV人脸检测-Haar级联和LBP_Harrytsz》[J/OL].[https://blog.csdn.net](https://blog.csdn.net)
/Harrytsz/article/details/97803652,2019-07-30.
[11] Melexis.《Datasheet-MLX90614-中文数据手册》[M/CD]
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet