-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMEAS.ino
86 lines (73 loc) · 2.59 KB
/
PMEAS.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 <SoftwareSerial.h>
#define BUTTON_PIN 4
#define LED_PIN 2
#define BUZZER_PIN 3
#define LED2_PIN 5
#define BUZZER2_PIN 6
SoftwareSerial SIM900A(9, 10); // 9 as Rx || 10 as Tx
void setup()
{
SIM900A.begin(9600); // GSM Module Baud rate - communication speed
Serial.begin(9600); // Baud rate of Serial Monitor in the IDE app
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(BUZZER2_PIN, OUTPUT);
Serial.println("Text Message Module Ready & Verified");
delay(100);
}
void SendMessage()
{
SIM900A.println("AT+CMGF=1"); // Text Mode initialization
delay(1000);
SIM900A.println("AT+CMGS=\"+919618531821\"\r"); // Receiver's Mobile Number
delay(1000);
SIM900A.println("PATIENT MEDICAL EMERGENCY ALERT SYSTEM"); // Message content
delay(100);
SIM900A.println((char)26); // character 26 is used to indicate the end of the message content
delay(1000);
}
void SendCall()
{
Serial.println("Calling through GSM Modem");
// set the data rate for the SoftwareSerial port
SIM900A.begin(9600);
delay(2000);
SIM900A.println("ATD8978722723;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the end!!
Serial.println("Called ATD8978722723");
// print response over serial port
if (SIM900A.available())
Serial.write(SIM900A.read());
}
void loop()
{
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW)
{
Serial.println("Button is pressed");
// Blink LEDs and sound buzzers as long as the button is pressed
while (digitalRead(BUTTON_PIN) == LOW)
{
digitalWrite(LED_PIN, HIGH); // Turn on the LED 1
digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer 1
digitalWrite(LED2_PIN, HIGH); // Turn on the LED 2
digitalWrite(BUZZER2_PIN, HIGH); // Turn on the buzzer 2
delay(500); // Wait for 500ms
digitalWrite(LED_PIN, LOW); // Turn off the LED 1
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer 1
digitalWrite(LED2_PIN, LOW); // Turn off the LED 2
digitalWrite(BUZZER2_PIN, LOW); // Turn off the buzzer 2
delay(500); // Wait for 500ms
}
// Send SMS if the button was held for more than 10 seconds
if (millis() > 10000)
{
SendCall();
SendMessage();
}
}
delay(100);
if (SIM900A.available() > 0) // checks if there is any data available to be read from the SoftwareSerial object
Serial.write(SIM900A.read()); // monitor the response from the GSM module for debugging or verification purposes
}