My intention is to control an LED according to the content of the SMS received. For example, if the SMS is "ON", turn on the LED and if it is "OFF", turn it off. I referred many sites and got the below code. The digital pins 9 and 10 are used instead of Rx and Tx to avoid the code uploading problem.
(I have kept the different versions of AT commands commented in the code because I'm not sure which one is correct. With the current one, I'm able to get some kind of output which I've mentioned after the code.)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
char msg;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600); // Setting the baud rate of GSM Module
delay(1000);
//mySerial.print("AT+CMGF=1r"); // set SMS mode to text
mySerial.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
//mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
//mySerial.print("AT+CNMI=2,2,0,0,0r");
mySerial.print("AT+CNMI=1,2,0,0,0\r"); // AT Command to receive a live SMS
delay(100);
Serial.println("Ready");
}
void loop()
{
if (mySerial.available()>0)
{
msg=mySerial.read();
Serial.print(msg);
}
}
This is the output I'm getting..
Ready
AT+CMGF=1
AT+CNMI=1,2,0,0,0
OK
+CMTI: "SM",31
+CMTI: "SM",32
+CMTI: "SM",33
+CMTI: "SM",34
The issue is, I'm not able to retrieve the message content. What I'm getting is
"+CMTI: "SM",31"
"+CMTI: "SM",32"
and the number keeps on incrementing. (33, 34 and so on).
I do understand that I have to parse the message to get the exact content, but here I'm not getting the content at all. What exactly should I do to get the SMS content? Could anybody help me to solve this?
One more thing, the GSM module I'm using is a SIM900A type (from elementzonline.com). It's not a shield type, so I've made connections using wires; the Rx, Tx connections and the ground one.
(Sorry for the bad explanation, I'm a complete noob in Arduino, a hobbyist.)
Thanks in advance.