Interfacing Sim900A GSM Module with Arduino Mega R3

Connection Details
Rx of GSM to Tx0 of Mega
Tx of GSM to Rx0 of Mega
Powering th GSM module by a 12V 2amps supply, it is connecting to the network and working fine.

Code Details:
char phone_no[]="9*********";
void setup() {
Serial.begin(9600);
delay(2000);
Serial.println("AT");
Serial.print("ATD");
Serial.print(phone_no);
Serial.println(";");
delay(30000);
Serial.println("ATH");
}

But it does not make the call.
Help needed ASAP.
Thanks and Regards.

Try listening (by looking at Serial.available() and Serial.read() ) if you get any acknowledge or error from the module. The first AT should return a OK.

For this you should move the GSM comm to TX/RX1 (wires and change the code) and free the TX/RX so you print diagnostic on your SerialMonitor.

Msquare:
Try listening (by looking at Serial.available() and Serial.read() ) if you get any acknowledge or error from the module. The first AT should return a OK.

For this you should move the GSM comm to TX/RX1 (wires and change the code) and free the TX/RX so you print diagnostic on your SerialMonitor.

First of all thankyou so much for replying :slight_smile:
I have used this code
char msg;
char inData[200];
char inChar;
int a;
void setup()
{
Serial.begin(9600);

for (a=0;a<5;a++)
{
Serial.println("AT\r");

if (Serial.available())
{
// store everything into "inData"
int i;
for (i=0;i<10;i++)
{
inChar= Serial.read();
inData = inChar;

  • }*
  • Serial.print(inData);*
  • }*
  • }*

}
void loop()
{

  • // put your main code here, to run repeatedly:*
    }
    and i am getting this at the serial monitor
    AT
    AT
    AT
    AT
    AT
    which i think means I am not getting any reply.
    What should I do to make it work ?

I think it only means that you can send 5 times "AT\r" before you get an answer.

Whandall:
I think it only means that you can send 5 times "AT\r" before you get an answer.

``

I have seen a lot of video tutorials interfacing uno with sim900A module is it that it's not compatible with MEGA?

You do not wait for an answer.

You blast three strings in the transmit buffer, then you stop looking for input.

"which i think means I am not getting any reply."

Shure, but probably just not yet.

With your sketch you will miss any messages arriving after the 5th "AT\n" was put into the tx buffer.

Your sending only takes 296 µS on my Mega.

Transferring one byte with 9600 baud roughly takes 960µS.

How come you expect an answer to arrive before the first byte of the question is even sent?

char msg;
char inData[200];
char inChar;
int a;
unsigned long startTime;
unsigned long endTime;
void setup()
{
  Serial.begin(9600);
  startTime = micros();
  for (a = 0; a < 5; a++)
  {
    Serial.println("AT\r");
    if (Serial.available())
    {
      // store everything into "inData"
      int i;
      for (i = 0; i < 10; i++)
      {
        inChar = Serial.read();
        inData[i] = inChar;
      }
      Serial.print(inData);
    }
  }
  endTime = micros();
  Serial.print("micros for send ");
  Serial.println(endTime - startTime);
}
void loop(){}
AT
AT
AT
AT
AT
micros for send 296

Whandall:
You do not wait for an answer.

You blast three strings in the transmit buffer, then you stop looking for input.

"which i think means I am not getting any reply."

Shure, but probably just not yet.

With your sketch you will miss any messages arriving after the 5th "AT\n" was put into the tx buffer.

Thanks for the reply, kindly see the original post I have attached two image

  1. One of the GSM Module.
  2. The second one is the connections made with the Arduino Mega.

I have also attached the code with it, kindly please tell me whats wrong in the interfacing/code due to which I am not able to make any calls via it.

It's nice of you to read data ... but you do not look at it. So how do you know if it says OK or ERR?

You need to use TWO serial lines here - one to communicate with your PC so you can see the answer the GSM makes, and one Serial to talk to the GSM.

The MEGA that your are using on the picture does have multiple Serials. The first Serial is the only that sends to the Pc via the USB.

Change your code so it does something along the lines of

 Serial.begin(9600) ; Serial.println("Test prog start") ; // This serial is our terminal
 Serial1.begin(9600);   // This Serial does IO to the GSM (using the pins labelled TX1/RX1)
 ...
 Serial1.println("AT");
 char C = '.' ;
 while ( C != '\n' ) {  // keep looking until we get a LINE back from the module
   if (Serial1.available()>0 ) { // When a character arrives
     C = Serial1.read() ;
     Serial.print(C) ;  // echo it to PC
   }
 }

While you are trying verify your GSM module in general, you might want to use the same while-construct that transfers the characters from Serial to Serial1 - then you can type the commands in your SerialMonitor and see the answer. You can skip the test for \n making the Arduino a simple pass-throu - but you will need that again, when you start putting your real program together.