sms based device control...need all tne details

Status
Not open for further replies.
AT+CMGS="9xxxxxxxxxxx" //
check for '>' character
Message
cntrl Z


here i'm sending these commands as a string.
How shud i send the number..in double inverted comma "9xxxxxxxxx"

send_string("AT+CMGS="9xxxxxxxxx"");
enter();

You can double quotes as \" or equivalent hex(0x22):
For example:
Code:
send_string("AT+CMGS=\"9xxxxxxxxx\"");
OR
send_string("AT+CMGS=");
send_char(0x22);
send_string("9xxxxxxxxx");
send_char(0x22);
<Enter>
wait for >
message
<ctrl><Z>

and how to send a message to multiple numbers ??

You can send to multiple recipient but you have to wait to receive "OK" from every message you sent.

- - - Updated - - -

can we use AT+CMGW command to store the message at particular memory location and later sending it to multiple numbers ??

You can do. see the datasheet for AT+CMGW.
 

@speedEC--- thankuuuuu
that is very useful :smile:

@speedEC. @aameer
I checked the AT+CMGW command.
By using that and AT+CMSS command i can send the same message to multiple recipients.
but i hv one doubt by sending sms using CMSS command it will store the sent message copy in the memory. Then after some msgs memory will be full. It will be difficult to delete message copy as we hv to search everytime the memory location for sent message copy and delete them. SO what shud i do ??
https://www.developershome.com/sms/sendSmsByAtCommands.asp

One more doubt- I want to read the message and do the require operation as soon as new message comes. As i read by using AT+CNMI command we can do it. I'm not understanding the exact working of this commmand.
It sends +CMTI: index no whnevr new sms comes. AM i going correctly ?
How to detect that automatically or is there any other way like serial interrupt( whenevr +cmti comes it shud go to particular ISR) ?
I am not gud at interrupts as i have not done it till now. WOuld u guys please help me ?
 


You can use single AT+CMGDA="DEL SENT" wherever you need to delete all the copy of sent messages. Also, you have to delete unnecessary/anonymous SMS from your inbox. So, you have to use AT+CMGD=<message number> command to delete incoming SMS(you can obtain the SMS Message Number from +CMTI: SM, <message number> string).

...It sends +CMTI: index no whnevr new sms comes. AM i going correctly ?...

Correct. You are on the right path.

or is there any other way like serial interrupt( whenevr +cmti comes it shud go to particular ISR) ?..

2 options there:
1. You can set and enable RCIE and store the GSM data to (by combining data) string whenever RCIF interrupt occurred.
For example,
Code:
void interrupt isr(){
     if (RCIE && RCIF){
         char GSM_REPLY = getch(); // Hi-tech c for PIC16
         RCIF = 0;
     }
}

