pcbway





Update: I have updated the code and removed the bug. Thanks for informing. Now this code will work perfectly.


Receive text message,Arduino at commands,gsm at commands, get sms with at commands, get sms with arduino gsm

Hello friends, hope you all are fine and having good health. Today, as the name suggests, I am gonna post on how to Receive SMS with AT Commands using Sim900 and Arduino. I have already posted a tutorial on How to Send SMS with Arduino UNO and Sim900, so now we are gonna check the opposite. Sending SMS is quite easy, you just need to write some AT commands and write the message you wanna send and hit the Cntrl + Z and it will be sent. But receiving a text message on your SIM900 shield is a bit difficult because now you need to place a check when user will send a message. So, ideally whenever anyone send a message to your SIM900 module, you should get notified. Today, we are gonna cover this how to receive SMS with AT Commands in detail.

Now, after you get notified, there’s a need to read the message as well and also who has sent this message. So, we are also gonna cover it today. So, first of all we will place a check that whenever someone sends a message to our SIM900 module, we get notified and after that we will extract the message and the mobile number of sender. We have designed this code after a lot of effort that’s why this code isn’t free but we haven’t placed a very small amount of $20 so that engineering students can also buy it easily. We can also interface our GSM board with other microcontrollers like PIC Microcontroller as well as 8051 Microcontroller. I have also posted tutorial on How to Receive SMS with SIM900 & PIC Microcontroller and How to Send SMS with PIC Microcontroller so if you are working on PIC Microcontroller then you must give it a look. So, let’s get started with How to receive SMS with AT Commands using SIM900 and Arduino.

You must also check GSM Library for Proteus, using this library you can easily simulate your GSM module in Proteus ISIS. Moreover, also have a look at Send SMS with Sim900D in Proteus ISIS in which I have designed a simulation of sms sending in Proteus ISIS.

Receive SMS with AT Commands using Sim900 and Arduino

  • There are many GSM modules available in the market so it doesn’t matter which one you are using unless its having SIM900 module in it.
  • I have explained in my previous post that all GSM modules work on AT commands, so here first of all we are gonna have a look on AT commands we are gonna use for receiving the SMS.
  1. ATE0 – IT is used to turn off the Echo of GSM shield.
  2. AT – Just to check that your GSM module is working fine.
  3. AT + CMGF = 1 – This command will convert the message style to text. In other words we are telling our shield that we are expecting a text message.
  4. AT+CNMI=1,2,0,0,0 – This command will alert our GSM shield and now whenever it will receive message, it will automatically send an alert on the serial port.
  • We are gonna use these four commands in our code and we will be able to receive text message on the GSM shield.
  • Remember we have to put Enter after each of the above AT commands in order to execute it.
  • Below is the first phase of the code and as you can see in this code we are simply sending these four commands serially from arduino to GSM shield.
  • These are two functions I have shown below, the first function is Config() which is simply sending the commands via serially and then the Response() function which is called after every AT command and is receiving the response of that AT command.
  • So, here’s the partial code for How to Receive SMS with AT Commands using Sim900 and Arduino.

  • The response of these commands is shown below on the Serial Monitor of Arduino.
  • For each AT command, we get a response “OK” from the GSM shield.

Receive text message,Arduino at commands,gsm at commands, get sms with at commands, get sms with arduino gsm




  • Now, I know that I have sent all these four AT commands and my GSM shield is ready to receive the text messages and will inform me.
  • So, when you send a message to your GSM shield, it will give a notification as shown in the below figure:

Receive text message,Arduino at commands,gsm at commands, get sms with at commands, get sms with arduino gsm

  • Each message received by SIM900 module is start with “+CMT” and after that it has the mobile number of the sender and at the end lies the body of the message, which in our message is “www.TheEngineeringProjects.com”
  • So now let’s extract this mobile number and the text body from this CMT string.

Getting the SMS Text & Sender Mobile Number

  • Till now we have learnt How to Receive SMS with AT Commands using Sim900 and Arduino and send you notification over the serial monitor.
  • Now we have to place some checks in our code so that we could be able to get the required data out of this string.
  • In order to do so, I am gonna first save this CMT string into an array, which I named as RcvdMsg[index].
  • But before saving the data into this string, first I need to make sure that I am actually getting the requried string, that’s aso possible that I am receving some garbage values.
  • So, I placed a check first, which is checking for these four characters “+CMT”, and when I got these character on my serial terminal I got sure that I have the string ready so I made the index = 0 and starting receving the string.



  • Next thing I need to do is make sure that I have got the complete string, that was really a tricky part as there’s no end character in the string.
  • So, I used “n” null character for that. If you check the string then you can see that we are getting two null characters in complete string.
  • I placed this check that when I get 2 null characters means I have got the complete string so I stopped receving the string.
  • After that I simply count the charaters, in my string the sender mobile number is at posting 4 to 16 so I made a loop and save it in another array. and similarly did for the message text.
  • Now when I send message after uploading this final code into my Arduino board, I get the below result on my Serial Monitor.

