Hello everyone,
I am doing some code for request send data through sms commands.
Here is my code:
#include <SoftwareSerial.h>
// Configure software serial port
SoftwareSerial SIM900(7, 8);
// Create variable to store incoming SMS characters
char incomingChar;
void setup() {
Serial.begin(9600);
SIM900.begin(9600);
// Give time to your GSM shield log on to network
delay(2000);
Serial.print("SIM900 ready...");
// AT command to set SIM900 to SMS mode
SIM900.println("AT+CMGF=1\r");
delay(1000);
// Set module to send SMS data to serial out upon receipt
SIM900.println("AT+CNMI=2,2,0,0,0\r");
delay(1000);
}
void loop(){
if (SMSRequest()){
delay(10);
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
SIM900.println("AT + CMGS = \"+911234567890\"");
delay(1000);
// REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
String dataMessage = ("Hello From Arduino");
// Send the SMS text message
SIM900.println(dataMessage);
delay(100);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
}
delay(100);
}
boolean SMSRequest() {
if(SIM900.available() >0) {
incomingChar=SIM900.read();
if(incomingChar=='S') {
delay(10);
Serial.print(incomingChar);
incomingChar=SIM900.read();
if(incomingChar =='T') {
delay(10);
Serial.print(incomingChar);
incomingChar=SIM900.read();
if(incomingChar=='A') {
delay(10);
Serial.print(incomingChar);
incomingChar=SIM900.read();
if(incomingChar=='T') {
delay(10);
Serial.print(incomingChar);
incomingChar=SIM900.read();
if(incomingChar=='E') {
delay(10);
Serial.print(incomingChar);
Serial.print("...Request Received \n");
return true;
}
}
}
}
}
}
return false;
}
Output window shown when I type "STATE" and send it to GSM module:
SIM900 ready...STATE...Request Received
S
but no text received in my mobile when I am sending "STATE".
Please help me.