Tuesday, December 11, 2012

Sending SMS using Huawei 3G modem | MATLAB code (Working and Tested)

This is the method for sending SMS to any Mobile phone or a GSM Modem using MATLAB.
Here I'm using a Huawei  E156G 3G modem/dongle to send the SMS. Don't worry first study the method and then You can try with your model. Most probably this will work with any Huawei 3G modem. lets start the coding..

 First of all you have to get a brief idea about the command. AT Commands (Attention Commands) are used by a mobile application to control a wireless modem. The AT command set consists of a series of short text strings which combine together to produce complete commands for operations such as dialing, hanging up, and changing the parameters of the connection. The command set for GSM modems is specified in 3GPP specifications, TS 27.007 and TS 27.005 (for SMS-related commands). The standardized commands include some commands that are optional. Therefore, most wireless modem makers support most, but not all standardized commands. In addition, most modem makers include additional vendor-specific AT commands.

If I says in simple tums, AT commands are predefined  short  text strings for operating a 3G modem(in our case)

we can send those AT commands as string to 3G modem/dongle to do our task, that mean Sending SMS.

you can use any programming language to do that, Its simple..! but remember this is a MATLAB tutorial, so lets start the work with MATLAB. For better understanding I'll explain with screenshots and photos.

This is the working and tested MATLAB code for sending SMS with a Huawei E156G 3G modem.

%%%%%%%%%%%%%%%%Matlab code for sending SMS%%%%%%%%%%%%
%%%%%% %%%%%%%%Author :  http://simpletechtrick.blogspot.com// %%%%%%%%%%
%%%%%%%%%%%%%%Tested Model Huawei E156G%%%%%%%%%%%%%%
clc;
clear all;
global BytesAvail;
global A;
global B;
tx ='ATI';
tx1=char(13);
tx2=char(26);
tx3='AT+CMGS="+12345678901"';  % You have to replace this with the Receiver's Phone number
tx4= ' This is a test msg ';     %This is the msg body
tx5='AT+CMGF=1';

s = serial('COM4'); % You have to replace this with your 3G modem's COMport number
                             
s.baudrate=9600;
fopen(s);
s.Terminator = 'CR';

fprintf(s,'%s', tx);
fprintf(s,'%s', tx1);

BytesAvail=s.BytesAvailable;
    if(BytesAvail > 0), A=fread(s,BytesAvail,'char'); end
A;
sprintf('%c', A)

%%%%%%%%%%%%%%%Send SMS%%%%%%%%%%%%
fprintf(s,'%s', tx5);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx3);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx4);
fprintf(s,'%s', tx2);
BytesAvail=s.BytesAvailable;
    if(BytesAvail > 0), B=fread(s,BytesAvail,'char'); end
B;

fclose(s)
%%%%%%%%%%%%%%%%%%%%End%%%%%%%%%%%


Note :  You have to close Mobile Partner Software completely to work this code. (For more information see the video tutorial below)



This is the MATLAB Output.


If you have any questions, just comment below, I'll answer as soon as possible.. Have a nice day... :-)

6 comments:

  1. i want to see the video tutorialso that i can see little mare detailed,can i plz

    ReplyDelete
  2. Would it work with VODAFONE VODEM STICK K3772 or similar? Hope to view your video soon.

    ReplyDelete
  3. while using above published code i get this error..


    Error using serial/fprintf (line 144)
    Unexpected Error: An error occurred during writing.

    Error in SMS (line 22)
    fprintf(s,'%s', tx);


    please help me to solve this issue...

    ReplyDelete
    Replies
    1. i am also getting the same error..have you resolved the problem?? #ARUNBALAN NV

      Delete
    2. I'am also getting the same error. Can anybody send me the correct code plz???????????

      Delete
  4. Can you plz.. send me the matlab code to send sms using dlink modem or airtel modem

    ReplyDelete