2. in while(1){ you have to read continuously.
For example:
Code:
while(1){
         char GSM_REPLY = getch(); // Hi-tech c for PIC16
     }
 
Yes speedEC told the right thing
during the start up you delete first message.with command AT+CMGD=1 <enter>
Later wait for +CMTI:"SM",1. when it comes read the message with AT+CMGR=1 <enter>
then check and perform operation you want to do.
Later again delete that message AT+ CMGD=1.

make a variable=0;
check if it is greater than 0
if it is greater than zero check for the above mentioned things.

Its very appreciating as you are moving..
All The Best
 

what is RCIE and RCIF...would you plz elaborate
 

HOW TO STORE THE INCOMING sms IN BUFFER AND USE IT LATER

Sir,
I am able to send msg via SIM300. But i'm facing some problem with receiving sms from sim300 to uc. I'm using two sensor inputs for security features. SO how to store the incoming SMS in a buffer and use it later. Could you plz give me a sample code for that. A s soon as sensor input gets high, i have to send sms to owner regarding security breach. As SIM 300 sends around 60 characters before actual message, how shud i store those values and decode the sms. i want to use interrupt for sensor input (2) and serial interrupt. Plz help
 
Last edited:

hello
i have written codes in assembly for my project i.e. display the message we get from gsm module to the lcd using 8052
so i m using sim900 with 8052
i have checked that my lcd is working fine with the 8052 but i am not able to communicate with sim900...i don't knwo where the problem is, so i am posting the codes here
please check them and introduce me to the errors if any
thanks
Code:
ORG 0H
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
ACALL INT_LCD
H_1: MOV DPTR,#MSG_1
     CLR A
     MOVC A,@A+DPTR
     JZ B_1
     ACALL SEND
     INC DPTR
     SJMP H_1
B_1: ACALL DELAY
     ACALL RECV
     ACALL DATAWRT
     ACALL CLR_LCD
     ACALL INT_LCD
H_2: MOV DPTR,#MSG_2
     CLR A
     MOVC A,@A+DPTR
     JZ B_2
     ACALL SEND
     INC DPTR
     SJMP H_2
B_2: ACALL DELAY
     ACALL RECV
     ACALL DATAWRT
     ACALL CLR_LCD
INT_LCD:
     MOV A,#38H
	 ACALL COMNWRT
	 ACALL DELAY
	 MOV A,#0EH
	 ACALL COMNWRT
	 ACALL DELAY
	 MOV A,#06H
	 ACALL COMNWRT
	 ACALL DELAY
	 RET
COMNWRT:
     MOV P1,A
	 CLR P0.0
	 SETB P0.1
	 ACALL DELAY
	 CLR P0.1
	 RET
DELAY:
     MOV R0,#10
HERE3: MOV R3,#250
HERE2: MOV R4,#255
HERE1: DJNZ R4,HERE1
       DJNZ R3,HERE2
	   DJNZ R0,HERE3
	   RET
SEND: MOV SBUF,A
H: JNB TI,H
   CLR TI
   RET
RECV: JNB RI,RECV
      MOV A,SBUF
	  CLR RI
	  RET
MSG_1: DB "AT",0
MSG_2: DB"AT+CMGF=1",0
DATAWRT:
     MOV P1,A
	 SETB P0.0
	 SETB P0.1
	 ACALL DELAY
	 CLR P0.1
	 RET
CLR_LCD:
     MOV A,#01H
	 ACALL COMNWRT
	 ACALL DELAY
	 RET
END
 

Finally done with project :-D
thankuuuu guys....especially.. SpeedEC, aameer, Jayant thanks a ton for helping !!

- - - Updated - - -

@ammy rao
Try to write code in C..dat wil be more easier for us to understand..nd for u too
 

step 1>>first connect your gsm modem with pc..nd check whether u r able to send sms
step2>> connect ur uc with pc and check whether u r able to communicate with pc.....

have u cmpltd these two steps ??
 

my modem is giving response with mcu
but its not showing any connection with pc
and i have lcd connected to my mcu and that's working perfect

- - - Updated - - -

Connection = MCU board to MAX232 to DB9 Connector to SIM300 board DB9 Connector.
hello
help me i got stuck somewhere

- - - Updated - - -

Code:
#include<reg51.h>
#include<intrins.h>
#include<string.h>
sbit relay=P2^7;
void data_send(unsigned char *);
void delay1();
void compare();
void data_send1(unsigned char *);
void command_mode(unsigned char );
void busy();
void data_res();
void lcd_init();
void gsm_receive();
void gsm_send(unsigned char *);
void delay();
void data_mode(unsigned char *);
void data1_mode(unsigned char);
unsigned char data_receive();
void intialisation();
sbit rs=P0^0;
sbit rw=P0^4;
sbit en=P0^1;
sbit en1=P1^7;
unsigned char *ch="AT\r\n";
unsigned char *ch1="AT+CMGF=1\r\n";
unsigned char *ch2="AT+CMGS=";
unsigned char *ch3="Hi world\r\n";
unsigned char *ch4="AT+CNMI=2,2,0,0,0\r\n";
unsigned char *ch5="AT+CMGR=1\r\n";
unsigned char *ch6="AT+CMGD=1\r\n";
unsigned char *ph1="+919717856679";
unsigned char *msg1="MOTOR ON";
unsigned char *msg2="MOTOR OFF";
unsigned char *ch7="ATEO\r\n";
unsigned char *ch8="AT&W\r\n";
unsigned char *ch9="+919717856688";
unsigned char a[2],cha,ph[14],msg[10],count=0,count1=0;
int main()
{
unsigned char j=0,cha;
P1=0x00;
P2=0x00;
rs=0;
rw=0;
en=0;
en1=1;
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
//gsm_send();
lcd_init();
gsm_receive();
while(1)
{
command_mode(0x80);
cha=data_receive();
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
while(cha!='9')
{
cha=data_receive();
}
while(cha!='1')
{
cha=data_receive();
}
 command_mode(0x01);
for(j=0;j<10;j++)
{
cha=data_receive();
ph[j]=cha;
}
ph[j]='\0';
while(cha!='\n')
{
cha=data_receive();
}
j=0;
cha=data_receive();
while(cha!='\n')
{
msg[j]=cha;
cha=data_receive();
j++;
}
msg[j-1]='\0';
compare();
}
return 0;
}

void data_send(unsigned char *p)
{
while(*p!='\0')
{
SBUF=*p;
while(TI==0);
TI=0;
p++;
}
}

unsigned char data_receive()
{
unsigned char i=0,j=0,ch;
RI=0;
while(RI==0);
ch=SBUF;
return ch;
}
void data_res()
{
unsigned char i=0;
while(i<4)
{
unsigned char ch;
RI=0;
while(RI==0);
ch=SBUF;
i++;
}
}

void compare()
{
unsigned char j=0;
if(strcmp(ph,ph1)==0&&strcmp(msg,msg1)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=1;
count1=0;
ch9=ph;
if(count>0)
{
gsm_send("MOTOR ALREADY ON");
}
else
{
gsm_send("MOTOR ON");
}
count++;
}
else if(strcmp(ph,ph1)==0&&strcmp(msg,msg2)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=0;
count=0;
ch9=ph;
if(count1>0)
{
gsm_send("MOTOR ALREADY OFF");
count=0;
}
else
{
gsm_send("MOTOR OFF");
}
count1++;
}
else if(strcmp(ph,ph1)!=0&&strcmp(msg,msg1)!=0)
{
ch9=ph;
data_mode("Invalid no & msg");
gsm_send("you r not authorised");
}
else if(strcmp(ph,ph1)!=0||strcmp(msg,msg1)!=0)
{
if(strcmp(ph,ph1)!=0)
{
ch9=ph;
data_mode("Invalid no");
command_mode(0xc0);
data_mode(ph);
gsm_send("you r not authorised");
}
else{
ch9=ph;
data_mode("Invalid msg");
command_mode(0xc0);
data_mode(msg);
gsm_send("Invalid msg");
} 
}
}
void command_mode(unsigned char a)
{
busy();
rs=0;
rw=0;
P1=a;
en=1;
_nop_();
_nop_();
en=0;
}

void busy( )
{
en1=1;
rs=0;
rw=1;
while(en1)
{
en=0;
_nop_();
_nop_();
en=1;
}
}

void data_mode(unsigned char *p)
{
busy();
rs=1;
rw=0;
while(*p!='\0')
{
P1=*p;
intialisation();
p++;
}
} 

/*void data1_mode(unsigned char p)
{
busy();
rs=1;
rw=0;
P1=p;
intialisation();
}*/ 

void intialisation()
{
en=1;
_nop_();
_nop_();
en=0;
}
void gsm_send(unsigned char *ch3)
{
data_send(ch);
data_res();
data_send(ch1);
data_res();
data_send(ch2);
data_res();
data_send(a);
data_send(ch9);
data_send(a);
data_send("\r\n");
data_send(ch3);
data_res();
SBUF=0x1a;
while(TI==0);
TI=0;
}
void gsm_receive()
{
data_send(ch7);
data_res();
data_send(ch8);
data_res();
data_send(ch1);
//delay();
data_res();
data_send(ch4);
//delay();
data_res();
}

void lcd_init()
{
command_mode(0x01);
command_mode(0x38);
command_mode(0x06);
command_mode(0x80);										
command_mode(0x0f);
}

/*void delay1()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/

/*void delay()//10ms delay
{
TMOD=0x01;
TH0=0xdb;
TL0=0xff;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/
i get these codes from somewhere...will anyone please check them out??
i have to submit my project on 29may...so i need urgent help
 

Have you interfaced with max232 while connecting to PC. Check the cable connection. it should work with PC,if it is working with micro controller.
 

i have checked that my lcd is working fine with the 8052 but i am not able to communicate with sim900

my modem is giving response with mcu
but its not showing any connection with pc
and i have lcd connected to my mcu and that's working perfect

Earlier u said..ur modem is not working fine.
Now u'r saying ..modem is giving response with uc..
What prblm ur exactly facing.. download putty software. Connect ur modem to PC via serial to usb convertor. Set the baudrate 9600. and type "AT" enter.
Check the response !!
and let me know.
I completed dis project just 7 days ago. It will work. easy only !!
 

Have you set ATE0(echo off), IPR match with GSM module? If yes, then just display the GSM output on LCD using following method (Don't need to send any AT command initially) just call the GSM mobile number from your phone/mobile- you have to convert it in to asm.

char GSM_char = getch(); // receive the char from GSM Module

showOnLcd(GSM_char);

Note: see the value of GSM_char in debugging. It should show 0x0D ('\r').
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…