Pages: [1]   Go Down
Author Topic: Send temp via sms "Sagem Hilo"  (Read 608 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,

i want to send temperature via sms to my mobilephone two time a day. 
I know how i can send a sms, here the code:

void loop(){
   
   while (count < timesToSend){
      delay(1500);
      Serial.print("AT+CMGS=");          // send the SMS the number
      Serial.print(34,BYTE);             // send the " char
      Serial.print("*********");         // send the number (change ********* by the actual number)
      Serial.println(34,BYTE);           // send the " char
      delay(1500);
      Serial.print("Hola caracola...");     // the SMS body
      delay(500);
      Serial.print(0x1A,BYTE);             // end of message command 1A (hex)
         
      delay(5000);

      count++

but if i want to send for example temperature which I have previously recorded, how looks the code therefor.

I hope you understand what i mean.
Sorry for the bad english.



allp
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46265
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but if i want to send for example temperature which I have previously recorded, how looks the code therefor.
You have this code:
Code:
     Serial.print("Hola caracola...");     // the SMS body
Replace that literal string with a variable:
Code:
char *buffer = "Hey, there";
Serial.print(buffer);
to print data that is in a variable.

Now, you can create an array, instead:
Code:
char buffer[128];
sprintf(buffer, "Temp is %d degrees C", tempC);
Serial.print(buffer);
where it is assumed that tempC is an int variable containing the temperature.

The sprintf function for the Arduino does not support the %f format specifier, so formatted printing of floats is a bit more of a challenge.

However, the Serial instance derives from the Print class, whose print method is overloaded to print floats, so, if tempC is a float (or double), you could do this:
Code:
Serial.print("Temp is ");
Serial.print(tempC);
Serial.print(" degrees C");
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey PaulS,

thanks for the code and the good explanation, you are the best! smiley-wink
It sounds really easy!

Quote
Code:
Serial.print("Temp is ");
Serial.print(tempC);
Serial.print(" degrees C");

but that means that i send 3 sms a time, or not?


whats about to send a sms at a certain time, e.g. at 11.00am? how can i realize this, with a loop? or is there a better way?


allp
« Last Edit: August 18, 2011, 07:26:52 am by allp » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46265
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but that means that i send 3 sms a time, or not?
Not. Look back at your original code.
Code:
      Serial.print(0x1A,BYTE);    // end of message command 1A (hex)
Nothing actually gets sent until this function is called.

Quote
whats about to send a sms at a certain time, e.g. at 11.00am?
Do you know when it is 11:00 AM? If so, then, when it is that time, or the next pass through loop when it is after that time, send the message.

If not, you need either an RTC (real time clock) or a way to get the time - a permanent USB connection to a PC or an ethernet shield. The RTC is a lot cheaper...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx for the fast answer.

okay i think i will try it with a RTC. a good idea! smiley-wink

now i will also query the temp at any time, for example i send a sms with a code to the shield and get so the temp from the shield. is so what feasible? can you help me in this case?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46265
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is so what feasible?
Yes.

Quote
can you help me in this case?
No, sorry.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No Problem. smiley-wink
Perhaps you have any Links where i can get some info how i can do this?

allp
Logged

Pages: [1]   Go Up
Jump to: