forked from nejohnson2/arduino-GSM-sketches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsm-serial-communication.ino
59 lines (49 loc) · 1.49 KB
/
gsm-serial-communication.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
/*
This sketch uses the Arduino GSM Shield to allow the user to send AT Commands to the GSM module
directly without needing the Arduino GSM Library. Upload this sketch, open a serial application
like CoolTerm, and begin sending commands.
Developed by Benedetta Simeonidis
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
char inChar = 0;
char message[] = "hello world";
void setup()
{
Serial.begin(9600);
Serial.println("Hello Debug Terminal!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
//Turn off echo from GSM
mySerial.print("ATE0");
mySerial.print("\r");
delay(300);
//Set the module to text mode
mySerial.print("AT+CMGF=1");
mySerial.print("\r");
delay(500);
//Send the following SMS to the following phone number
mySerial.print("AT+CMGS=\"");
// CHANGE THE NUMBER BELOW!
// 129 for domestic #s, 145 if with +area code in front of #
mySerial.print("1234567\",129"); //this is where you would replace the phone number
mySerial.print("\r");
delay(300);
// TYPE THE BODY OF THE TEXT HERE! 160 CHAR MAX!
// mySerial.print("T4D);
mySerial.print(message);
// Special character to tell the module to send the message
mySerial.write(0x1A);
delay(500);
}
void loop() // run over and over
{
if (mySerial.available()){
inChar = mySerial.read();
Serial.write(inChar);
delay(20);
}
if (Serial.available()>0){
mySerial.write(Serial.read());
}
}