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.

What are AT command?

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 🙂

14 Comments

  1. Jake pamplona October 9, 2014
  2. Indugu Rushiraj May 27, 2015
    • BILAL Malik May 28, 2015
  3. KHATRI July 4, 2015
  4. ghulam qadir July 10, 2015
  5. Hassan July 12, 2015
  6. ayat August 26, 2015
  7. sintayehu alemu February 3, 2016
  8. Saideeo April 18, 2016
  9. sabrina May 6, 2016
  10. Jim June 14, 2016
  11. Cezar July 5, 2016
  12. Anil kumar December 19, 2016

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 706 other subscribers