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”.
- 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.

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.

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 🙂
sir ;;;; do you know about a pic to wifi module to pc to vb interfacing?
Sir, Which appplication you have used to write and compile the code.
I have used Mikro c pro for pic by mikroE
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.
i tried it on proteus but not getting the text on virtual terminal
what can i do for this
help plz
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.
Sir,can u teach me how to coding pic16f877a for gsm to control the circuit..such as to turn off or turn on the led
sir i have need of matlab or proteous model of this project”
automatic load sharing of transformer by pic microcontroler”
can you send me it at [email protected]
hi i want contact with if you can my Email [email protected]
contact me at [email protected]
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
hello! thank you for eplication (Y) I wonder if this program is for pic18f4550 ??
Hey! What would I have to change for this code to work on a 16f887?
Can I use a PIC18F45K22 microcontroler?
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
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.
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
don’t we need to declare the uart1_init () and uart1_write() functions?
Hi I am unable to get the ok messages in second virtual terminal what is the problem
Please, what’s COMPIN configuration?
compin configuration is same as what he did configuration video.
this is very important to me..
thanks..
very nice
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
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.
I think, D4 should be placed in otherway. Clarify please
Sir it work for pic18f4520 pic microcintroller
sir, it can work for gsm sim 800L?
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
The code is sending message repeatedly with A6 GSM module. How can I modify the code for calling thanks
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);
}
please help me with a code to debug the program.
Use the one above with pic16f877a
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
yes it can be used
Hello please I observed something, I used the code and I observed that the system send more than one message continuously. Please how can I prompt the code to send only one message and after sending it should not resend it again.
Tried this code in MikroC but it doesn’t work, it shows errors.
I have not found even a single code on internet that can be converted to hex and can be run from PIC16F877A.