GSM TUTORIAL

on Saturday, 14 December 2013

Hi guys , i'm back with the Gsm(SIM 300) tutorial. In this tutorial I will be explaining how to send and receive sms by interfacing gms module with microcontroller.
I have used PIC18f452 microcontroller and mikroC as a vehicle to explain these concepts but the concept will be the same for all compilers and microcontrollers.
Note, i'm just writing as easy as possible for you to understand better, so this tutorial is limited.
In this tutorial mainly i will deal with few AT commands for sending , receiving, extracting the actual message, deleting the message. To understand practically we will look at one of the projects of gsm in the next post. Project which we do is the "Controlling home appliances by simple SMS ".

Basic Understanding:
As we know GSM stands for Global System for Mobile communication. By using Gsm module we can handle all the basic operations of any mobile phone i.e making a call , receiving a call, sending sms , receiving sms and so on..

It supports AT commands to deal with all these operations. There are many AT commands which are supported by SIM 300 GSM module. SIM 300 is one of its type, which available easily in the market. SIM 900 is its advanced version. Most of the commands which supports in SIM 300 also support for SIM 900 but few of them varies. So to know all the AT commands which are supported by your device better refer its datasheet.This tutorial is based upon SIM 300 type. So let’s see one by one.

BASIC TEST:

Just to check whether our device working or not we send this AT command
AT()
If we get the response as below then it’s working all right
OK

ECHO:

>whenever we sends any character to the module it retransmits back, i.e if we connect gsm module to our computer or micro controller(or any other device) whenever we sends any data then it reflects back to computer or micro controller(or any other device).
If we dont want GSM module to retransmits back what we have sent , an AT command to do this.
ATE0 < enter>
If we want to enable the ECHO i.e we want gsm module to retransmit the data which we send then
ATE1< enter>
We should send the ascii value for ENTER i.e 0xd(in hex) , now to disable the ECHO "ATE0 0xd" and for enable "ATE1 0xd"
Note: While we are using computer, then we just press "Enter key"() for Enter, but while using microcontroller we send 0xd (i.e its ascii value).

TEXT MODE:

There are two modes to get the data when we read any message; they are in TEXT MODE and PSU MODE. In text mode data will be similar to that of our conventional readable type, but in PSU mode its in hex code (ex: 132543682A2D456..).

To set our module to TEXT MODE we use this command

AT+CMGF=<mode><enter or CR>
if mode =1 then TEXT mode
=0 then PSU mode
Enter or CR = 0xd
Example: To make the Text mode , AT=CMGF=1()

Passing Mobile Number To Send SMS:

while sending any message we send the mobile number to our gsm module. AT command to do so is
AT+CMGS="mobile number" ()
mobile number= number to which we want to send sms
semi colon         = 0x22 Ascii value
Enter ()             = 0xd

STEPS FOR SENDING SMS:

AT()
after some milli sec delay
ATE0()
after some milli sec delay
AT+CMGF=1()
after some milli sec delay
AT+CMGS="XXXXXXXX"()
after some milli sec delay
Enter message body which you want to send , press ctrl+z after complition. Ascii code for ctrl+z is 26(decimal)
Example: we want to send SMS to the number "1234567890" and message body to send is "how are you my friend".
AT()
after some milli sec delay
ATE0()
after some milli sec delay
AT+CMGF=1()
after some milli sec delay
AT+CMGS="1234567890"()
how are you my friend ctrl+z

Important Notes:
1.We need to note few important points here, in the above steps for sending sms, first three commands we use only for the first time while sending sms.
For example we want to send 10 messages then its not necessary to use first three commands(AT,ATE0,AT+CMGF) for all 10 messages, we only send them for the first message, from the 2nd message we only send from step 4(AT+CMGS="1234567890"() ).
2. When we send any command then gsm module will respond it back i.e if we send command 'AT' then response will be 'OK', above we neglected the response from the module that is the reason we use delay after every command.

RECEIVING SMS:


STEP1: When a text message (SMS) arrives on SIM300 GSM Module it sends a response as
 <CR><LF>+CMTI: <mem>,<n><CR><LF>
To confirm whether we received SMS or not we need to check +CMTI: continuously.
Here <n> is the memory slot at which SMS have been saved. So we need to save character which comes after comma (,)

STEP2:After we received the sms, we need to send this command at+cmgr=<n> in order to read the received message. Here <n> is the memory slot where our sms has been saved.


STEP3:We will get a response as soon as we send the command, so response will be a long string, its look like this
+CMGR: “STATUS”,”OA”,,”SCTS”<CR><LF>Message Body<CR><LF><CR><LF>OK<CR><LF>
We should check for +CMGR: and if it satisfies then we save Message Body in an array, which is after <LF> and before <CR> i.e after 0xa and before 0xd(ascii values of Lf and CR). 



Based on this tutorial we will look at a project "Controlling home appliances by simple SMS " in our next post.
AUTHOR: YOUSTRON SIC
 
  



10 comments:

M Azeem Ul Haq said...

Salam!

bro a bit confused about reading fresh SMS, or old msg
i can read only one sms by using AT+CMGR=1

if i use AT+CMGR=2 it gives error.
i ve many SMS in SIM card
can u elaborate a bit more like u did in sending SMS part with example?

YOUSTRON SIC said...
This comment has been removed by the author.
YOUSTRON SIC said...

AT+CMGR= msg slot number...
example if you want to read msg of slot 5, then at+cmgr=5
if you want to read msg of slot 8, then at+cmgr=8

Freeky Roslin said...

Nice information sharing .As you said GSM stands for Global System for Mobile Communication and is an open, digital cellular technology used for transmitting mobile voice and data services. The GSM standard is the most widely accepted standard and is implemented globally.The GSM provides basic to advanced voice and data services including Roaming service.GSM is SIM specific, User has option to select handset of his choice ,sometime it will locked with a particular network contract for a particular periods, but we can remove it by getting the unlocking service from an provider like ClassicUnlocking.com

Fahad Wasti said...

Hi I am observing every step of my working code. When I started to check +CMTI.
It confirms '+'
then 'C'
But it stops after 'C' and did not proceed further. Pleae Help

YOUSTRON SIC said...

You can be in touch with me on fb
Www.facebook.com/youstron.sic

BILAL MALIK said...

gsm modules are very popular in engineering students. you have presented a very good article on gsm and AT commands. Do you have gsm based projects?

malik kamran said...

i intend to make degree project on this .i want to open door from any where through finger print using gsm module ,can you help little bit ?

Aoudumbar Pawar said...

its very helpful information for beginners......thanks a lot.....

Ajay Dhamde said...

how to collect read sms with pic 16f877a,I hd tried but it doesn't catch a sms data.please help me

Post a Comment