Hello All,
I am new Arduino coding, currently working on GSM interface i attached the code here , the below code I am facing issue it is not receiving the sms. the same GSM is working when i connected to via RS232 in PC directly via Putty. But the same AT command if i coded via Arduino am not getting the response all. Only for AT+CNMI=2,2,0,0,0 i am not getting response,
Let me know how to solve the below error.
Code
void setup()
{
pinMode(LAMP, OUTPUT);
pinMode(SYRIN, OUTPUT);
digitalWrite(SYRIN, HIGH);
digitalWrite(LAMP, HIGH);
pinMode(LAMPLED, OUTPUT);
pinMode(SYRINLED, OUTPUT);
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
Serial.print("Enter s or r or t ");
//Configure the GSM to txt receivce mode
updateSerial();
mySerial.println("AT");
updateSerial();
mySerial.println("AT");
updateSerial();
mySerial.println("AT+IPR=9600");
updateSerial();
mySerial.println("AT&W");
updateSerial();
mySerial.println("AT");
updateSerial();
mySerial.println("AT+CMGF=1");
updateSerial();
mySerial.print("AT+CNMI=2,2,0,0,0");
updateSerial();
SendMessage("Setup Finished", "**********");
updateSerial();
mySerial.print("AT+CNMI=2,2,0,0,0");
updateSerial();
delay(2000);
Serial.println( "Setup Finished" );
}
void loop()
{
int checkNum = 0;
while (mySerial.available() > 0)
{
char c = mySerial.read();
temp = temp + c;
smsflag = true;
checkNum = temp.indexOf("+91");
}
if (checkNum >= 1)
{
*************do the function ************
}
void SendMessage(String text, String num)
{
mySerial.println("AT+CMGF=1");
delay(2000);
Serial.println("AT+CMGS="+91" + num + ""\r");
mySerial.println("AT+CMGS="+91" + num + ""\r");
delay(2000);
Serial.println(text);
mySerial.println(text)
delay(2000);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(2000);
mySerial.print("AT+CNMI=2,2,0,0,0");
delay(2000);
}
void updateSerial()
{
delay(1000);
while (Serial.available())
{
mySerial.write(Serial.read());
}
while (mySerial.available())
{
Serial.write(mySerial.read());
}
}
Response
Enter s or r or t AT
21:03:03.406 ->
21:03:03.406 -> OK
21:03:04.389 -> AT
21:03:04.389 ->
21:03:04.389 -> OK
21:03:05.418 -> AT+IPR=9600
21:03:05.418 ->
21:03:05.418 -> OK
21:03:06.401 -> AT&W
21:03:06.401 ->
21:03:06.448 -> OK
21:03:07.431 -> AT
21:03:07.431 ->
21:03:07.431 -> OK
21:03:08.461 -> AT+CMGF=1
21:03:08.461 ->
21:03:08.461 -> OK
21:03:09.444 -> AT+CNMI=2,2,0,0,0AT+CMGS="+91**********"
21:03:13.516 -> Message from device
21:03:21.565 -> Setup Finished