Simple example for getting started sending SMS (using a button to send the required CTRL+Z char)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First, wait for the green LED to go solid green | |
// Then, set the pin code using | |
// AT+CPIN=2643 | |
// When the green LED blinks, you can check the name of the operator | |
// AT+CSPN? | |
// The turn on sending plain text messages (ASCII chars only) | |
// AT+CMGF=1 | |
// Then start sending the message. The module will output a single ">" char. Then press the button to send! | |
// AT+CMGS="+4790691786" | |
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(8, 9); | |
const int buttonPin = 2; | |
int buttonState = 0; | |
void setup() | |
{ | |
delay(500); | |
Serial.begin(115200); // use these two lines on a new module using 115200 baud by default | |
mySerial.begin(115200); | |
//Serial.begin(19200); // after changing the baud rate to 19200 using AT+IPR=19200, we use the speeds instead | |
//mySerial.begin(19200); | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(buttonPin, INPUT); | |
delay(1000); | |
} | |
int counter = 0; | |
void loop() | |
{ | |
/* send everything received from the hardware uart to usb serial & vv */ | |
if (Serial.available() > 0) { | |
Serial.print(">"); | |
delay(100); | |
while ( Serial.available() ) { | |
char ch = Serial.read(); | |
Serial.print(ch); | |
mySerial.print(ch); | |
} | |
} | |
if (mySerial.available() > 0) { | |
Serial.print(":"); | |
delay(10); | |
while ( mySerial.available() ) { | |
digitalWrite(LED_BUILTIN, HIGH); | |
char ch = mySerial.read(); | |
if ( ch ) { | |
Serial.print(ch); | |
} | |
} | |
} else { | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
buttonState = digitalRead(buttonPin); | |
// check if the pushbutton is pressed. If it is, the buttonState is HIGH: | |
if (buttonState == HIGH) { | |
digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED for debugging | |
delay(200); | |
mySerial.print("Testing SMS\r\n"); // type your message here | |
mySerial.print(char(26)); | |
Serial.println("CRTL+Z was sent to the module!"); // just print in the Serial monitor that we sent the special char | |
} else { | |
delay(200); | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment