Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

code for interfacing gsm modem with at89s52

Status
Not open for further replies.

Jestin Kuriakose

Newbie level 6
Newbie level 6
Joined
Dec 21, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
97
i am doing a project on gsm based irrigation system.i am using at89s52 uc and sim300 gsm modem.

here i am interfacing 3 sensors ,and accordingly it will send sms to users mobile when any one of the sensor values decreses below some value.also,we can check the condition of the field at any time just by sending a message to the gsm modem.

i am done with the hardware part,but i m confused with the coding part.should i initialize the gsm modem inside the while loop,before checking the sensor values ??

please help.this is my final year project.urgent !!
 

Hello,
As per your expalnation you should do the basic thing

HTML:
send the AT Commands using Tx of your Microcontroller 
// AT Commands in main Function  ( NOT In WHILE(1)LOOP )
AT - Initailize the communication
ATE0 - Echo Off 
AT+CMGF=1 ; // Configures as TEXT MODE
//THIS COMMAND is needed only for SIM300 if you are using SIM900 you just discard this Command//
AT+CSCA="+xxxxx" Set your SMS center's number. Check with your provider.

So, These are the basic AT Command which you have to use before while(1) loop that runs only 1 time in the main Function,

Your GSM will be configured to send SMS in CASES you have defined depending upoun your sensors
like I am giving you one example
Code:
if(1stsensorevent==occurs)
{
delay(10);
send AT Commad through Tx of your MCU, 
AT+CMGS = "NUMBER";
delay(any_number);
SEND text via Tx Line again
delay();
SEND (ctrl+Z) though Tx of MCU in Hex that is (0x1D); // CHECK for that I may be wrong whetjer it is 0x1A or 0x1D
}
 
Thank you so much for your reply.
As i said already,my GSM modem should send message to user's phone when any one of the sensor values decreases below certain value.the message should contain the sensor values.
for eg-i am using a temp sensor LM35.If the temp value increases above 40*c,a message should be sent to user's phone indicating the current temperature.According to the datasheet for 10bit ADC,for 40*c,corresponding ADC value will be 82.So the code-
if(adc1>82)
{
temp=adc1*0.489;
send2gsm("temperature=temp");
can i write temp there ?? will it send the current temp value ??
 
Last edited:

temp=adc1*0.489;
send2gsm("temperature=temp");

No You can not write send2gsm("=TEMP") as i don't know your Functions details but still that " TEMP " will be treated as a STRING so better it would be like

Code:
// Write in the Following Manner
AT+CMGS = "Phone_number";
>  // This comes after this command is given //
/*Write like*/ send_string_gms("Temperature="); 
send_string_gsm(temp) ; // This will take the Char String temp's Value
 
the functions are as follows-

void serial(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}


void Send2Gsm(char *aaa)
{
unsigned int i;
for(i=0;aaa!=0;i++)
{
serial(aaa);
}
}

and in the while(1) loop,
while(1)
{
if(adc1>82)
{
temp=adc1*0.489;
send2gsm("temperature=");
send2gsm(temp);
Will the SMS comes likes 'temperature=40' ??
 

If the Serial Function is correct then I am writing Code

Code:
void serial(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
Now Use the Following

Code:
// This Will send the Strings via Tx PIN of UART

void Send_string(char *aaa)
{
while(*aaa!='\0')
{
serial(*aaa);
aaa++;
}
}

Now here Comes main() Function

Code:
void main()
{
unsigned char user_phone_number[13] = "***********", my_char_temp[10] ;

Send_string("AT\r");
delay(2500);
/**
***********************************************
 Send the AT Commands as I told in My Previous POST sequentially
************************************************/
while(1)
{
if(adc1>82)
{
temp=(adc1*0.489);
/*** if temp is an integer Variable***/
sprintf(my_char_temp,"%d",temp);
/** This will convert Integer Value to String ***/
delay(500); // Delay half second
Send_string("AT+CMGS=");
serial('"');
Send_string(User_phone_number); serial('"');
Send_string("\r\n");
/*******************
Write You Desired Text or message to be sent
*********************/
Send_string("Tempertaure="); Send_string(my_char_temp);

delay(500);
serial()

}

}
 
Code:
Send_string("Tempertaure="); Send_string(my_char_temp);

delay(500);
serial()

will the message comes like-Temperature=40' ?
what is the need of calling function serial() at the end ?
 

Sorry, i forgot to write the serial(0x1A); i.e to send the sms :: equivalent to (ctrl+z),
that will send message as you can see in while(1) loop in my previous post,


yes the message that you will receive is like the string "Temperature=" and then it would take the value my_temp i.e whatever be the temperature !!
 
so,can i write like this ?

Code:
temp=(adc1*0.489);
rh=***** ;
sleval=****;
sprintf(string,"Temperature=%f *c,relative humidity=%f %,soil moisture=%f ",temp,rh,sleval);
delay(500);
Send2Gsm(string);
delay(500);
serial(0x1A);

will it send message like below-
Temperature=40 *c
relative humidity=** %
soil moisture=**
 

You are not getting it sprintf converts integer to char ,
your function send2gsm sends the string via TX of UART but you have to send it to GSM Rx pin so you need to send

RELEVANT AT COMMANDS first then text as i mentioned in my previous post also,
after sending "AT+CMGS="number" followed by Carriage return ,
whatever you will send it will be received in MOBILE,here you can write Send2gsm("your particulars");
if they are in quotes then the Word which you have written inside it will be sent and after that if you write send2sgm(temp_my); then it will send the Value assigned to "temp_my" variable so finally you what you will receive in mobile

TEMPERTAURE= // This is the first string
40 or whatever be the value assigned to 'tmep_my' variable

Same for Humidity and all

sprintf worked fine for me for integer Values You check for Floating type value ?
Also separate sprintf has to be used for Conversion like for temp one another sprintf for humidity
// But check for the sprintf whether it works for floating type Variables or not ??
 
ok
here i am using a 11.0592mhz crystal oscillator.so,does the below delay() function works to give msec delay?

Code:
void MsDelay(unsigned int value)
  {
    unsigned int x, y;
    for(x=0;x<1275;x++)
      for(y=0;y<value;y++);
  }
 

yes it can
for more analysis you can use CRO also but as reference from ALI Mazidi Book It gives 1ms delay
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top