GSM program to identify calling number using software serial

We are developing a program to identify the number called to our GSM module(SIM 900-not GSM shield).
We are using software serial.The program is not working.Can you please help with that?

sketch_may04b.ino (1.88 KB)

Welcome to the Forum. Please read this post: How to use this forum - please read. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Your formatting is annoying. Also please remove the lines that you have commented out.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Rather than just say, "it's not working", please explain exactly in what way it isn't working.

This is the code (after ctrl-T formatting)

#include <SoftwareSerial.h>

SoftwareSerial SIM900(10, 11); // RX, TX
char inchar;
int onff = 0;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);

  // WAKE UP GSM
  //  SIM900power();
  SIM900.begin(9600);
  delay(200000);
  SIM900.println("AT+CLIP=1\r");
  delay(100);
}

//void SIM900power()
//{
//digitalWrite(9,HIGH);
//delay(1000);
//digitalWrite(9,LOW);
//delay(7000);
//}

void dosomething()
{
  if (onff == 0)
  {
    onff = 1;
    digitalWrite(12, HIGH);
    digitalWrite(13, LOW);
    Serial.println("D12 high D13 low");
  }
  else
  {
    onff = 0;
    digitalWrite(12, LOW);
    digitalWrite(13, HIGH);
    Serial.println("D12 low D13 high");
  }
}

void loop()
{ // run over and over
  if (SIM900.available() > 0)
  {
    inchar = SIM900.read();
    if (inchar == 'a')
    {
      delay(10);
      inchar = SIM900.read();

      if (inchar == 'b')
      {
        delay(10);
        inchar = SIM900.read();
        if (inchar == 'c')
        {
          delay(10);
          inchar = SIM900.read();

          if (inchar == 'd')
          {
            delay(10);
            inchar = SIM900.read();

            if (inchar == 'e')
            {
              delay(10);
              inchar = SIM900.read();

              if (inchar == 'f')
              {
                delay(10);
                inchar = SIM900.read();

                if (inchar == 'g')
                {
                  delay(10);
                  inchar = SIM900.read();

                  if (inchar == 'h')
                  {
                    delay(10);
                    inchar = SIM900.read();

                    if (inchar == 'i')
                    {
                      delay(10);
                      inchar = SIM900.read();

                      if (inchar == 'j')
                      {
                        delay(10);
                        inchar = SIM900.read();

                        if (inchar == 'k')
                        {
                          delay(10);
                          inchar = SIM900.read();

                          if (inchar == 'l')
                          {
                            delay(10);
                            inchar = SIM900.read();

                            if (inchar == 'm')
                            {
                              Serial.println("dosomething");
                              delay(10);
                              dosomething();
                              delay(60000);
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Study Serial input basics

You did in nearly no way develop a program to identify the number called to your SIM 900.
Ok, you are advising the module to give you the information… (that is the nearly)

You have a 3 minute 20 second delay after power up, that is crude, unresponsive and makes your debugging cycles take ages.
You scatter your code with useless delays.
You don’t process the incoming data.

One way it could work:

  • collect all incoming characters until you see a CR (you can savely ignore LF)
  • check if the line begins with “+CLIP:”
  • if it does, get the number behind it until you hit a ‘,’