Send sms using gsm module and pic microcontroller




Send sms using gsm module and pic microcontroller : this article explains how to send sms using gsm module and pic microcontroller. what is AT commands and their use to send and receive sms. I have already posted a article on gsm module interfacing with pic microcontroller. I suggest you to go through that article before proceeding in this article.so that you may get an idea about gsm module SIM900D, its features and interfacing circuitry. There are many gsm based project which you like to make using this module.




AT commands are used to initialize whatever you want gsm module to do for you. SIMCOM a company of sim tech have a AT command complete document for SIM900. You can easily download it from google. For each SIM900D feature there are separate AT command available. User can easily use these commands to configure whatever functionality they want to use from gsm module available features. In this article I will discuss only AT commands use to send sms. But you will get an idea how to use rest of AT commands for using other features of gsm module. AT commands you need to know for sending sms through gsm module SIM900D and how to use while writing code:

For example we want to send SMS “Welcome to microcontrollerslab.com”.




  1. AT+CMGF

There are two modes to send sms in gsm 1) in text mode  2) PDU in binary format but it is easier to send sms using text mode. To set gsm to text mode :

AT+CMGF = 1;

 2. AT+CMCS

This command is used to selest character mode and set gsm character mode to

AT+CMCS = “GSM”

 3. AT+CMGS

This command is used to select number of message recipient and message you wan to send to recipient.To select number and message follow the following procedure :

AT+CMGS = “+090078601”

when you send this command to modem, modem will respond you with greater than mark “>”. After that sign write your message you want to send to recipient and terminate your message with control+z in character form.I will show you in code how to write control+z in character form.

Above commands are necessary command to send sms through gsm module SIM900D. Below is a list of optional AT commands use to send sms :

  • AT + CSCA  is used to set message center number of sim which you are inserted in gsm module sim jacket
  • AT + CSMP  is used to set parameters of text mode.

To know more about AT commands for SMS and their details, go through data sheet of AT commands by SIMCOM.

Circuit diagram

In gsm module interfacing with pic microcontroller article I have discussed RXD and TXD pins of gsm module and pic microcontroller should be connected with each other in reverse manner.Because transmitted data of pic microcontroller receive to gsm module and similary tranmissted data from gsm TXD go to RXD receive pin of pic microcontroller. This is a wired communication to send data from one device to another. There are many methods of wired communication but pic and gsm interfaced through 2 wire serial communication.Serial communication mean to send data bit by bit.There is one important to consider while using serial communication that is baud rate. Baud rate is the number of bits transfer per second from one device to another. You should check baud rate compatibility between two devices.Usually SIM900D gsm module support 9600 baud rate with UART type serial commnunication. UART mean universal Asynchronous receiver and transmitter. Pic microcontroller have built int hardware to implement UART serial communication process between pic microcontroller and gsm module. SIM900D gsm module also support UART serial communication. Circui diagram is shown below.

gsm module interfacing with pic microcontrolle
gsm module interfacing with pic microcontrolle

Because there is no gsm simulation model available in Proteus to simulate it. But  you can check your virtual hyper terminal available in Proteus to check either microcontroller is transmitting data or not.

Video lecture to send sms using gsm module

CODE

Code is written is Mikro C.

char AT[]="AT";   // To initialize mode
 char noecho[]="ATE0";   // To stop echo
 char mode_text[]="AT+CMGF=1";   // to set text mode
 char char_mode[]="AT+CSCS=\"GSM\"";   // to set character mode
 char param[]="AT+CSMP=17,167,0,0";   // set the parameter of character
 char mobile_no[]="AT+CMGS=\"+92090078601\"";   //use to set receinpent number and mesg
 char terminator=0x1A;     // chartacter form of control + z terminator character
 char mesg[]="welcome to microcontrollerslab.com";   // mesg we want to send
 void send_to_modem(char *s)   //function to write anything serially
 {
 while(*s)
 UART1_WRITE(*s++);
 UART1_WRITE(0X0D);
 }
 void send_to_modem1(char *s)
 {
 while(*s)
 UART1_WRITE(*s++);
 }
 void send_sms()
 {

send_to_modem1(mesg);
 delay_ms(100);
 uart1_write(terminator);
 delay_ms(1000);
 }
 void main()
 {

UART1_INIT(9600);
 send_to_modem(AT);
 delay_ms(2000);
 send_to_modem(noecho);
 delay_ms(2000);
 send_to_modem(mode_text);
 delay_ms(2000);
 send_to_modem(mobile_no);
 delay_ms(2000);
 send_sms();
 }

