-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_sim.ino
55 lines (41 loc) · 1.23 KB
/
control_sim.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
#include <SoftwareSerial.h>
#define Relay1 4
#define Relay2 5
//Create software serial object to communicate with SIM800L
SoftwareSerial MySim(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
String message;
void setup() {
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
MySim.begin(9600);
Serial.println("Initializing...");
delay(1000);
MySim.println("AT+CMGF=1"); // Configuring TEXT mode
MySim.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
}
void loop() {
while (MySim.available()) {
message = MySim.readString();
Serial.println(message);
//Serial.println(message);//[N] Debugging print statement
//Turn R1 on
if (message.indexOf("R1ON") >= 0) {
digitalWrite(Relay1, HIGH);
}
//Turn R1 off
if (message.indexOf("R1OFF") >= 0) {
digitalWrite(Relay1, LOW);
}
//Turn R2 on
if (message.indexOf("R2ON") >= 0) {
digitalWrite(Relay2, HIGH);
}
//Turn R2 off
if (message.indexOf("R2OFF") >= 0) {
digitalWrite(Relay2, LOW);
}
delay(250);
}
}