Click here to Skip to main content
15,888,527 members
Articles / Programming Languages / Visual Basic

vb.net AT commands to send SMS

Rate me:
Please Sign up or sign in to vote.
4.81/5 (24 votes)
25 Mar 2009CPOL1 min read 434.8K   30.5K   62   118
this article allows you to send SMS to any mobile using GSM modem or your mobile connected via USB able to Computer

Introduction

This code provided allows to send SMS from the PC to any mobile with the help of GSM modem or any GSM compatible mobile.

Background

Basically I am making use of AT commands , which are AtTention Commands which are used for  communication between the computer and the modem.

Microsoft windows provides witha software called Hyperterminal which is available through thispath.

Start-> Programs-> Accessories->communications->hypertreminal

AT commands can be typed here. Hypertreminal communicates directly with the modem /mobile connected and instructs the modem. It also gives responses back as OK or error etc. But if we have a application where we need to send SMS after a specific set of actions, then hypertreminal is not useful, since it requiers manual typing. You need to select the COm port on which modem/mobile is connected.(port can be serial port for modem or USB port for mobile).

The code given does this.If any doubs are there you can contact me on the forum below

Using the Code

First, connect modem or mobile. Go to device manager and under Ports options check for which COM (e.g. COM3 , COM4 etc)port your modem/mobile has been connected to.

VB
//
// if COM3 is shown in device manager then put COM4 in foll statement
//
    Dim SMSEngine As New SMSCOMMS("COM4")

'the port needs to be initialised

SMSPort = New SerialPort
        With SMSPort
            .PortName = COMMPORT
            .BaudRate = 19200
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
            .Handshake = Handshake.RequestToSend
            .DtrEnable = True
            .RtsEnable = True
            .NewLine = vbCrLf
        End With 


        'this is  the set of AT commands to be written on serial port

            SMSPort.WriteLine("AT")
            'set command message format to text mode(1)
            SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 
            'set service center address (which varies for service providers (idea, airtel))
            SMSPort.WriteLine("AT+CSCA=""+919822078000""" & vbCrLf)             
            ' enter the mobile number whom you want to send the SMS
            SMSPort.WriteLine("AT+CMGS=  + TextBox1.text + " & vbCrLf) 
            _ContSMS = False
            SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending

    Dim i As Integer
    Private Sub Button1_Click(ByVal sender As System.Object,
       ByVal e As System.EventArgs) Handles Button1.Click

        SMSEngine.Open() 'open the port
        SMSEngine.SendSMS() 'send the SMS

    End Sub

class SMSCOMMS is defined in the code. I have tried this code with only nokia mobiles like nokia 5310, nokia 3500 etc. ALso i have tried sending sms from airtel provider to idea also. It works fine. Download the code. Its simple n explained with comments. 

Points of Interest

Programming in mobile communication, serial port interfacing, TAPI programming in.net

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior)
India India
hello . I am studying BE in information technology in GOA.
My interests lie in programming in mobile communication in vb.net etc.

Comments and Discussions

 
GeneralSMS Via GSM Mobile Pin
balap719-May-10 0:47
balap719-May-10 0:47 
Questionneed help with this code Pin
red_face_boy1-Mar-10 12:25
red_face_boy1-Mar-10 12:25 
AnswerRe: need help with this code Pin
h0pefree24-Apr-10 8:18
h0pefree24-Apr-10 8:18 
GeneralProblem sending the sms [modified] Pin
btushar200029-Jan-10 2:49
btushar200029-Jan-10 2:49 
Generalusb modem Pin
rgupta12207-Jan-10 22:35
rgupta12207-Jan-10 22:35 
GeneralNot responding Pin
Krishna Kapadia26-Dec-09 6:11
Krishna Kapadia26-Dec-09 6:11 
GeneralRe: Not responding Pin
namrata khandeparkar28-Dec-09 0:54
namrata khandeparkar28-Dec-09 0:54 
GeneralRe: Not responding Pin
Krishna Kapadia30-Dec-09 6:21
Krishna Kapadia30-Dec-09 6:21 
Hiiiii

Thank you very much for your reply...

I have checked the list of connected modems in Control Panel->Phone And Modem Options
and have entered correct COM port. I have also installed Sony Ericcson's PC Suite. My phone is in phone mode by default.

But my problem is still same because SMS is not received on receiver's mobile.

All commands are successfully executing. But no output is coming.

I have checked Microsoft SMS sender application through which I can do same that your application do. It works for my mobile.
I have checked Logix Mobile Component Library(which is built using .Net Technology). They are providing a dll to send SMS. And they also provide demo application which is also working for my mobile smoothly.

And I'm 100% sure that Above all are doing these by AT commands but don't know what I'm missing.

I have used your code without any modification except Service provider no, Receipient's no and message.

If possible please reply me on my yahoo ID(mentioned below) offline because the email ID that I have used on this site is for rough internet use and I never check its mail.

This is my Yahoo ID : krish_kapadia9676

Thank you very very much for your support.
GeneralRe: Not responding Pin
namrata khandeparkar30-Dec-09 20:16
namrata khandeparkar30-Dec-09 20:16 
GeneralRe: Not responding Pin
sinafe29-Jun-10 19:28
sinafe29-Jun-10 19:28 
Questionwhere u define and call the SMS PORT CLASS Pin
Ahsin sdaqat8-Dec-09 3:39
Ahsin sdaqat8-Dec-09 3:39 
GeneralNeed help Pin
VyankateshRahul27-Nov-09 21:02
VyankateshRahul27-Nov-09 21:02 
GeneralRe: Need help Pin
namrata khandeparkar30-Dec-09 20:24
namrata khandeparkar30-Dec-09 20:24 
GeneralGreat Stuff! Pin
Tomcause24-Nov-09 23:36
Tomcause24-Nov-09 23:36 
GeneralSend Msg Box Displayed But destination number didnt receive msg Pin
cpandiya30-Sep-09 20:19
cpandiya30-Sep-09 20:19 
GeneralRe: Send Msg Box Displayed But destination number didnt receive msg Pin
dileep_sahrdaya23-Mar-10 7:28
dileep_sahrdaya23-Mar-10 7:28 
GeneralRe: Send Msg Box Displayed But destination number didnt receive msg Pin
namrata khandeparkar23-Mar-10 22:40
namrata khandeparkar23-Mar-10 22:40 
GeneralThe port 'COM2' does not exist Pin
cpandiya30-Sep-09 0:11
cpandiya30-Sep-09 0:11 
GeneralRe: The port 'COM2' does not exist Pin
namrata khandeparkar30-Sep-09 17:56
namrata khandeparkar30-Sep-09 17:56 
GeneralMsg Box Displayed as send but cant receive msg on the destination no... Pin
cpandiya30-Sep-09 19:12
cpandiya30-Sep-09 19:12 
Generalits not working on E71 Pin
kuniyo24-Jul-09 4:10
kuniyo24-Jul-09 4:10 
GeneralRe: its not working on E71 Pin
namrata khandeparkar30-Sep-09 17:58
namrata khandeparkar30-Sep-09 17:58 
GeneralRe: its not working on E71 Pin
namrata khandeparkar30-Sep-09 17:59
namrata khandeparkar30-Sep-09 17:59 
GeneralUsing my mobile as GSM modem!! Pin
s42624-Jun-09 9:37
s42624-Jun-09 9:37 
GeneralMsg box indicates msg sent but the recipient never receive the sms Pin
van_walkman3-Jun-09 23:51
van_walkman3-Jun-09 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.