-
Notifications
You must be signed in to change notification settings - Fork 0
/
televrata.ino
77 lines (69 loc) · 2.26 KB
/
televrata.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
#include <SoftwareSerial.h>
#define RELAY_PIN 4
#define GSMRX_PIN 2
#define GSMTX_PIN 3
#define GSMPOWER_PIN 8
// Configure software serial port
SoftwareSerial SIM900(GSMRX_PIN, GSMTX_PIN);
void setup() {
pinMode(RELAY_PIN, OUTPUT); // sets the digital pin 13 as output
// Arduino communicates with SIM900 GSM shield at a baud rate of 19200
// Make sure that corresponds to the baud rate of your module
SIM900.begin(19200); // for GSM shield
// For serial monitor
Serial.begin(19200);
// Give time to log on to network.
SIM900power();
SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
delay(100);
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
pinMode(GSMPOWER_PIN, OUTPUT);
digitalWrite(GSMPOWER_PIN, HIGH);
delay(1500);
digitalWrite(GSMPOWER_PIN, LOW);
delay(5000);
}
char incoming_char=0;
void loop() {
// Display any text that the GSM shield sends out on the serial monitor
if(SIM900.available() >0) {
// Get the character from the cellular serial por
// With an incomming call, a "RING" message is sent out
incoming_char=SIM900.read();
Serial.print(incoming_char);
// Check if the shield is sending a "RING" message
if (incoming_char=='R') {
delay(10);
incoming_char=SIM900.read();
Serial.print(incoming_char);
if (incoming_char =='I') {
delay(10);
incoming_char=SIM900.read();
Serial.print(incoming_char);
if (incoming_char=='N') {
delay(10);
incoming_char=SIM900.read();
Serial.print(incoming_char);
if (incoming_char=='G') {
delay(10);
// If the message received from the shield is RING
gotRing();
}
}
}
}
}
}
void gotRing() {
Serial.println("");
Serial.println("Activating relay");
digitalWrite(RELAY_PIN, HIGH); // sets the digital pin 13 on
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(3000); // waits for a second
Serial.println("Dectivating relay");
digitalWrite(RELAY_PIN, LOW); // sets the digital pin 13 off
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}