常用传感器讲解三--心率传感器-KY-039(heartbeat)

简介: 常用传感器讲解三

具体讲解

心跳传感器会返回一个心率的数字。传感器提供的只是一个从0到1023的“模拟”值

简而言之:把手指放在传感器的IR led和光晶体管之间。你的心跳会使手指的血管扩张,从而过滤掉红外线。这就产生了一个脉动信号。

电路连接

截屏2023-12-27 下午7.19.27.png

效果图
截屏2023-12-27 下午7.19.49.png

代码介绍

#define samp_siz 4
#define rise_threshold 5
// Pulse Monitor Test Script
int sensorPin = 0;
void setup() {
   
   
   Serial.begin(9600);
}
void loop ()
{
   
   
   float reads[samp_siz], sum;
   long int now, ptr;
   float last, reader, start;
   float first, second, third, before, print_value;
   bool rising;
   int rise_count;
   int n;
   long int last_beat;
   for (int i = 0; i < samp_siz; i++)
     reads[i] = 0;
   sum = 0;
   ptr = 0;
   while(1)
   {
   
   
     // calculate an average of the sensor
     // during a 20 ms period (this will eliminate
     // the 50 Hz noise caused by electric light
     n = 0;
     start = millis();
     reader = 0.;
     do
     {
   
   
       reader += analogRead (sensorPin);
       n++;
       now = millis();
     }
     while (now < start + 20);  
     reader /= n;  // we got an average
     // Add the newest measurement to an array
     // and subtract the oldest measurement from the array
     // to maintain a sum of last measurements
     sum -= reads[ptr];
     sum += reader;
     reads[ptr] = reader;
     last = sum / samp_siz;
     // now last holds the average of the values in the array
     // check for a rising curve (= a heart beat)
     if (last > before)
     {
   
   
       rise_count++;
       if (!rising && rise_count > rise_threshold)
       {
   
   
         // Ok, we have detected a rising curve, which implies a heartbeat.
         // Record the time since last beat, keep track of the two previous
         // times (first, second, third) to get a weighed average.
         // The rising flag prevents us from detecting the same rise 
         // more than once.
         rising = true;
         first = millis() - last_beat;
         last_beat = millis();
         // Calculate the weighed average of heartbeat rate
         // according to the three last beats
         print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third);
         Serial.print(print_value);
         Serial.print('\n');
         third = second;
         second = first;
       }
     }
     else
     {
   
   
       // Ok, the curve is falling
       rising = false;
       rise_count = 0;
     }
     before = last;
     ptr++;
     ptr %= samp_siz;
   }
}
相关文章
|
2月前
|
传感器 数据采集 监控
[开源免费]基于STM32的心率监控仪 —— 从原理到实现的完整技术解析
本文详解基于STM32的心率监控仪设计,涵盖硬件搭建、ADC采样、峰值检测算法及OLED波形显示。采用STM32F103C8T6与PulseSensor实现心率实时监测,支持报警提示与按键交互,适合嵌入式入门与课程实践。
|
传感器 编解码 IDE
|
物联网 智能硬件
物联卡如何选择
选择物联卡需综合考量设备类型与数量、流量需求及卡种特性。明确设备属性后,挑选适宜流量套餐,并了解普通物联网卡、语音卡、NB-IoT卡及陶瓷卡等不同类型的应用场景。同时考虑网络覆盖、服务质量及成本预算,优选性价比高且售后服务完善的运营商,确保物联卡兼容设备并顺利完成实名认证。
物联卡如何选择
|
存储 JSON 物联网
设备管理组件功能介绍
设备管理组件功能介绍
640 2
|
监控 安全 物联网
物联卡安全问题
物联卡安全性涵盖技术、管理和使用安全。技术上,通过专用通道和加密技术保障数据传输安全;管理上,实施实名认证与风险防控措施;使用中需合规操作、警惕诈骗并定期检查更新。尽管如此,仍需防范管理漏洞、诈骗及非法流量风险,确保安全运行。
|
人工智能 自然语言处理 小程序
政务VR导航:跨界融合AI人工智能与大数据分析,打造全方位智能政务服务
政务大厅引入智能导航系统,解决寻路难、指引不足及咨询台压力大的问题。VR导视与AI助手提供在线预览、VR路线指引、智能客服和小程序服务,提高办事效率,减轻咨询台工作,优化群众体验,塑造智慧政务形象。通过线上线下结合,实现政务服务的高效便民。
466 2
政务VR导航:跨界融合AI人工智能与大数据分析,打造全方位智能政务服务
|
安全 算法 小程序
院内智能导航系统赋能医院智慧化转型,加速医疗服务升级
**智慧医院的智能导航系统**是医疗数字化转型的关键,它改善患者就医体验,减轻医务人员压力,优化资源配置并强化安全监管。3D导航、AR指路、VR辅助、自动导诊和停车管理等先进技术,结合实时定位功能,确保精准、快捷的导航服务。此系统减少患者寻路时间,降低服务台咨询量,优化医院交通,增强患者安全,同时提高就医效率和医院信息化水平。
543 1
院内智能导航系统赋能医院智慧化转型,加速医疗服务升级
|
消息中间件 分布式计算 网络协议
从管道路由到共享内存:进程间通信的演变(内附通信方式经典面试题及详解)
进程间通信(Inter-Process Communication, IPC)是计算机科学中的一个重要概念,指的是运行在同一系统或不同系统上的多个进程之间互相发送和接收信息的能力。IPC机制允许进程间共享数据、协调执行流程,是实现分布式系统、多任务操作系统和并发编程的基础。
355 1
从管道路由到共享内存:进程间通信的演变(内附通信方式经典面试题及详解)