Go Down

Topic: How to switch LEDs on & off sending sms to a single led (Read 8631 times) previous topic - next topic

Stefano81

Hello Guys
I am new on this forum and I am trying to look for a project using sim 900 that switchs on and off a single led sending sms.
I found one on a website that it's pretty much what I am looking for,  but the problem is that I have to write in a sms all the sequence starting from LED 'A' to 'D' to get what I need, (example, #a1b1c0d1). If I want to command a single LED by just writing a sms starting with #c1 or #d0 ..... Does anyone know how to help me, is it possible to do that? I am posting the sketch I want to modify.
Thank you.


#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7,8);

int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;

void setup()
{
 Serial.begin(19200);
 // set up the digital pins to control
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(led4, OUTPUT);
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 digitalWrite(led3, LOW);
 digitalWrite(led4, LOW);

 // wake up the GSM shield
 SIM900power();
 SIM900.begin(19200);
 delay(20000);  // give time to log on to network.
 SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
 delay(100);
 SIM900.print("AT+CNMI=2,2,0,0,0\r");
 // blurt out contents of new SMS upon receipt to the GSM shield's serial out
 delay(100);
 Serial.println("Ready...");
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
 digitalWrite(9, HIGH);
 delay(1000);
 digitalWrite(9, LOW);
 delay(7000);
}

void loop()
{
 //If a character comes in from the cellular module...
 if(SIM900.available() >0)
 {
   inchar=SIM900.read();
   if (inchar=='#')
   {
     delay(10);

     inchar=SIM900.read();
     if (inchar=='a')
     {
       delay(10);
       inchar=SIM900.read();
       if (inchar=='0')
       {
         digitalWrite(led1, LOW);
       }
       else if (inchar=='1')
       {
         digitalWrite(led1, HIGH);
       }
       delay(10);
       inchar=SIM900.read();
       if (inchar=='b')
       {
         inchar=SIM900.read();
         if (inchar=='0')
         {
           digitalWrite(led2, LOW);
         }
         else if (inchar=='1')
         {
           digitalWrite(led2, HIGH);
         }
         delay(10);
         inchar=SIM900.read();
         if (inchar=='c')
         {
           inchar=SIM900.read();
           if (inchar=='0')
           {
             digitalWrite(led3, LOW);
           }
           else if (inchar=='1')
           {
             digitalWrite(led3, HIGH);
           }
           delay(10);
           inchar=SIM900.read();
           if (inchar=='d')
           {
             delay(10);
             inchar=SIM900.read();
             if (inchar=='0')
             {
               digitalWrite(led4, LOW);
             }
             else if (inchar=='1')
             {
               digitalWrite(led4, HIGH);
             }
             delay(10);
           }
         }
         SIM900.println("AT+CMGD=1,4"); // delete all SMS
       }
     }
   }
 }
}

dannable

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

Stefano81

I did because I got the sketch from http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/ and I really like how it works but the only problem I want to find if there is a way to modify something in it to no write all the sequence starting from LED a-d

dannable

I don't really understand what you are trying to do.
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

Stefano81

I just want to control 4 lights using arduino through sms and reading the status of a single light.

What I want to do is to use some specified command to control each light separately.

For example, I want to send #a1 or #a0 to control light1 only, and #b1 or #b0 to control light2 only, and #as

or #bs to control the status of a single light

For example I only want to turn on or off light2 without turning light1

I hope I have been clearer now.



Thank you

Stefano81

Does anyone have some sketch to help me to switch on and off each single light using sim900?

Thank you

dannable

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

Stefano81

If I send the sms #a1 it works but if I send only #b1 it doesn't. To switch on and off b1 I have to send #a1b1

dannable

Have a look at the switch...case function, and apply after your second read of SIM900.read().
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

nikhiljoji

Hi,
While receiving an sms you will get details like date, time, sms, sms sender number etc...you can check this in the serial terminal .. so what we need to do is to check whether the incoming data has got the required data..
for example if you want to turn on an led by sendin sms "ledON" ...
try this program code

while (Serial.available())
{
delay(3);
 d = Serial.readString();  //this will save the whole data to the String variable d..
if(d.indexOf("ledON") >=0)  // checking whether the msg(that is saved in d) has got "ledON" in it
   {
 digitalWrite(ledPin1,HIGH);  // turning on led
 Serial.println("light one is ON");
    }


check the link below ..this worked for me...

http://arduinoisfun.blogspot.in/2015/04/receive-message-with-arduino-with.html

all the best .. :)

Go Up