Tutorial :: Using AT commands to Send and Receive SMS

Posted: June 16, 2009 in Uncategorized

Tutorial :: Using AT commands to Send and Receive SMS
This AT command tutorial is written to support our Teltonika T-ModemUSB, a USB2.0 GSM modem based on the Nokia 12i GSM module – fast EDGE technology is supported. Some of the most popular applications are SMS based telemetry, security and news broadcasting.

Steps using AT commands to send and receive SMS using a GSM modem from a computer

1. Setting up GSM modem
2. Using the HyperTerminal
3. Initial setup AT commands
4. Sending SMS using using AT commands
5. Receiving SMS using using AT commands
6. Using a computer program to send and receive SMS

After succesfully sending and receiving SMS using AT commands via the HyperTerminal, developers can ‘port’ the ASCII instructions over to their programming environment, eg. Visual Basic, C/C++ or Java and also programmically parse ASCII messages from modem.

1. Setting up your GSM modem

Most GSM modems comes with a simple manual and necessary drivers. To setup your T-ModemUSB, download the USB GSM Modem Quick Start ( Windows ) guide (460kB PDF). You would be able to send SMS from the Windows application and also setup GPRS connectivity. The GSM modem will map itself as a COM serial port on your computer.

T-ModemUSB Windows Control Tool and SMS sending application
Windows based control panel to setup GSM modem, GPRS and send SMS

2. Using the HyperTerminal

Hint :: By developing your AT commands using HyperTerminal, it will be easier for you to develop your actual program codes in VB, C, Java or other platforms.

Go to START\Programs\Accessories\Communications\HyperTerminal (Win 2000) to create a new connection, eg. “My USB GSM Modem”. Suggested settings ::

– COM Port :: As indicated in the T-Modem Control Tool
– Bits per second :: 230400 ( or slower )
– Data Bits : 8
– Parity : None
– Stop Bits : 1
– Flow Control : Hardware

You are now ready to start working with AT commands. Type in “AT” and you should get a “OK”, else you have not setup your HyperTerminal correctly. Check your port settings and also make sure your GSM modem is properly connected and the drivers installed.

3. Initial setup AT commands

We are ready now to start working with AT commands to setup and check the status of the GSM modem.

AT Returns a “OK” to confirm that modem is working
AT+CPIN=”xxxx” To enter the PIN for your SIM ( if enabled )
AT+CREG? A “0,1” reply confirms your modem is connected to GSM network
AT+CSQ Indicates the signal strength, 31.99 is maximum.

4. Sending SMS using AT commands

We suggest try sending a few SMS using the Control Tool above to make sure your GSM modem can send SMS before proceeding. Let’s look at the AT commands involved ..

AT+CMGF=1 To format SMS as a TEXT message
AT+CSCA=”+xxxxx” Set your SMS center’s number. Check with your provider.

To send a SMS, the AT command to use is AT+CMGS ..

AT+CMGS=”+yyyyy” <Enter>
> Your SMS text message here <Ctrl-Z>

The “+yyyyy” is your receipent’s mobile number. Next, we will look at receiving SMS via AT commands.

5. Receiving SMS using AT commands

The GSM modem can be configured to response in different ways when it receives a SMS.

a) Immediate – when a SMS is received, the SMS’s details are immediately sent to the host computer (DTE) via the +CMT command

AT+CMGF=1 To format SMS as a TEXT message
AT+CNMI=1,2,0,0,0 Set how the modem will response when a SMS is received

When a new SMS is received by the GSM modem, the DTE will receive the following ..

+CMT :  “+61xxxxxxxx” , , “04/08/30,23:20:00+40”
This the text SMS message sent to the modem

Your computer (DTE) will have to continuously monitor the COM serial port, read and parse the message.

b) Notification – when a SMS is recieved, the host computer ( DTE ) will be notified of the new message. The computer will then have to read the message from the indicated memory location and clear the memory location.

AT+CMGF=1 To format SMS as a TEXT message
AT+CNMI=1,1,0,0,0 Set how the modem will response when a SMS is received

When a new SMS is received by the GSM modem, the DTE will receive the following ..

+CMTI: “SM”,3 Notification sent to the computer. Location 3 in SIM memory
AT+CMGR=3 <Enter> AT command to send read the received SMS from modem

The modem will then send to the computer details of the received SMS from the specified memory location ( eg. 3 ) ..

+CMGR: “REC READ”,”+61xxxxxx”,,”04/08/28,22:26:29+40″
This is the new SMS received by the GSM modem

After reading and parsing the new SMS message, the computer (DTE) should send a AT command to clear the memory location in the GSM modem ..

AT+CMGD=3 <Enter>   To clear the SMS receive memory location in the GSM modem

If the computer tries to read a empty/cleared memory location, a +CMS ERROR : 321 will be sent to the computer.

6. Using a computer program to send and receive SMS

Once we are able to work the modem using AT commands, we can use high-level programming ( eg. VB, C, Java ) to send the AT ASCII commands to and read messages from the COM serial port that the GSM modem is attached to.

Developer Tip : To speed up development of your solution, download trial versions of SerialTools for C# and VB.NET or SerialTools ActiveX for Windows – with sample serial port ( modem ) reading and writing samples.

  1. majeeth says:

    hello sir! i’m trying to do project based on gsm module which is going to recieve sms from user and reply for his request….GSM modem only receiving the data but not the destination number….without the number i couldn’t send the sms for him…please help me how to receive the number of the mobile user using GSM modem……

  2. dbametrix says:


    Excellent sharing. Thanks for same.


  3. rafay says:

    sir i have made my programing in vb to send sms ,only outgoing,and i want to fix a number b y which only that person will be able to send sms,it is all for security and authentication.can u provide me some info that how to do it

  4. Romil says:

    do can i use this for the C# appliacation ??
    SO i can bind the AT commands with the c# code??
    I want to to make an pc suite so for that i need to connect phone with the pc so for that i will use AT commands but do i can bind the at commands with the c#

  5. arunkrishnab says:

    I cant get my message on system. it seems to be in some codes. why like this

  6. Deepsan says:

    Hello sir,
    Sir i want to make a listener for receiving sms, means when any sms received it should automatically show indication like new message received, i m working with c# how can i get the required output.

  7. Deepsan says:

    Thanks , i have studied your given commands and i found the solution..

  8. bryan says:

    any other way to store sms to database?

  9. PS Randhawa says:

    Thanks sir, for sharing very usefull information

  10. djamel says:

    hello i hope to find how to send an sms from gsm modem using a Dos batch file containing the recipient numbers (multibroadcast) thanks for ur help

  11. kosovy says:

    please help AT+CMGL=”ALL” Does not work with nokia x3-02 need the different code

  12. veeramani says:

    this is very helpful for my project. thank a lot sir.

  13. lima says:

    thank u for sharing (y)

  14. John says:

    Thank you for sharing. everything works fine. only issue is that when i receive long sms (170 character or up) it’s just showing number like this 3549648054684068468405

  15. Asitha says:

    Sir, I want to separate receive sms data from following AT command:

    mySerial.println(“AT+CNMI=2,2,0,0,0”); // AT Command to recieve a live SMS

    Please help me..

  16. Jethro says:

    Thank you! Very informative sir.

  17. Prashant says:

    Hello sir,

    My GSM module can’t rececived msg so can you give me command for receiving msg. I was try the CNMI command but it still not working so help me.

    Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s