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 ??
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
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' ??
// 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()
}
}
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 !!
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 ??