Go Down

Topic: Control LED via SMS (Read 441 times) previous topic - next topic

remms

Jan 20, 2014, 03:08 am Last Edit: Jan 20, 2014, 04:24 am by remms Reason: 1
Code: [Select]

// include the GSM library
#include <GSM.h>


// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

int led = 13; //pin 13

void setup()
{
 // initialize serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }
pinMode(13, OUTPUT);
digitalWrite(13, LOW);

 Serial.println("SMS Messages Receiver");
 
}

void loop()
{
 
char c;
 
 while(c=sms.read())
     Serial.print(c);
 // If there are any SMSs available()  
 if (sms.available())
 {
 c=Serial.read();
   {
   if( c == 'a')
       {
         digitalWrite(13,HIGH);
       }
   
   if(c == 'o'){
     digitalWrite(13, LOW);}
     
   
   // Delete message from modem memory
   sms.flush();
   Serial.println("MESSAGE DELETED");
 }

 delay(1000);

}
}


This is the code that we made (from several sources). We have compiled it, and uploaded into Arduino Uno R3 which has been attached with GSM SIM900.

We made it so when  we sent "a" the led will turn on while "o" will turn it off.

But then, we sent a text, but nothing happened.

We're desperately need help, thanks.


Quote
PS: To connect the arduino to the breadboard, well the led will be used on breadboard, should we use RX and TX?

graynomad

Code: [Select]
  while(c=sms.read())
      Serial.print(c);
  // If there are any SMSs available() 
  if (sms.available())
  {
  c=Serial.read();


I'm not familiar with the SMS library but that looks to me as though you read character before you check for an SMS, then having found an SMS you read the serial port, wouldn't you do as sms.read() ?

As I said I'm not familiar with the SMS lib, but that seems all arse about face to me. Wouldn't you wait for an sms to be available then read from the sms?

(I'll go have a look at the library)

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up