Receive text message,Arduino at commands,gsm at commands, get sms with at commands, get sms with arduino gsm

  • Isn’t it cool 🙂 So, now we have separated the complete text as well as the sender’s mobile number from our GSM string and we can use it anywhere we want.
  • We can use this mobile number in the previous post code and can reply some text back and can also give a missed call to the user, anything we want. I am gonna post on How to send a call using SIM900 in the next post.
  • You can buy the codefor How to Receive SMS with AT Commands using Sim900 and Arduino from our shop by clicking the below button:

Buy Code for Receiving SMS with AT Commands using Sim900 and Arduino

  • I have highlighted all the functions in the code.
  • As I always say, understand it first and then write on your own and do mistakes so that you learn.

That’s all for today. I hope you have enjoyed this project named Receive SMS with AT Commands using Sim900 and Arduino. I will meet you guys in the next post. Till then have fun !!! 🙂

77 Comments

  1. Haaiz Sir,

    I have a question. I’m using a Siemens TC35i to send en receive SMS
    but on the test program where do you get de “R” and “K” value for the response of the shield ?
    Can I use the same condition for a TC35i ?
    Because when I test my tc35i with your code, I get a “GSM not working” for all 4 commands.

    • Hi,

      First of all, it’s not the way to work on any new module. You should first try to do the basics . Don’t run mu code yet just send the AT command to your module and get the response.

      If you got succeeded in receiving the response then move forward. Let me know when you get the response n then we will discuss it further.

      Thanks.

        • Receiving sms is quite tricky, it normally doesn’t work in first attempt so give it some time and test it again and again. Moreover, don’t test the whole code instead test it step by step. Try AT commands and then check their response and then move on.

          • Hi, First I send sms it receives and displays, but since the second onwards, it receives but does not display any text whatsoever.Help me. Thanks.

      • Hi Syed,

        When i use this code it works fine the first message i send the arduino, however each message after this skips the +CMT check so no message is displayed?

        Thanks for you time

        Andy

  2. Hi ,
    well thank u Syed for every thing ,
    but I have little problem in my project and I hope to help me ,
    my project is smart home security .
    Im using Icomsat v1.1 GSM and arduino uno and RIP,Gas,and water sensors and Relay
    meaning I want my project send and receive SMS.
    Windows 7 , Arduino IDE 1.6.0
    Im using AT commend .

    its sending very good but it take about 2minuts to receive sms and excute it .
    this is my cod >>
    #define _SS_MAX_RX_BUFF 256 //RX BUFFER SIZE
    #include
    char inchar; // Will hold the incoming character from the GSM shield
    SoftwareSerial SIM900(4, 6);

    int Buzzer = 13;
    int x = 0;
    int y = 0;
    float z =0;
    int RIP_sensor = 12;
    int Room2 = 11 ;
    int Room1 = 7 ;
    int Home_light = 8;
    int water_sensor = 0;
    int Gas_sensor = 0;
    float Tem_sensor = 0;
    float temp =0.0;
    String textForGAS ;
    String textForRIP ;
    String textForWATER;
    String textForTAM ;

    void setup()
    {
    Serial.begin(19200);
    // set up the digital pins to control
    pinMode(RIP_sensor, INPUT);
    pinMode(Buzzer, OUTPUT);
    pinMode(Room1, OUTPUT);
    pinMode(Room2, OUTPUT);
    pinMode(Home_light, OUTPUT);
    digitalWrite(Buzzer, LOW);
    digitalWrite(Room1, LOW);
    digitalWrite(Room2, LOW);
    digitalWrite(Home_light, LOW);

    // wake up the GSM shield
    SIM900.begin(19200);
    delay(20000); // give time to log on to network.
    SIM900.print(“AT+CMGF=1r”); // set SMS mode to text
    delay(100);
    SIM900.print(“AT+CNMI=2,2,0,0,0r”);
    // blurt out contents of new SMS upon receipt to the GSM shield’s serial out
    delay(100);
    Serial.println(“Ready…”);
    }

    void sendSMS(String message)
    {
    SIM900.print(“AT+CMGF=1r”);
    delay(100);
    SIM900.println(“AT + CMGS = “+967737704074″”);
    delay(100);
    SIM900.println(message);
    delay(100);
    SIM900.println((char)26);
    delay(100);
    SIM900.println();
    delay(5000);
    }

    void loop()
    {
    //If a character comes in from the cellular module…
    if (SIM900.available())
    {
    inchar = SIM900.read();
    Serial.println(inchar);
    if (inchar == ‘#’)
    {
    delay(10);

    inchar = SIM900.read();
    if (inchar == ‘a’)
    {
    delay(10);
    inchar = SIM900.read();
    if (inchar == ‘0’)
    {
    digitalWrite(Home_light, HIGH);
    }
    else if (inchar == ‘1’)
    {
    digitalWrite(Home_light, LOW);
    }
    delay(10);
    inchar = SIM900.read();
    if (inchar == ‘b’)
    {
    inchar = SIM900.read();
    if (inchar == ‘0’)
    {
    digitalWrite(Room1, HIGH);
    }
    else if (inchar == ‘1’)
    {
    digitalWrite(Room1, LOW);
    }
    delay(10);
    inchar = SIM900.read();
    if (inchar == ‘c’)
    {
    inchar = SIM900.read();
    if (inchar == ‘0’)
    {
    digitalWrite(Room2, HIGH);
    }
    else if (inchar == ‘1’)
    {
    digitalWrite(Room2, LOW);
    }
    delay(10);
    }
    }
    SIM900.println(“AT+CMGD=1,4”); // delete all SMS
    }
    }
    }

    // put your main code here, to run repeatedly:
    Gas_sensor = (analogRead(A0));
    water_sensor = (analogRead(A1));
    Tem_sensor = (analogRead(A2));
    temp = Tem_sensor * 0.48828125;
    //program for GAS sensor
    if (temp > 70.0)
    {
    textForTAM = “Alarm ! The degree of Tamperture is :n “;
    textForTAM.concat(temp);
    textForTAM = textForTAM +”C”;
    digitalWrite(Buzzer, HIGH);
    Serial.println(textForTAM);
    sendSMS(textForGAS);
    delay(1000);
    do {
    z = (analogRead(A0));
    } while (z >= 141.312);
    }
    else {
    digitalWrite(Buzzer, LOW);
    delay(1000);
    }

    //program for GAS sensor
    if (Gas_sensor > 500)
    {
    textForGAS = “Alarm ! there is Gas by rate :n “;
    textForGAS.concat(Gas_sensor);
    digitalWrite(Buzzer, HIGH);
    Serial.println(textForGAS);
    sendSMS(textForGAS);
    delay(1000);
    do {
    x = (analogRead(A0));
    } while (x >= 499);
    }
    else {
    digitalWrite(Buzzer, LOW);
    delay(1000);
    }

    //program for Water sensor
    if (water_sensor > 830)
    {
    digitalWrite(Buzzer, HIGH);
    delay(60);
    digitalWrite(Buzzer, LOW);
    delay(40);
    textForWATER = “Warnning ! n Tank is Empty ! tourn on the Dynamo “;
    textForWATER.concat(water_sensor);
    Serial.println(textForWATER);
    sendSMS(textForWATER);
    delay(1000);
    do {
    y = (analogRead(A1));
    } while (y >= 829);
    }

    else if (water_sensor < 175 )
    {
    digitalWrite(Buzzer, HIGH);
    delay(60);
    digitalWrite(Buzzer, LOW);
    delay(40);
    textForWATER = "Warrning ! n Tank is Full ! tourn off the Dynamo ";
    textForWATER.concat(water_sensor);
    Serial.println(textForWATER);
    sendSMS(textForWATER);
    delay(1000);
    do {
    y = (analogRead(A1));
    }
    while (y <= 176);
    }

    else {
    digitalWrite(Buzzer, LOW);
    delay(1000);
    }
    }
    thank you

    • If its receving the message then it means your code is correct and working and if its taaking time in receving this message then its network fault. Attach antenna with your GSM shield and it will perform quicker.

      • sir i got the gsm response well, but when i try to run the whole code I get the following errors. how can I solve this.?

        SIM900.ino: In function ‘void RecSMS()’:
        SIM900.ino:93:19: error: ‘amp’ was not declared in this scope
        SIM900.ino:93:22: error: expected ‘)’ before ‘;’ token
        SIM900.ino:93:24: error: ‘amp’ was not declared in this scope
        SIM900.ino:93:45: error: expected ‘;’ before ‘)’ token
        SIM900.ino:94:22: error: expected ‘)’ before ‘;’ token
        SIM900.ino:94:45: error: expected ‘;’ before ‘)’ token
        SIM900.ino:95:22: error: expected ‘)’ before ‘;’ token
        SIM900.ino:95:45: error: expected ‘;’ before ‘)’ token
        SIM900.ino:109:18: error: ‘lt’ was not declared in this scope
        SIM900.ino:109:23: error: expected ‘)’ before ‘;’ token
        SIM900.ino:109:24: error: name lookup of ‘x’ changed for ISO ‘for’ scoping [-fpermissive]
        SIM900.ino:109:24: note: (if you use ‘-fpermissive’ G++ will accept your code)
        SIM900.ino:109:27: error: expected ‘;’ before ‘)’ token
        SIM900.ino:116:19: error: ‘lt’ was not declared in this scope
        SIM900.ino:116:31: error: expected ‘)’ before ‘;’ token
        SIM900.ino:116:35: error: expected ‘;’ before ‘)’ token
        Error compiling.

      • I have used Arduino Mega 2560 , SIM900a (SIMCom) and on running your code I always get
        “GSM not Found” message for all 4 commands.
        Expecting your help!

      • Hi Sr.
        I have the same problem with arduino uno, the first 4 commands always display “GSM not found”, can you tell me why or send me a copy of your sketch where this has been corrected.
        Thanks in advance
        Regards
        Jose

  3. Thank you very much for this wonderful code, It helps me a lot! I have a question Sir. When I send text message from my mobile phone it reads for the first time but when I send another message only the mobile number appeared. Thank you Sir more power.

    • Hi,

      Yeah it has this small bug, I have tested it. Will remove this bug soon. Thanks for mentioning.

      Regards.

    • After printing your message, clear all the buffers and assign initial values to all integers. Make a function to do this say clear_everything() and call it just after last serial.println(). It will work for sure.

  4. Great program! I am working with sim300 and atmega8 arduino. The foll. is a program to send an sms. But the sms does not get sent. It just displays on the serial monitor. The place from where i got the program uses a peizo sensor to send sms but i dont want to use it. Pls check and suggest changes that i should make to send an SMS everytime reset is pressed. i.e (The program is run) My current rogram is:-
    void setup()
    {
    Serial.begin(9600); // the GPRS baud rate
    delay(2500);

    Serial.println(“AT”); //To check if GSM module is working
    delay(2000);
    Serial.println(“AT+CMGF=1”); // set the SMS mode to text
    delay(1500);
    }

    void loop()
    {
    delay(1500);
    Serial.print(“AT+CMGS=”);
    Serial.write(“34”);
    Serial.print(“+919408955901”);
    Serial.write(“34”);

    delay(1500);
    Serial.println(“This is a sms from BCG”); //this is the message to be sent
    delay(1500);
    Serial.write(“26”); //Ascii code of ctrl+z to send the message
    while(1);
    {
    }
    }
    THANK YOU!!!!!!!!!

  5. Hello Sir,
    Thank you for the code, its great…
    Is there any command which can display all my sms that are stored in the SIM card? or any particular message which is at ‘n’th position?
    Please respond
    Thank you

    • Hi,

      Use this command Serial.print(“AT+CMGL=\”ALL\”\r”); and it will display all the messages stored in the SIM card. Also use Responsefunction in order to get that response.

      Thanks.

  6. Hello I write Function for clear the buffs but not Working again when i send second sms not Display my function is

    void Clear(){

    char RcvdMsg[200] = ” “;
    int RcvdCheck = 0;
    int RcvdConf = 0;
    int index = 0;
    int RcvdEnd = 0;
    char MsgMob[15];
    char MsgTxt[50];
    int MsgLength = 0;

    }

    • Yeah others have also talked about this problem in comments, give me a day and I will make the correction andwill upload the new code.

  7. thank you sir for this tutorial , it worked with my arduino uno and GSM module

    but i need to control something (let’s say LED connected on digital pin 13) , so i added that piece of code in the void loop function
    if ( MsgTxt== “ON”) {digitalWrite(13,HIGH);}
    else digitalWrite(13,LOW);

    but it isn’t working
    can you help me please ? 🙂

  8. Dear Syed Zain Nasir,
    first thank you for the sketch it is really great.
    i just want to ask what are the serial letters “K” & “R” that you check in Response() function, because i always get “GSM not found”. I use Arduino Leonardo.
    Regards

  9. Hi sir, your updated codes still does not work. can you please recheck? It appears that the first message is printed but the second message only displays the mobile number of the first sender. Please update it as soon as possible.

  10. Yeah I have the same problem! Only the SMS body appears first time, it shows nothing when I send another SMS even though it receives the message.

  11. sir i got the gsm response well, but when i try to run the whole code I get the following errors. how can I solve this.?

    SIM900.ino: In function ‘void RecSMS()’:
    SIM900.ino:93:19: error: ‘amp’ was not declared in this scope
    SIM900.ino:93:22: error: expected ‘)’ before ‘;’ token
    SIM900.ino:93:24: error: ‘amp’ was not declared in this scope
    SIM900.ino:93:45: error: expected ‘;’ before ‘)’ token
    SIM900.ino:94:22: error: expected ‘)’ before ‘;’ token
    SIM900.ino:94:45: error: expected ‘;’ before ‘)’ token
    SIM900.ino:95:22: error: expected ‘)’ before ‘;’ token
    SIM900.ino:95:45: error: expected ‘;’ before ‘)’ token
    SIM900.ino:109:18: error: ‘lt’ was not declared in this scope
    SIM900.ino:109:23: error: expected ‘)’ before ‘;’ token
    SIM900.ino:109:24: error: name lookup of ‘x’ changed for ISO ‘for’ scoping [-fpermissive]
    SIM900.ino:109:24: note: (if you use ‘-fpermissive’ G++ will accept your code)
    SIM900.ino:109:27: error: expected ‘;’ before ‘)’ token
    SIM900.ino:116:19: error: ‘lt’ was not declared in this scope
    SIM900.ino:116:31: error: expected ‘)’ before ‘;’ token
    SIM900.ino:116:35: error: expected ‘;’ before ‘)’ token
    Error compiling.

  12. I have used Arduino Mega 2560 , SIM900a (SIMCom) and on running your code I always get
    “GSM not Found” message for all 4 commands.
    Expecting your help!

    • Hi,

      Check yourpinconnectionsand andif they are correct then increase the delay before sending first command. Few modules are slow to response.

      Thanks.

      • My project is mini But project is that type of one lamp is control (on, off) through sms.I have taken one GSM Module Sim900a and one Arduino uno R3. Sir how to interface and GSM module with Arduino uno R3. And programming code. Sir Plz help me.

        • #include
          #include

          static const int RXPin = 4, TXPin = 3;
          static const int GPSBaud = 9600;
          TinyGPSPlus gps;
          SoftwareSerial ss(RXPin, TXPin);

          void setup()
          {
          Serial.begin(9600);
          ss.begin(GPSBaud);
          }

          void loop()
          {
          // This sketch displays information every time a new sentence is correctly encoded.
          while (ss.available() > 0)
          if (gps.encode(ss.read()))
          displayInfo();

          if (millis() > 10000 && gps.charsProcessed() < 10)
          {
          Serial.println(F("No GPS detected: check wiring."));
          while(true);
          }
          }

          void displayInfo()
          {
          Serial.print(F("Location: "));
          if (gps.location.isValid())
          {
          Serial.print(gps.location.lat(),4);
          Serial.print(F(","));
          Serial.print(gps.location.lng(),4);
          }
          else
          {
          Serial.print(F("INVALID"));
          }

          Serial.println();
          }

          void Sendsms()
          {
          Serial.println("AT+CMGF=1\r\n");
          delay(5000);
          Serial.print("AT+CMGS=\"+923339383046");
          Serial.print("\"\r\n");
          delay(5000);
          Serial.print(F("Location: "));
          Serial.write(0x1A);
          while(3);

          }

          Sir.
          This is my code Gps get coordinates correctly but doesn't send properly throuh GSM module (Sim900a).help me in this code. At sherhasan78@gmail.com.

  13. AOA how r u sir?
    Sir please help me in my project if you can.. sir i need complete arduino code for electronic notice board.
    my project is that simple text msg from your mobile to arduino kit n arduino display that msg on LCD 16*2 lcd. plz help me 🙁 i m really very worried about it:(
    my mob no:0334-8473040

  14. Hi Sir,
    Am trying to receive sms with SIM900 and Arduino UNO but when i have send a message to sim900,l serial monitor display
    +CMTI: “SM”=1
    value of SM increase as to number of times i send sms to SIM900
    i have use following code :

    #include
    SoftwareSerial gsm(7, 8);

    char incoming_char=0;

    void setup()
    {
    Serial.begin(9600); // for serial monitor
    gsm.begin(2400); // for GSM shield

    delay(20000); // give time to log on to network.
    gsm.println(“ATE0\r”);
    delay(100);
    gsm.println(“AT\r”);
    delay(100);
    gsm.println(“AT+CMGF=1\r”);

    delay(100);
    gsm.println(“AT+CNMI=0,0,0,0,0\r”);
    delay(100);
    gsm.println(“AT+CNMI=2,2,0,0,0\r”);
    delay(100);
    Serial.println(“GSM READY”);
    }

    void loop()
    {

    if(gsm.available() >0)
    {
    incoming_char=gsm.read(); //Get the character from the cellular serial port.
    Serial.println(incoming_char); //Print the incoming character to the terminal.

    }
    }

    Please help me out ‘
    Thank You.

  15. Sir,
    Still it can only read the first message only. Please help me in reading the upcoming messages also.
    Thanks in advance.

  16. thanks a lot for your tutorial..can you post a similar post regarding web server..recieving data and storing it on a server…thank you….

  17. Hi Syed,
    How are u? I am testing your code, what i want to do is read the Imei number. When I test your code, I could read char by char, but i cant read a hole phrase. How can I do that?
    Can you give me a hand please?
    Thank you very much
    Jose Luis

    • In this code, I am not reading it character by character. I am saving it in Array so from that arracy you can get the IMEI number. Need more help then add me on skype.

  18. Hello Syed,
    This is really great and helped me a lot!
    However, I have several GSM modules and some work with this code, others do not (even with the same setup). I’m really stuck on why the other modules give very strange outputs (big ‘?’ characters as though it were initialized on the wrong baud rate). I’ve tried initializing the rx pin as low (digitalWrite(rxPin, LOW)) which only allows me to confirm that something has been written to the SIM card (sim.available() > 0). So I’m under the impression that my tx pin works, but something is happening during the rx transfer. I tried changing inverse_logic to true by declaring SoftwareSerial(rxPin, txPin, true). But this has also not helped.

    All of this hangup occurs when I call your Response() routine. On the working GSM modules (with the same setup mind you), the commands initialize as OK, on the others, they simply say GSM not found.

    I have attached a sample output. The first numbers are Serial.print(sim.available()), then I try to print the data char from Response to the Serial.

    Do you have any suggestions?
    Thank you! These are great tutorials.

    • Hmmm it happens to me as well when I try different modules sometimes they didn’t work. So what I do is I simply change the delay time. Some gsm modules are slow so they respond slowly. In these cases you need to increase the delay. So my suggestion is to try 1500 n them 2000 value in delay.

      Thanks.

  19. Hi
    It is a very nice piece of cod and very useful.
    I think that can be used on my project but is come :
    SIM900.ino: In function ‘void RecSMS()’:
    SIM900.ino:93:19: error: ‘amp’ was not declared in this scope
    SIM900.ino:93:22: error: expected ‘)’ before ‘;’ token
    SIM900.ino:93:24: error: ‘amp’ was not declared in this scope
    SIM900.ino:93:45: error: expected ‘;’ before ‘)’ token…………..

    I understood that you have already corrected the cod and I will like to tested and see if can be integrated. So plaese if is not to much send the corrected code at mmedocean@gmai.com
    All the best and thanks in advance

  20. Hi,
    I have used the code as it. I just had change the position where we extract phone number. so for the first message it works fine and from the it displays
    Mobile Number is: +27630894756
    Message Text: http://Www.engineeringprojects.com

    and the second time
    Mobile Number is: +27630894756
    Message Text:
    ===
    [Code hidden]
    May you please help to find what i have missed.

  21. Big thanks for this post! It’ll help me a lot in my current project.
    Would be nice if it was possible to copy the source code 1 to 1.
    At the moment it has html tags in it like & and <…

    Cheers Paul

  22. #include
    #include

    static const int RXPin = 4, TXPin = 3;
    static const int GPSBaud = 9600;
    TinyGPSPlus gps;
    SoftwareSerial ss(RXPin, TXPin);

    void setup()
    {
    Serial.begin(9600);
    ss.begin(GPSBaud);
    }

    void loop()
    {
    // This sketch displays information every time a new sentence is correctly encoded.
    while (ss.available() > 0)
    if (gps.encode(ss.read()))
    displayInfo();

    if (millis() > 10000 && gps.charsProcessed() < 10)
    {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
    }
    }

    void displayInfo()
    {
    Serial.print(F("Location: "));
    if (gps.location.isValid())
    {
    Serial.print(gps.location.lat(),4);
    Serial.print(F(","));
    Serial.print(gps.location.lng(),4);
    }
    else
    {
    Serial.print(F("INVALID"));
    }

    Serial.println();
    }

    void Sendsms()
    {
    Serial.println("AT+CMGF=1\r\n");
    delay(5000);
    Serial.print("AT+CMGS=\"+923339383046");
    Serial.print("\"\r\n");
    delay(5000);
    Serial.print(F("Location: "));
    Serial.write(0x1A);
    while(3);

    }

    GPS Coordinates doesn't send through GSM module(Sim900a) why sir help me in this code. At sherhasan78@gmail.com

  23. hello sir,
    it would be great if you post the code for getting the message and sender number from received output i got what you explained in the points but i was not able to code it.so, please it would be helpful for my project if you post the code.
    regards
    sagar

  24. Hi Mr Syed Zain Nasir, powerful your explanation. I’m a young programmer. I start focus some my programming in AT command (GSM module, interface with computer…). I very interested on that particular part of the programming and wish to master it. Unfortunately I not get documentation on it. Please can you help me to provide some documention? Please me I used CCS compiler software to write programs. I start start learn ADUINO but I was in face in a particular problem. I remark that we most used xBoard(AVR dev Board) which is not available in how country. And also ARDUINO is just program ATMEGA microcontroller and not other types of microcontrollers such as 16fxx, 18fxxx…Thus, this discourage me to program with ARDUINO. Please sir I will very happy I you send me the documentation on AT command, serial communication RS232, GSM module.
    I see the example that your show. It is very powerfull… .
    Thank in advance…
    Cordially Arthur

  25. Sir i want to recieve a message, if the message is from the right number then i gsm module should reply “hellow” can you help me to sort my problem. gsm module is sim800l.

  26. Dear Syed Zain Nasir sir.. is it possible to move the robot in all 4 directions using GSM module and arduino uno?? plzz sir suggest me. thanks

  27. hey! can you please help me out. i need your code for my college project purpose. my project is based on iot and its topic is solid waste management. and as a college student i can’t afford to buy your code for $20. please can you provide me your code for free. if you want i can send you my project details. it will become very important for me… please!!!

  28. Can I ask help on my code sir?(Code which i formed from various codes on the forums about parsing sms, with the aid of your guide/steps sir)
    I am confused, as to where should I put my Clear function. It gives me nothing on my serial monitor everytime I’ll put the clear function in my sketch. But if clear function is not present, there is a result in the serial monitor, though the output prints the same on my after my 1st msg.

    Ouput is something like:
    AT+CMGF =1

    OK
    AT+CNMI = 1,2,0,0,0

    OK

    Success!
    Received from: +639********** // I just hid my number here for privacy
    Message Text : 12345678
    Received from: +639********** // the same output
    Message Text : 12345678 // I sent another message:87654321, yet the prev. one displayed. its Clearing problem..
    Success!
    Received from : +6392**********
    Message Text : 12345678

    ***
    Your help would be greatly appreciated. I just dont know how to clear it.
    I can be contacted at mi.lenmuelt@gmail.com.

  29. Hi, sir. Im sharif here. Im working with circuit simulation in Proteus software. How can we send commands to arduino in the circuit simulation,sir? i have attached the virtual terminal and it shows AT+CNMI=2,2,0,0,0
    AT+CMGF=1. Im doing project on load switching controlled by sending sms. That means whenever i send a command sms from any phone to the gsm module, it will send the message to the arduino and the output will be 16×2 lcd which indicating either the load is on or not and also to relays. I am using sim 900A in my project. TQ

  30. Sir i have done my project on smart surveillance system using motion sensor and gsm when pir sensor detects someone it text and if i give reply it does not call me otherwise it will call till now it works fine but i want add program that if i send D so it will deactivate means not to text and call and if i send A it will sense again and call and text me what changes can be made in my programming plz help my programming is as under
    #include
    SoftwareSerial SIM900(7, 8);
    char inchar; // Will hold the incoming character from the GSM shield
    int x,y,m,n;
    String textForSMS;

    int motion = 4;
    int infrared = 5;
    int fflag = 0; // feedback flag. for ackonowledgment message
    int mflag = 0; // message flag
    // for timing

    int interval= 60 ; // in secs
    // Tracks the time since last event fired
    unsigned long previousMillis=0;
    unsigned long int previoussecs = 0;
    unsigned long int currentsecs = 0;

    unsigned long currentMillis = 0;
    int relay = 13;

    void setup()
    {
    SIM900.begin(19200);
    Serial.begin(9600);

    // delay(20000); // give time to log on to network.
    Serial.println(” logging time completed!”);
    randomSeed(analogRead(0));

    pinMode(motion, INPUT);
    pinMode(infrared, INPUT);
    digitalWrite(infrared, HIGH);
    digitalWrite(motion, HIGH);
    pinMode(relay, OUTPUT);
    digitalWrite(relay, LOW);
    // gsm modem settings
    SIM900.print(“AT+CMGF=1\r”); // set SMS mode to text
    delay(1000);
    SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
    // blurt out contents of new SMS upon receipt to the GSM shield’s serial out
    delay(1000);
    SIM900.println(“AT+CMGD=1,4”); // delete all SMS
    delay(5000);
    Serial.println(“Ready…”);
    }

    void sendSMS(String message)
    {
    SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message
    delay(100);
    SIM900.println(“AT + CMGS = \”+923339322283\””); // recipient’s mobile number, in international format

    delay(100);
    SIM900.println(message); // message to send
    delay(100);
    SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
    delay(100);
    SIM900.println();
    delay(5000); // give module time to send SMS

    }
    // to call someone
    void callSomeone()
    {
    SIM900.println(“ATD + +923339322283;”); //
    delay(100);
    SIM900.println();
    delay(10000); // wait for 10 seconds…
    // SIM900.println(“ATH”); // hang up
    }

    void loop()
    {
    //while((SIM900.available() == 0)&& (digitalRead(motion) == LOW ) && (digitalRead(infrared)== HIGH ) ) ; // ORIGINAL

    while((SIM900.available() == 0)&& (digitalRead(motion) == HIGH) && (digitalRead(infrared)== HIGH ) )
    {
    if (fflag == 1 )
    {
    // Get snapshot of time
    currentMillis = millis();
    currentsecs = currentMillis / 1000;

    // How much time has passed, accounting for rollover with subtraction!
    if ((unsigned long)(currentsecs – previoussecs) >= interval) {

    Serial.println(“calling…”);

    callSomeone(); // call someone
    delay(1000);
    fflag = 0 ;
    digitalWrite(infrared, HIGH);
    previoussecs = currentsecs;
    } else
    Serial.println(currentsecs);

    }
    // Serial.println(currentsecs);
    delay(1000);
    }

    if((SIM900.available() >0) && (fflag == 1))
    {
    inchar=SIM900.read();
    Serial.println(inchar);
    delay(20);

    if (inchar == ‘V’)
    {
    fflag = 0;
    digitalWrite(relay, HIGH);
    Serial.println(“acknowledgment msg received”);
    delay(15000);
    digitalWrite(relay, LOW);
    }
    }

    // if(digitalRead(infrared) == LOW)
    if((digitalRead(infrared) == LOW)&& ( fflag == 0))
    {

    textForSMS = “\nIntruder detected on infrared sensor\n kindly send the acknowledgment message V”;
    sendSMS(textForSMS);
    Serial.println(textForSMS);
    Serial.println(“message sent.”);
    digitalWrite(infrared, HIGH); // new line
    fflag = 1;
    delay(10000);
    currentMillis = millis();
    currentsecs = currentMillis / 1000;
    previoussecs = currentsecs;

    }

    if((digitalRead(motion) == LOW)&& ( fflag == 0))
    {

    textForSMS = “\nIntruder detected on motion sensor\n kindly send the acknowledgment message V”;
    sendSMS(textForSMS);
    Serial.println(textForSMS);
    Serial.println(“message sent.”);
    digitalWrite(motion, HIGH); // new line
    fflag = 1;
    delay(10000);
    currentMillis = millis();
    currentsecs = currentMillis / 1000;
    previoussecs = currentsecs;

    }

    }

  31. Actually i need one help from u,While i missed-call to that particular GSM number then only i want to receive massage from GSM,Do u have any sollution for this problem then please help me….!

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment