-
Notifications
You must be signed in to change notification settings - Fork 1
/
patientmonitoring.ino
86 lines (73 loc) · 2.15 KB
/
patientmonitoring.ino
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
#include <ThingSpeak.h>;
#define USE_ARDUINO_INTERRUPTS false
#include <PulseSensorPlayground.h>
#include <DHT.h>
DHT dht;
const char* ssid = "Wifinam"; // Your Network SSID
const char* password = "wifi_password"; // Your Network Password
const int PulseWire = A0;
const int LED2 = 2;
int led = D5;
int buzzer = D6;
int Threshold = 550;
WiFiClient client;
unsigned long myChannelNumber = 1780412; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "ZRWEF5ZFAHALY193"; //Your Write API Key
PulseSensorPlayground pulseSensor;
void setup()
{
Serial.begin(9600);
delay(5000);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
dht.setup(D1);
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED2);
pulseSensor.setThreshold(Threshold);
pinMode(led,OUTPUT);
pinMode(buzzer,OUTPUT);
if(pulseSensor.begin()){
Serial.println("We created a pulseSensor Object!");
}
Serial.println("Status\tHumidy\tTemperature(C)\t(F)\tPulse");
}
void bpm(){
pulseSensor.sawNewSample();
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
Serial.println("♥ A HeartBeat Happened ! ");
Serial.print("BPM: ");
Serial.println(myBPM);
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
float fr = dht.toFahrenheit(temperature);
Serial.println(fr);
if (myBPM > 100){
digitalWrite(led,HIGH);
tone(buzzer,1000);
}
else if(myBPM < 60){
digitalWrite(led,HIGH);
tone(buzzer,1000);
}
else{
digitalWrite(led,LOW);
tone(buzzer,0);
}
ThingSpeak.setField(1, fr);
ThingSpeak.setField(2, myBPM);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}
delay(20);
}
void loop() {
bpm();
}