当前位置:网站首页>STM32单片机使用ADC功能驱动手指检测心跳模块
STM32单片机使用ADC功能驱动手指检测心跳模块
2022-07-23 22:01:00 【wanglong3713】
一、模块简介
某宝或某多,两三块钱一个,如下图。
该模块采用超亮红外LED和光敏晶体管来探测手指的脉搏,将手指放在发射和接收端之间,血压随着脉搏变化,接收端收到的光会发生相应的变化,因此可用来检测心跳。
二、STM32MX Cube配置
采用STM32F103C8T6最小系统板,STM32MX Cube进行系统配置并自动生成代码。
在ADC1中,我们选则IN1通道,即PA1引脚,其他配置如图,基本都是默认的配置,无需选择。所有配置完成后,生成工程代码,本文不再详细介绍。
三、主要代码
ADC的初始化代码在MX_ADC1_Init()中,生成的main函数会自动调用:
MX_ADC1_Init();
在进行AD转换时,需要先调用HAL_ADC_Start(&hadc1)函数开始转换,我们不使用中断,通过while (HAL_ADC_PollForConversion(&hadc1,10) != HAL_OK)来等待转换完成,然后通过HAL_ADC_GetValue(&hadc1)函数获取AD值,HAL_ADC_Stop(&hadc1)函数结束转换。以上过程每10ms执行一次,即采样频率100Hz。
HAL_ADC_Start(&hadc1);
while (HAL_ADC_PollForConversion(&hadc1,10) != HAL_OK)//等待转换完成
{
}
HeartBeat_RawData = HAL_ADC_GetValue(&hadc1);//RAW_DATA_LENGTH为保存的数据个数
HAL_ADC_Stop(&hadc1);
printf("%d\n", HeartBeat_RawData);
上面代码中的printf函数将数据打印到串口。看,需要自己写的代码,没有几行。
四、运行效果

上图是通过串口绘图软件VOFA+绘制的原始AD值的图,可看出数据比较杂乱,下图中绿色线是经过简单滤波后的效果:
五、总结
1.实际测试发现,该模块环境影响较大,白天、夜晚,开灯、关灯都会对数据有很大影响,且数据经常会漂移;
2.只是读取了数据,做了简单滤波,从时域图中,找不出什么规律;
3.如果只是用来学习ADC的使用,可以使用本模块练手,也可用这些数据来学习滤波算法、傅里叶变换等,但是想用来比较精准的检测心跳,还是不推荐。
边栏推荐
- Customer exit variable in query
- Use of cjson Library
- Pulsar open source message queue_ Understand pulsar --- pulsar work notes 001
- Openlayers instance accessible map accessible map
- MySQL的JDBC編程
- 启牛是什么?请问一下手机开户股票开户安全吗?
- How does MySQL prepare SQL (solve the problem that in query SQL preprocessing can only query one record)
- SQL injection attack
- 【数学建模暑期培训】配送中心选址问题
- Apprentissage Lambda (utilisation du comparateur après tri, regroupement après collecte avec collectors.groupingby)
猜你喜欢
![[mathematical modeling summer training] location of distribution center](/img/d5/c9b4de6750a7ed080c194250629467.png)
[mathematical modeling summer training] location of distribution center

Postgraduate entrance examination | advanced mathematics Chapter4 indefinite integral

02.网页结构相关知识补充

The simple use of ADB command combined with monkey is super detailed

JS - event proxy and application scenarios

Programmation JDBC pour MySQL

Altium Designer - schematic diagram of Arduino uno & PCB diagram (self-made Arduino board)

众邦科技又一潜心力作 —— 陀螺匠 OA 系统

&9 nodemon自动重启工具

05_ UE4 advanced_ Material UV scaling
随机推荐
uniapp使用canvas写环形进度条
How to use cesium knockout?
experimental design
壹沓数字机器人入选Gartner《中国AI市场指南》
Sudoku written for once and for all
MySQL的JDBC编程
Interval DP chain stone merging
还在为XShell破解烦恼,试试tabby
YOLO7 口罩识别实战
Application of performance test knowledge to actual combat
Is it safe to open a securities account online?
为了一劳永逸而写的数独
二分函数细节
-2021 sorting and sharing of the latest required papers related to comparative learning
[hiflow] Tencent cloud's new generation of automation assistant, which I used to complete the enterprise epidemic prompt (no code)
MySQL索引事务
PCL error: error c2589 "(": "::" illegal mark on the right)
Comparison of open source distributed link tracking
Deep learning - NLP classic papers, courses, papers and other resources sorting and sharing
Neo4j应用