学物联网,来万物简单IoT物联网!!
PulseSensor(MDL0025) 是一款用于脉搏心率测量的光电反射式模拟传感器。将其佩戴于手指或耳垂等处,通过导线连接可将采集到的模拟信号传输给HaaS开发版用来转换为数字信号,再通过开发板简单计算后就可以得到心率数值,此外还可将脉搏波形上传到电脑上显示波形。PulseSensor 是一款开源硬件,其适用于心率方面的科学研究和教学演示,也非常适合用于二次开发。
引脚定义:
heartbeatdev = HEARTBEAT(adcdev,rled,gled,bled,highBPM=150,lowBPM=100)
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
adcdev | ADC | 是 | 传入ADC对象 |
rled | GPIO | 否 | 传入GPIO对象 |
gled | GPIO | 否 | 传入GPIO对象 |
bled | GPIO | 否 | 传入GPIO对象 |
highBPM | int | 否 | 心率报警上限 |
lowBPM | int | 否 | 心率报警下限 |
from machine import ADC, Pin
import heartbeat
BPM_high=150
BPM_low=100
#初始化ADC类型的设备
adcObj = ADC(Pin(32))
#初始化GPIO类型的设备
redled = Pin(16, Pin.OUT)
blueled = Pin(17, Pin.OUT)
greenled = Pin(18, Pin.OUT)
heartbeatdev = HEARTBEAT(adcdev = adcobj, rled=redled, bled=blueled, gled=greenled, highBPM=BPM_high, lowBPM=BPM_low)
print("heartbeat inited!")
heartbeat inited!
heartbeatdev.start()
from machine import ADC, Pin
import heartbeat
BPM_high=150
BPM_low=100
#初始化ADC类型的设备
adcObj = ADC(Pin(32))
#初始化GPIO类型的设备
redled = Pin(16, Pin.OUT)
blueled = Pin(17, Pin.OUT)
greenled = Pin(18, Pin.OUT)
heartbeatdev = HEARTBEAT(adcdev = adcobj, rled=redled, bled=blueled, gled=greenled, highBPM=BPM_high, lowBPM=BPM_low)
print("heartbeat inited!")
heartbeatdev.start()
heartbeat inited!
heartbeatdev.stop()
from machine import ADC, Pin
import heartbeat
BPM_high=150
BPM_low=100
#初始化ADC类型的设备
adcObj = ADC(Pin(32))
#初始化GPIO类型的设备
redled = Pin(16, Pin.OUT)
blueled = Pin(17, Pin.OUT)
greenled = Pin(18, Pin.OUT)
heartbeatdev = HEARTBEAT(adcdev = adcobj, rled=redled, bled=blueled, gled=greenled, highBPM=BPM_high, lowBPM=BPM_low)
print("heartbeat inited!")
heartbeatdev.stop()
heartbeat inited!
heartbeatdev.getBPM()
from machine import ADC, Pin
import heartbeat
BPM_high=150
BPM_low=100
#初始化ADC类型的设备
adcObj = ADC(Pin(32))
#初始化GPIO类型的设备
redled = Pin(16, Pin.OUT)
blueled = Pin(17, Pin.OUT)
greenled = Pin(18, Pin.OUT)
heartbeatdev = HEARTBEAT(adcdev = adcobj, rled=redled, bled=blueled, gled=greenled, highBPM=BPM_high, lowBPM=BPM_low)
print("heartbeat inited!")
heartbeatdev.start()
heartrate=heartbeatdev.getBPM()
print("heartrate is ", heartrate, "BPM")
heartbeat inited!
heartrate is 80 BPM
leb_b, led_g, led_r 分别对应蓝色,绿色,红色三色LED灯,如果这三个LED灯设备存在并且在心率传感器驱动初始化时作为参数传入,则心率传感器驱动会根据心率值让不同颜色的LED灯闪烁:心率值大于上限值时,红灯按实测心率为频率闪烁; 心率在上限和下限之间时,绿灯按照实测心率为频率闪烁;心率低于下限值时,蓝灯按实测心率为频率闪烁。
# Python代码
import utime
from machine import ADC, Pin
import heartbeat
BPM_high=150
BPM_low=100
#初始化ADC类型的设备
adcObj = ADC(Pin(32))
#初始化GPIO类型的设备
redled = Pin(16, Pin.OUT)
blueled = Pin(17, Pin.OUT)
greenled = Pin(18, Pin.OUT)
heartbeatdev = HEARTBEAT(adcdev = adcobj, rled=redled, bled=blueled, gled=greenled, highBPM=BPM_high, lowBPM=BPM_low)
print("heartbeat inited!")
heartbeatdev.start()
for i in range(100):
print ("heart rate is: ", heartbeatdev.BPM)
utime.sleep(0.5)
heartbeatdev.stop()
...
heartbeat inited!
heart rate is: 80
heart rate is: 88
heart rate is: 99
heart rate is: 100
...
主控芯片和心率测量传感器之间通信为 ADC 通讯,获取电压值 mV
如下图所示,传感器利用人体组织在血管搏动时造成透光率不同,将透光率转化为电信号来进行脉搏测量的。
光的透光率发生改变,此时光感受器接收经人体组织反射光线,转变为电信号并将其放大输出。