Sim 900 sketch works but How I get more contolled LED's

hey

I am quite new here so. I got this sketch working with gsm gprs libraries. I want atleast 4 remote controlled digital pins. Now there is One working (D13)
How I change the code ? :o

Code is here:

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
char number[]="3921234567";
char message[180];
char pos;
char *p;
void setup()

{

Serial.begin(9600);

if (gsm.begin(2400))
  Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
pos=sms.IsSMSPresent(SMS_UNREAD);

Serial.println((int)pos);

if((int)pos>0&&(int)pos<=20){
  Serial.print("NUOVO MESSAGGIO, POS=");
  Serial.println((int)pos);
  message[0]='\0';
  sms.GetSMS((int)pos,number,message,180);
  p=strstr(message,"testpwd");
  if(p){
    Serial.println("PSWD OK");
    p=strstr(message,"LEDON");
    if(p){
      Serial.println("LED ON");
      digitalWrite(13,HIGH);
    }
    else{
      p=strstr(message,"LEDOFF");
      if(p){
        Serial.println("LED OFF");
        digitalWrite(13,LOW);
      }
    }
  }
  sms.DeleteSMS((int)pos);
}
delay(5000);
};

There are lots of projects related to this :
click here

Could you edit your post and put the code within code tags please? It’s the scroll icon with <> on it.

And in general, send a different message for each action and check for the presence as you do for “testpwd”, say “led1on”, “led1off”, “led2on” (you get the idea?) then act accordingly.

You look as though you have some unnecessary characters in your code too.

Ya, I get that, sending different sms. But How I modify the code?

Following in the style you are using, just expand your code. Where you have

  p=strstr(message,"testpwd");
  if(p){
    Serial.println("PSWD OK");
    p=strstr(message,"LEDON");
    if(p){
      Serial.println("LED ON");
      digitalWrite(13,HIGH);
    }
    else{
      p=strstr(message,"LEDOFF");
      if(p){
        Serial.println("LED OFF");
        digitalWrite(13,LOW);
      }
    }
  }

replace it with

  p=strstr(message,"testpwd");
  if(p){
    Serial.println("PSWD OK");
    p=strstr(message,"LED13ON");
    if(p){
      Serial.println("LED 13 ON");
      digitalWrite(13,HIGH);
    }
    p=strstr(message,"LED13OFF");
    if(p){
      Serial.println("LED 13 OFF");
      digitalWrite(13,LOW);
    }
    p=strstr(message,"LED12ON");
    if(p){
      Serial.println("LED 12 ON");
      digitalWrite(12,HIGH);
    }
    p=strstr(message,"LED12OFF");
    if(p){
      Serial.println("LED 12 OFF");
      digitalWrite(12,LOW);
    }
  }

(Not compiled or tested)

If you are going to do more than the example above you might want to read up on arrays.

Hey again :slight_smile:

I tried that code + several others styles but not mach.
with your expanded code it arduino program say:

error: expected declaration before '}' token
and the "delay(5000)" is yellow

My code was just an example. You'd better post your code. Don't forget the code tags!