-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype.ino
More file actions
63 lines (54 loc) · 1.49 KB
/
Prototype.ino
File metadata and controls
63 lines (54 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
bool samePulse = false;
bool firstPulse = false;
float bpm = 0;
unsigned long firstPulseTime;
unsigned long secondPulseTime;
unsigned long pulseInterval;
void setup() {
BTSerial.begin(9600);
}
void loop() {
analogReference(INTERNAL);
int tempSignal = accurateAnalogRead(0);
BTSerial.print("Temperature:");
BTSerial.println(tempSignal / 9.31);
analogReference(DEFAULT);
int GSRSignal = accurateAnalogRead(1);
BTSerial.print("GSR:");
BTSerial.println(GSRSignal);
int muscleSignal = accurateAnalogRead(2);
BTSerial.print("Muscle Tenseness:");
BTSerial.println(muscleSignal);
int pulseSignal = accurateAnalogRead(3);
BTSerial.print("Pulse Signal:");
BTSerial.println(pulseSignal);
BTSerial.print("BPM:");
BTSerial.println(calculateBPM(pulseSignal));
}
int accurateAnalogRead(int pin) {
int sensorData = analogRead(pin);
delay(7);
sensorData = analogRead(pin);
delay(7);
return sensorData;
}
float calculateBPM(int pulse) {
if(pulse > 600 and samePulse == false){
if(firstPulse == false){
firstPulseTime = millis();
firstPulse = true;
}
else{
secondPulseTime = millis();
pulseInterval = secondPulseTime - firstPulseTime;
firstPulseTime = secondPulseTime;
}
samePulse = true;
}
if(pulse < 590){
samePulse = false;
}
return bpm = (1.0/pulseInterval) * 60.0 * 1000;
}