Arduino Mega interface with GSM Sim900A SMS receive

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

Please post the complete sketch within </> code-tags

I am facing the receiving sms by gsm
The code is given below

#include <SoftwareSerial.h>
SoftwareSerial SIM900(15,14);
char incoming_char=0;

void setup()
{
Serial.begin(9600); // for serial monitor
SIM900.begin(4800); // for GSM shield
// SIM900power(); // turn on shield
delay(20000); // give time to log on to network.

SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
delay(100);
SIM900.print("AT+CMGD=1,4\r");  // Deletes all SMS saved in SIM memory
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
}

void loop()
{
// Now we simply display any text that the GSM shield sends out on the serial monitor
Serial.println("loop");
if(SIM900.available() > 0)
{
Serial.print("waiting");

incoming_char=SIM900.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
while(1){};

}
}

output

Please modify your post so the code sits in between </> code-tags

void loop()
{
// Now we simply display any text that the GSM shield sends out on the serial monitor
Serial.println(“loop”);
if(SIM900.available() > 0)
{
Serial.print(“waiting”);

incoming_char=SIM900.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
while(1){};
}
}

With this code you will print 'loop' until a single character is received, which then gets printed, and then goes into an eternal loop. That will not provide you with correct information about the SIM's response. Also the mega has 4 hwSerial, you should use one of them for your SIM and not swSerial.
How about you start with the Serial Passthrough example (File -> Examples -> Communication -> SerialPassThrough)

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());   // read it and send it out Serial (USB)
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.