-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheartrate and temperature.ino
162 lines (152 loc) · 4.17 KB
/
heartrate and temperature.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
SoftwareSerial sim(9, 10);
String number = "+880XXXXXXXXXXX";
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String readString ;
//switch
int sw_pin1 = 6;
int sw_pin2 = 7;
int sw1_state = 0, sw1_prev_state = 0;
int sw2_state = 0, sw2_prev_state = 0;
int final_hr = 0;
int final_temp = 0;
int val;
int rst=0;
float value;
//heartbeat
unsigned int reading, wait_time = 15000, count = 0;
bool state = 0, lastState = 0, flag = 0;
unsigned long previousMillis = 0;
const long interval = 15000;
int BPM = 0;
int hr_gsm=0;
//temp
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.println("Starting.....");
pinMode(A3, INPUT); //heartbeat
pinMode(A1, INPUT); //temp
Serial.println("Wait few seconds...");
delay(5000);
Serial.println("Sistem Started...");
sim.begin(9600);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 0);
int sw1_read = digitalRead(sw_pin1);
int sw2_read = digitalRead(sw_pin2);
//switch 1
if (sw1_read == HIGH && sw1_prev_state == 0) {
sw1_state = !sw1_state;
}
sw1_prev_state = sw1_read;
//Serial.print(sw1_state);
//switch 2
if (sw2_read == HIGH && sw2_prev_state == 0) {
sw2_state = !sw2_state;
}
sw2_prev_state = sw2_read;
//Serial.println(sw2_state);
START:
if (sw1_state == 1 && sw2_state == 0) {
//hearbeat
unsigned long currentMillis = millis();
reading = analogRead(A3);
if ( reading >= 210 )
{
//Serial.println("Pulse..............................................................");
state = 1;
if (lastState != state)
{
count++;
//Serial.println(count);
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
BPM = 4 * count;
count = 0;
Serial.print("\n");
Serial.println(BPM);
//final_hr = BPM;
if(BPM>40){
final_hr = BPM;
hr_gsm = final_hr;
}
sw1_state = 0;
previousMillis = millis();
goto START;
}
else {
Serial.print("|");
Serial.print("Pulse");
Serial.print("|");
Serial.print(".");
}
}
}
else {
//Serial.println("Not Pulse");
//delay(100);
state = 0;
}
lastState = state;
}
else if (sw1_state == 0 && sw2_state == 1) {
//temperature
BPM = 0;
previousMillis = millis();
val = analogRead(A1);
Serial.println(val);
value = float(val);
float mv = ( value / 1024.0) * 5000.00;
float cel = mv / 10.00;
float farh = (cel * 9) / 5.00 + 32.00;
final_temp = int(farh);
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print(" *C | ");
delay(500);
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print(" *F");
Serial.println();
}
else if (sw1_state == 1 && sw2_state == 1) {
Serial.println("Two Process Can't Run Simultaneously");
sw1_state = 0;
sw2_state = 0;
BPM = 0;
previousMillis = millis();
}
else if (sw1_state == 0 && sw2_state == 0) {
Serial.println("Two Process Off");
BPM = 0;
previousMillis = millis();
}
lcd.setCursor(0,0);
lcd.print("Heart Rate:");
lcd.println(final_hr);
lcd.setCursor(0,1);
lcd.print("Temperature:");
lcd.println(final_temp);
if(hr_gsm>=68){
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(1000);
String SMS = "Patients heart rate in critical condition.HR:"+String(hr_gsm);
sim.println(SMS);
sim.println("ppm");
delay(100);
sim.println((char)26);
delay(1000);
hr_gsm = 0;
}
}