c
c
cavedu
Search…
手指偵測心跳模組

科易KEYES 手指偵測心跳模組

專案說明

使用「科易KEYES Arduino UNO R3 開發板」連接「手指偵測心跳模組」,讀取手指偵測心跳速率。
此科易手指偵測心跳模組包含於「科易KEYES 手指偵測心跳模組」內。

KEYES Arduino UNO R3電路圖

· 科易KEYES 手指偵測心跳模組
手指偵測心跳模組是類比訊號輸入,可以接「A0 ~ A5」的KEYES Arduino UNO R3訊號端上。 本範例連接到「A0」。
手指偵測心跳模組上S部分的腳位接到Arduino端的S、中間再接V端、-腳位接到GND。
手指偵測心跳模組由一個紅外線LED和光敏電晶體所構成,原理是透過手指放在紅外線發射器和光敏電晶體之間後,隨著心臟跳動,光敏電晶體的電阻值也在不斷變化,通過這種變化來檢測心跳。為防止外界光線對資料造成影響,最好將 手指偵測心跳模放在一個封閉的盒子裡或是用套子包住感測器,在進行心跳檢測。

Arduino 程式

如果手指放紅外線LED和光敏電晶體之間時在兩秒間的感測數值有不同的跳動的話,會顯示你目前手指脈搏偵測到的心跳數,沒有數值跳動的話則不會顯示心跳數。
產生出的 Arduino 程式如下
1
#define samp_siz 4
2
#define rise_threshold 4
3
4
// Pulse Monitor Test Script
5
int sensorPin = A0;
6
7
void setup() {
8
Serial.begin(9600);
9
}
10
11
void loop ()
12
{
13
float reads[samp_siz], sum;
14
long int now, ptr;
15
float last, reader, start;
16
float first, second, third, before, print_value;
17
bool rising;
18
int rise_count;
19
int n;
20
long int last_beat;
21
22
for (int i = 0; i < samp_siz; i++)
23
reads[i] = 0;
24
sum = 0;
25
ptr = 0;
26
27
while(1)
28
{
29
// calculate an average of the sensor
30
// during a 20 ms period (this will eliminate
31
// the 50 Hz noise caused by electric light
32
n = 0;
33
start = millis();
34
reader = 0.;
35
do
36
{
37
reader += analogRead (sensorPin);
38
n++;
39
now = millis();
40
}
41
while (now < start + 20);
42
reader /= n; // we got an average
43
44
// Add the newest measurement to an array
45
// and subtract the oldest measurement from the array
46
// to maintain a sum of last measurements
47
sum -= reads[ptr];
48
sum += reader;
49
reads[ptr] = reader;
50
last = sum / samp_siz;
51
// now last holds the average of the values in the array
52
53
// check for a rising curve (= a heart beat)
54
if (last > before)
55
{
56
rise_count++;
57
if (!rising && rise_count > rise_threshold)
58
{
59
// Ok, we have detected a rising curve, which implies a heartbeat.
60
// Record the time since last beat, keep track of the two previous
61
// times (first, second, third) to get a weighed average.
62
// The rising flag prevents us from detecting the same rise more than once.
63
rising = true;
64
first = millis() - last_beat;
65
last_beat = millis();
66
67
// Calculate the weighed average of heartbeat rate
68
// according to the three last beats
69
print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third);
70
71
Serial.print("心跳數:");
72
Serial.print(print_value);
73
Serial.print("\n");
74
75
third = second;
76
second = first;
77
78
}
79
}
80
else
81
{
82
// Ok, the curve is falling
83
rising = false;
84
rise_count = 0;
85
}
86
before = last;
87
88
89
ptr++;
90
ptr %= samp_siz;
91
92
}
93
}
94
Copied!