当前位置:网站首页>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的使用,可以使用本模块练手,也可用这些数据来学习滤波算法、傅里叶变换等,但是想用来比较精准的检测心跳,还是不推荐。
边栏推荐
- Practice data Lake iceberg lesson 37 kakfa write the enfour, not enfour test of iceberg's icberg table
- Quick review of interview (III): probability theory and mathematical statistics
- ESP32 的 I2C 原理 & 应用入门
- Record the process of the first excavation and intersection
- 【学习笔记】树的直径,重心
- Description and implementation of throttling and anti shake
- JS - event proxy and application scenarios
- 02. Supplement of knowledge related to web page structure
- Lambda learning (the use of comparator after sort and collectors.groupingby after collection)
- University database creation and query practice -- database table design
猜你喜欢

Jmeter性能综合实战——签到及批量签到

lambda学习(sort后面的Comparator的使用,collection后使用Collectors.groupingBy分组)

VLAN comprehensive experiment

LeetCode高频题62. 不同路径:机器人从左上角到右下角的路径有多少条?纯概率排列组合问题,而不是动态规划题

How does MySQL prepare SQL (solve the problem that in query SQL preprocessing can only query one record)

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

NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)

机器学习习题——对率回归

05_ UE4 advanced_ Material UV scaling

Kuberntes cloud native combat VI uses rook to build CEPH cluster
随机推荐
What is Kai Niu? Excuse me, is it safe to open a stock account by mobile phone?
初探POC编写
程序员成长第二十六篇:如何开好每日晨会?
138 - query case - knowledge points involved: foreach traversal & computed calculation attributes & V-for loop
Still have 1 requests outstanding when connection from slaveX/X.X.X.X:33202 is closed
SQL注入攻击
lambda学习(sort后面的Comparator的使用,collection后使用Collectors.groupingBy分组)
Bisection function details
Interval DP chain stone merging
Complete set of official openlayers instances
Several methods of obtaining longitude and latitude by cesium
Distributed transaction scheme: best effort notification scheme
如何在 pyqt 中实现桌面歌词
MySQL的JDBC編程
Pulsar open source message queue_ Understand pulsar --- pulsar work notes 001
MySQL的JDBC编程
experimental design
Jmeter性能综合实战——签到及批量签到
How does MySQL prepare SQL (solve the problem that in query SQL preprocessing can only query one record)
Comparison of open source distributed link tracking