Receive sms gsm module using pic microcontroller, In this article you will learn how to receive sms using gsm and pic microcontroller. I have already posted many articles on gsm and gsm module interfacing with pic microcontoller. Many users have asked me to post article on how to receive sms using gsm with pic microcontroller. First of all to use gsm module like SIM900A, SIM900B or many other versions available in market, you first should know how to use AT commands to get response from GSM module. Because the only way to interact with this module is through AT commands. Microcontroller sends specific AT commands to microcontroller and GSM module responds accordingly.
AT commands receive sms using gsm module
For example to send sms using GSM module and pic microcontroller, user have to use specific commands and similarly we can make call and answer phone call using this modem. So lets start with AT commands which are used to receive sms and how to read this sms and send date to UART of pic microcontroller. Because all these modules works on UART serial communication protocol. Following commands are used to receive sms and initialize modem that whenever it receive sms ,send this to UART pin of module. So that microcontroller can read it.
- AT :It will check the gsm module either it will connected with microcontroller or not and responds with ‘OK’ if it is connected.
- AT+CMGF=1 : this command sets the gsm module to text mode. Because we want to receive data in text format so that we can handle it easily while extracting sms from string which gsm will send to microcontroller. I will explain it in more detail in later part of this article.
- AT+CNMI=1,2,0,0,0 : This command force the gsm module to send receive sms gsm module to UART pins of microcontroller whenever sms is received. So that microcontroller can read it serially.
So these are the only three commands which will be used to to receive sms and send this sms to microcontroller.
Circuit diagram to receive sms using pic microcontroller
So now lets move to circuit diagram. Circuit diagram to receive sms is shown below. Circuit diagram remains same in all cases either you are sending or receiving sms.
So this is self explanatory circuit diagram. you just have to connect rx pin of gsm module with tx pin of microcontroller and tx pin of gsm with rx pin of microcontroller which is obvious that receiver of on is transmitter of other and vice versa. But make sure to connect power supply with gsm module which can supply peak current of 2A because while sending and receiving sms, it will take current in th order of two ampere.
I have used pic18f452 microcontroller while making this tutorial, but you can use any microcontroller you want and it depends on your application and selection of microcontroller depends on your microcontroller based project. you know what we can connect gsm module to com pin in proteus so its mean we can test our code by connect gsm module with computer or laptop and use this send data to proteus. So we can test our code without making actual hardware. But I recommend you test it on hardware.
Receive sms on computer or laptop
So first of all lets check, how our message string will look like when microcontroller receive it. For this purpose, we have to connect gsm module with computer or laptop. I have connected using usb to TTL converter as shown in figure below:
I have sent the sms from mobile number to sim in gsm module. I am using serial terminal proteus to receive sms as shown in figure below:
As you can see from above diagram that string receiving from gsm consists of +CMT at the start of string and it also includes sender mobile number, date and message at the end which is “microcontrollerslab.com” in this case. So string we have to extract sms string from this string to use it for useful purpose. For example you want to use it to control home devices by sending specific string to gsm. So you need to extract real message from string. Follow following step to extract message from this string:
- Send AT commands to from microcontroller to GSM as mentioned above to check it and initialize to send receive message to UART when it receive sms from any number.
- After that initialize UART module of pic microcontroller and start receiving string from gsm and store it in a string.
- After that you have to use string parsing to get only sms string form whole string received from gsm module.
How to receive sms using gsm and pic microcontroller
As mentioned above, you have to use UART module to receive sms available on UART pins of gsm modem. you should use it UART as interrupt so that whenever data available on tx and rx pin, microcontroller stop normal execution and goes to interrupt service routine to receive sms string. Check the video results shown below: I have connected gsm module to proteus and receiving sms.
Video lecture on how to receive sm using gsm
Click here to purchase code[/button-brown]
So this is all about how to receive sms to computer from SIM900A and how to receive this sms to microcontroller and how to extract real sms from gsm string. I will post a video in it also showing complete results. Code for this project is not free of cost. So please do not ask for free code. if you are interested to purchase code contact me. thanks