# Control LED via SMS

**URL:** <https://forum.arduino.cc/t/control-led-via-sms/206431>\
**Category:** General Guidance\
**Created:** [January 20, 2014, 2:08am UTC](https://forum.arduino.cc/t/control-led-via-sms/206431 "2014-01-20T02:08:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 20, 2014, 2:08am UTC](https://forum.arduino.cc/t/control-led-via-sms/206431/1 "2014-01-20T02:08:46Z")

</div>

```arduino
// 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.

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

---

<div class="post-metadata">

**Author:** ![graynomad](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/graynomad/32/213871_2.png) [@graynomad](https://forum.arduino.cc/u/graynomad)\
**Post date:** [January 20, 2014, 7:02am UTC](https://forum.arduino.cc/t/control-led-via-sms/206431/2 "2014-01-20T07:02:34Z")

</div>

```cpp
  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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 5:04pm UTC](https://forum.arduino.cc/t/control-led-via-sms/206431/3 "2021-05-05T17:04:08Z")

</div>

Closed on May 5, 2021, 5:04pm UTC