Above code will send message only once. Because I haven’t use while loop to perform sending action again and again.Diagram below shows  virtual terminal receiving data from microcontroller. As I have already mentioned , you can use it for checking.But it will work when you interface gsm with your personal computer.

sending sms using gsm and pic microcontroller
sending sms using gsm and pic microcontroller

This article explained you how to AT command in coding and sending sms using gsm and pic microcontroller. Its all about this article.For more article on gsm visit gsm category. You are welcome to comment on in this post , if you have any query. Check Gsm based projects list for more information. Enjoy playing with GSM 🙂



36 thoughts on “Send sms using gsm module and pic microcontroller”

  1. I AM USIBG AURDINO TO SEND SMS THROUGH GSM MODULE BIT I HAVE LITTLE KNOWLEDGE ABOUT PROGRAMMING. SO PLZ HELP ME BY CODE AND FULL SUGESSION HOW CAN i send sms through gsm module to my desired valid mobile no.

    • same things was happened to me,
      try to use same clock size in codes and microcontroller (I was used 16MHz both in code building and in PIC16F877a ) and finally they displayed.

  2. Sir i need to make project on wireless notice using gsm using pic microcontroller… Sir will you put some light like what all components will i need to sumulate using proteus and some imp tips on it

  3. hey bilal….. i have problem in my c-code for sending sms using gsm 900… i have received only call not sms please help me for that i have used pic16f887 for my project…
    thanks

  4. I tried sending sms from my M590E GSM module and am getting nothing at the moment. The modem is interfacing with AT89S52 microController. please help me with a code to debug the program.

  5. You have a diode in the RX of PIC and TX of your gsm module, so dont you think it should be facing the otherway as this will block any thing coming from gsm

  6. Hi I’m trying to modify this code for use in MPLAB X – XC8. I keep getting an error message that says that the functions are being used in the incorrect format. Please tell me what changes I can make to use this code in XC8
    Thanks

  7. Sir, I need a circuit diagram and details for an Automatic booking of lpg gas (SMS) when cylinder volume gets low.Please help me Sir! Thanks in advance.

  8. thank you sir for your motivation but i need protuos soft ware please send me the code of your vidio and if you can the program of gsm based monitoring of generators fuel and batteries level in base station sites ,to my email address

    • you need to add a flag when you want to send a message. For example you can add a time after which you want to send sms

      • Please how do I add the time. Bellow is the code I wrote, I have also tried the one you posted but am still getting the same problem.

        void main(){
        UART1_init(9600); //Initiate baud rate to 9600
        Delay_ms(2000);
        UART1_Write_Text(“AT”);
        Delay_ms(2000);
        UART1_Write(0x0D) ; // mean (Enter)

        Delay_ms(2000);
        UART1_Write_Text(“ATE0”); // Please give your no where have to send sms
        Delay_ms(2000);
        UART1_Write(0x0D) ; // mean (Enter)

        Delay_ms(2000);
        UART1_Write_Text(“AT+CMGF=1”); // Please give your no where have to send sms
        Delay_ms(2000);
        UART1_Write(0x0D) ; // mean (Enter)

        Delay_ms(2000); // Wait a bit after the AT+CMGF=1 command
        UART1_Write_Text(“AT+CMGS=\”+2347032199427\””); //’AT+CMGS=
        Delay_ms(2000);
        UART1_Write(0x0D) ; // mean (Enter)

        Delay_ms(2000);
        UART1_Write_Text(“testing GSM module”); // State test value
        Delay_ms(1000);
        UART1_Write(0x1A); // Ctrl+Z
        Delay_ms(2000);
        }

  9. is it possible to change the code and use sim800L instead? my guess was just to change in the code just the name because they work almost the same, but i don’t really know if it is just that. thank you

Leave a Comment