如何使用心脏脉搏传感器与Arduino
扫描二维码
随时随地手机看文章
在本教程中,我们将学习如何使用心脏脉冲传感器与Arduino。
你好,欢迎回来。在本教程中,我们将学习如何使用心脏脉冲传感器与Arduino。这个传感器的设计采用了一个有吸引力的心形标志。而且,它很小,很便宜。因此,你可以买它,并检查你的身体脉搏率很容易。为此,我将通过本教程一步一步地指导您。此外,这种传感器对运动员、学生和软件开发人员等也是最重要的。继续阅读。
该传感器的内部结构
该传感器主要由两部分组成。即ADPS-9008光传感器和一个绿色LED。接下来,在这个传感器的背面,我们可以看到LED的附加组件。其中,我们可以看到电阻、电容、运算放大器和一个反向保护二极管。这对初学者来说非常重要。
脉搏传感器是如何工作的?
当你的手指靠近传感器时,传感器上的绿光落在你的指尖上,光线也会反射到传感器上。然后,绿光被血液中的血红蛋白吸收。此外,由于我们体内的血液量不断泵送,血液中的血红蛋白含量也会增加或减少。因此,反射光的量也增加或减少。这种差异被光敏器捕捉到。(这就是所谓的光学心率感觉理论)最后,我们可以得到这个信号作为模拟值。
步骤1
首先,确定这些组件。
步骤2
其次,连接这些组件。
步骤3
为这个项目制定方案。如下所示。
Firstly, library files are included.
#include
#include
#include
#include
Secondly, an object is created for the OLED display
Adafruit_SSD1306 = Adafruit_SSD1306(128, 64, &Wire);
Thirdly, the sensor pin and the high pulse value are defined. After, variables are created to help the program
#define sensor A0
#define Highpulse 540
int sX = 0;
int sY = 60; I
nt x = 0; int Svalue;
int value; long Stime = 0;
long Ltime = 0;
int count = 0;
int Bpm = 0;
In the setup function,
void setup() { //The serial monitor is begun
Serial.begin(9600); //The OLED display is begun webotricks.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x32 delay(1000); //All characters are cleared in the screen
webotricks.clearDisplay(); }
In the loop function,
void loop() { //Gets sensor values S
value = analogRead(sensor);
Serial.println(Svalue); //These values are changed from 0 to 45
value = map(Svalue, 0, 1024, 0, 45); //These are the heartbeat design codes
int y = 60 - value;
if (x > 128) { x = 0;
sX = 0;
webotricks.clearDisplay();
}
webotricks.drawLine(sX, sY, x, y, WHITE);
sX = x; sY = y; x ++; //This is BPM calculate function.
BPM(); //The heartbeat is printed on the screen
webotrickssetCursor(0, 0);
webotricks.setTextSize(2);
webotricks.setTextColor(SSD1306_WHITE);
webotricks.print("BPM :");
webotricks.display();
}
This is the heart pulse calculate function.
void BPM() { if (Svalue > Highpulse)
{
Stime = millis() - Ltime; count++;
if (Stime / 1000 >= 10)
{
Ltime = millis();
Serial.println(count);
webotricks.setCursor(60, 0);
webotricks.setTextSize(2);
webotricks.setTextColor(SSD1306_WHITE);
webotricks.print(count);
webotricks.print(" ");
webotricks.display();
count = 0;
}
}
}
步骤4
现在,选择板和端口。之后,将此代码上传到Arduino板。
本文编译自hackster.io