-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransmitter Code.ino
74 lines (53 loc) · 1.77 KB
/
Transmitter Code.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
#include <RH_ASK.h> //include radiohead library
#include<LiquidCrystal.h> //include liquid crystal library
LiquidCrystal lcd(8, 6, 5, 4, 3, 2); // sets the interfacing pins // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7) //
RH_ASK driver; //creating object driver of class
char buffer[24]; // setting buffer size length
int temp;
int in = 9;
int i=0,k=0,rate=0;
unsigned long time2,time1;
unsigned long time;
void setup()
{ pinMode(in, INPUT); //make pin 9 as input pin
lcd.begin(16,2); //initialize 16*2 lcd display
delay(500);
Serial.begin(9600); //set up serial monitor
if (!driver.init()) // Debugging only
Serial.println("init failed");
}
void loop()
{
k=0;
while(k<7) // description given above.
{
if(digitalRead(in))
{
if(k==0)
time1=millis();
k++;
while(digitalRead(in));
}
}
time2=millis();
rate=time2-time1;
rate=rate/5;
rate=60000/rate; // here we are getting heart rate
temp = analogRead(A2);
int mv=(temp/1024.0)*5000;
int cel=mv/10; // here we are getting temperature in celsius
lcd.setCursor(0,0);
lcd.print("HeartRate=");
lcd.print(rate); //printing heart rate to the lcd display
lcd.print("_BPM");
lcd.setCursor(0,1);
lcd.print("Temp=");
lcd.print(cel); //printing temperature to lcd display
lcd.print(" *C");
delay(1000);
sprintf(buffer, "%d,%d", rate,cel); // converting integer to string; as we cannot transmit integer directly through network
driver.send((uint8_t *)buffer, strlen(buffer));
driver.waitPacketSent();
delay(500);
Serial.println((char*)buffer);
}