本 科 毕 业 设 计(论 文)
(2024 届)
题 目
基于单片机的室内有害气体检测报警
系统设计
学 院
电子信息学院
(集成电路科学与工程学院)
专 业
信息与通信工程
班 级
学 号
学生姓名
指导教师
完成日期
摘 要
室内空气质量对人们的健康和舒适至关重要。随着工业化和城市化的不断发
展,室内空气中的有害气体排放量也在逐渐增加,因此对室内空气质量进行监测
和控制变得尤为重要。本研究旨在设计一种基于单片机的室内有害气体检测报警
系统,以实时监测室内空气中的有害气体浓度,并在超过安全阈值时发出警报,
以保障居民的健康与安全。
本设计为一款基于单片机的室内有害气体检测报警系统装置。整个系统包括
四个子系统:主控制系统,室内气体检测系统,信息交互可视化系统与信息处理
识别反馈系统。其中,信息处理识别反馈过程是整个系统的关键。整个系统的工
作流程为主控系统通过相应的控制,驱动室内检测系统进行正常工作,同时在主
控系统的控制下,将从室内检测系统获取的传感器信息进行存储与处理,处理后
的信息通过信息交互可视化系统进行可视化显示,并将信息上传到云端与手机端,
方便实时监控查看。最终,通过信息处理识别反馈系统判断数据是否异常从而及
时发出警报。
有害气体检测报警系统装置信号流向及处理过程包括:数据采集,数据预处
理,数据性质判断,数据结果反馈。数据采集由一氧化碳气体传感器 MQ7,甲烷气
体传感器 MQ4,硫化物,苯系蒸汽传感器 MQ135,温湿度传感器 SHT20 对相应的检
测气体进行采集。对采集数据进行存储后,为了获得更加精确的数据,防止干扰
信号对最终判决结果造成影响,会进行数据预处理。预处理包括数据平滑与数字
滤波。获取预处理的数据后,会与国际制定污染标准表进行比对,判断是否有指
标异常,若有异常则会进行报警。
该系统实现了对于污染性质数据的实时精确检测,同时数据可视化,有利于
数据的观测与分析,并且可以在污染气体含量超标时,及时发出警报,有利于人
们及时规避潜在风险。
关键词:有害气体检测;信号处理;数据可视化;数字滤波
ABSTRACT
Indoor air quality is crucial for health and comfort. As industrialization and
urbanization progress, harmful gas emissions rise. Monitoring and controlling indoor air
quality become essential. This study aims to design a single-chip micro controller-based
indoor harmful gas detection and alarm system. It monitors indoor gas levels in
real-time, issuing alerts when they surpass safety thresholds, ensuring residents' health
and safety.
This is a single-chip microcomputer-based indoor harmful gas detection and alarm
system. It comprises four subsystems: main control, indoor gas detection, information
visualization, and feedback processing. The key process is the information processing
recognition feedback. The main control system drives the indoor detection system,
storing and processing sensor data. Visualized information is uploaded for real-time
monitoring, with the feedback system issuing alarms for abnormal data.
The signal flow and processing of the harmful gas detection and alarm system
device include data acquisition, data preprocessing, data nature determination, and data
result feedback. Data acquisition is performed by carbon monoxide gas sensor MQ7,
methane gas sensor MQ4, sulfide, benzene series vapor sensor MQ135, temperature and
humidity sensor SHT20 to collect corresponding detection gases. After storing the
collected data, data preprocessing is conducted to obtain more accurate data and prevent
interference signals from affecting the final judgment results. Preprocessing includes
data smoothing and digital filtering. After obtaining the preprocessed data, it is
compared with the internationally established pollution standard table to determine if
there are any abnormal indicators. If there are abnormalities, an alarm will be issued.
The system achieves real-time and accurate detection of pollution data, while
visualizing data, which is conducive to data observation and analysis. It can also issue
alerts in a timely manner when the pollution gas content exceeds the standard, which is
beneficial for people to avoid potential risks in a timely manner.
Key words: detection of harmful gases; Signal processing; Data visualization;
digital filter
目 录
1.引言 ................................................................................................................................1
2.概述 ................................................................................................................................2
2.1 研究背景与意义 .................................................................................................2
2.2 本次所设计有害气体检测报警系统概述 .........................................................2
2.3 工程设计方案思路 .............................................................................................4
2.4 研究方向和关键技术 .........................................................................................4
2.5 主要技术指标 .....................................................................................................4
3.系统总体设计 ................................................................................................................5
3.1 MQx 系列传感器的数据检测............................................................................5
3.2 MQx 系列传感数据的处理................................................................................6
3.3 MQx 系列传感器数据标准对比表....................................................................8
3.4 云平台与移动端数据传输模块 .........................................................................9
3.5 数据可视化显示 ...............................................................................................10
3.5.1 单片机数据可视化 ................................................................................10
3.5.2 阿里云端数据可视化 ............................................................................12
3.5.3 手机端数据可视化 ................................................................................13
3.6 预警系统 ...........................................................................................................13
4.硬件设计 ......................................................................................................................15
4.1 采样电路设计 ...................................................................................................15
4.2 单片机选型 .......................................................................................................16
4.3 外部 falsh ..........................................................................................................17
4.4 外围外设总控制电路设计 ...............................................................................18
4.4.1 硬件设计软件的使用 ............................................................................18
4.4.2 硬件设计思想 ........................................................................................18
5.软件设计 ......................................................................................................................21
5.1 总体方案 ...........................................................................................................21
5.2 程序流程图 .......................................................................................................21
5.3 硬件抽象层(HAL)程序代码实现
[3]
...........................................................21
5.3.1 LCD 驱动程序实现 ...............................................................................22
5.3.2 本实验所用 MQx 系列传感器及 SHT20 驱动程序 ............................23