如何使用心臟脈搏傳感器與Arduino
在本教程中,我們將學(xué)習(xí)如何使用心臟脈沖傳感器與Arduino。
你好,歡迎回來。在本教程中,我們將學(xué)習(xí)如何使用心臟脈沖傳感器與Arduino。這個(gè)傳感器的設(shè)計(jì)采用了一個(gè)有吸引力的心形標(biāo)志。而且,它很小,很便宜。因此,你可以買它,并檢查你的身體脈搏率很容易。為此,我將通過本教程一步一步地指導(dǎo)您。此外,這種傳感器對運(yùn)動(dòng)員、學(xué)生和軟件開發(fā)人員等也是最重要的。繼續(xù)閱讀。
該傳感器的內(nèi)部結(jié)構(gòu)
該傳感器主要由兩部分組成。即ADPS-9008光傳感器和一個(gè)綠色LED。接下來,在這個(gè)傳感器的背面,我們可以看到LED的附加組件。其中,我們可以看到電阻、電容、運(yùn)算放大器和一個(gè)反向保護(hù)二極管。這對初學(xué)者來說非常重要。
脈搏傳感器是如何工作的?
當(dāng)你的手指靠近傳感器時(shí),傳感器上的綠光落在你的指尖上,光線也會(huì)反射到傳感器上。然后,綠光被血液中的血紅蛋白吸收。此外,由于我們體內(nèi)的血液量不斷泵送,血液中的血紅蛋白含量也會(huì)增加或減少。因此,反射光的量也增加或減少。這種差異被光敏器捕捉到。(這就是所謂的光學(xué)心率感覺理論)最后,我們可以得到這個(gè)信號(hào)作為模擬值。
步驟1
首先,確定這些組件。
步驟2
其次,連接這些組件。
步驟3
為這個(gè)項(xiàng)目制定方案。如下所示。
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
現(xiàn)在,選擇板和端口。之后,將此代碼上傳到Arduino板。
本文編譯自hackster.io