当前位置:网站首页>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的使用,可以使用本模块练手,也可用这些数据来学习滤波算法、傅里叶变换等,但是想用来比较精准的检测心跳,还是不推荐。
边栏推荐
- 【golang学习笔记】flag包的简单使用,命令行解析
- JMeter performance comprehensive practice - sign in and batch sign in
- 阿里onedate分层思想
- Yuanqi Digitalization: existing mode or open source innovation Lixia action
- Jmeter性能综合实战——签到及批量签到
- 02.网页结构相关知识补充
- Leaderboard design in game server
- 软件体系结构期末复习六十题
- Application of performance test knowledge to actual combat
- [isprint function determines whether characters can be output]
猜你喜欢

王学岗视频编码————MediaCodec编解码

存储结构和管理盘。有点像装win98要先分区格式化硬盘

U++ 学习笔记 控制物体Scale

ONEFLOW V0.8.0 officially released

淘宝助理停用,用大淘营导入数据包上传宝贝提示“主图为必填项,不能为空”是什么原因?如何解决?

Machine learning exercises -- right rate regression

&9 nodemon自动重启工具

lambda學習(sort後面的Comparator的使用,collection後使用Collectors.groupingBy分組)

大学数据库创建与查询实战——数据库表设计
![[complex overloaded operator]](/img/ff/aafaa9471a1bd6ef57f6a619449e80.png)
[complex overloaded operator]
随机推荐
Compare kernelshap and treeshap based on speed, complexity and other factors
Providers and consumers tags in zfoo
JS - event proxy and application scenarios
-2021 sorting and sharing of the latest required papers related to comparative learning
Several methods of obtaining longitude and latitude by cesium
Neo4j应用
Use of cjson Library
[complex overloaded operator]
Mqtt connection, subscription and publishing can be realized without mqtt C library
How to use cesium knockout?
Payment products and their usage scenarios
Pulsar open source message queue_ Understand pulsar --- pulsar work notes 001
YOLO7 口罩识别实战
Openlayers instances advanced mapbox vector tiles advanced mapbox vector maps
The total ranking of blogs is 918
还在为XShell破解烦恼,试试tabby
二分函数细节
Altium Designer - schematic diagram of Arduino uno & PCB diagram (self-made Arduino board)
Machine learning exercises -- right rate regression
Ali onedate's layered thought