Go Down

Topic: Send temp via sms "Sagem Hilo" (Read 775 times) previous topic - next topic

allp

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

PaulS

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: [Select]
     Serial.print("Hola caracola...");     // the SMS body
Replace that literal string with a variable:
Code: [Select]
char *buffer = "Hey, there";
Serial.print(buffer);

to print data that is in a variable.

Now, you can create an array, instead:
Code: [Select]
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: [Select]
Serial.print("Temp is ");
Serial.print(tempC);
Serial.print(" degrees C");

allp

#2
Aug 18, 2011, 02:24 pm Last Edit: Aug 18, 2011, 02:26 pm by allp Reason: 1
Hey PaulS,

thanks for the code and the good explanation, you are the best! ;)
It sounds really easy!

Quote
Code: [Select]
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

PaulS

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

Not. Look back at your original code.
Code: [Select]
      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...

allp

thx for the fast answer.

okay i think i will try it with a RTC. a good idea! ;)

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?

PaulS

Quote
is so what feasible?

Yes.

Quote
can you help me in this case?

No, sorry.

allp

No Problem. ;)
Perhaps you have any Links where i can get some info how i can do this?

allp

Go Up