How to send multiple instructions in one sms.

hi guys,

I want to send multiple instructions in one sms e.g. (LED 1 ON , LED 2 OFF, LED 3 ON) to turn on/off any pin. And also want the arduino to send back the pin status whether on/off if i send " show status " , the message sent by arduino might be like ( LED 1 is ON , LED 2 ON ,and LED 3 OFF ). Thanks

I want to send multiple instructions in one sms

You have our permission.

And also want the arduino to send back the pin status whether on/off if i send " show status "

You have our permission.

Did you need anything else?

How to send multiple instructions in one sms.

Probably the easiest way is to delimit each data part in the total string sent, and end each string with another delimiter. The below test code looks for a comma to separate the data parts and a # as the end of the sent string marker.

//zoomkat 11-12-13 String capture and parsing  
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// * is used as the data string delimiter
// , is used to delimit individual data 

String readString; //main captured String 
String angle; //data String
String fuel;
String speed1;
String altidude;

int ind1; // , locations
int ind2;
int ind3;
int ind4;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like 90,low,15.6,125*
  //or 130,hi,7.2,389*

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == '*') {
      //do stuff
      
      Serial.println();
      Serial.print("captured String is : "); 
      Serial.println(readString); //prints string to serial port out
      
      ind1 = readString.indexOf(',');  //finds location of first ,
      angle = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(',', ind1+1 );   //finds location of second ,
      fuel = readString.substring(ind1+1, ind2+1);   //captures second data String
      ind3 = readString.indexOf(',', ind2+1 );
      speed1 = readString.substring(ind2+1, ind3+1);
      ind4 = readString.indexOf(',', ind3+1 );
      altidude = readString.substring(ind3+1); //captures remain part of data after last ,

      Serial.print("angle = ");
      Serial.println(angle); 
      Serial.print("fuel = ");
      Serial.println(fuel);
      Serial.print("speed = ");
      Serial.println(speed1);
      Serial.print("altidude = ");
      Serial.println(altidude);
      Serial.println();
      Serial.println();
      
      readString=""; //clears variable for new input
      angle="";
      fuel="";
      speed1="";
      altidude="";
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

In fact, I want to use GSM to control the home using SMS My question is how I can -Send a single message to GSM containing multiple commands like(led1 off,led2 on,led3 on){send by phone to arduino}

  • know the current situation if i send to arduino ((what is the situation now)) the arduino send back (the led1 is on,the led2 is off,the led3 is on){send by arduino to phone}

My question is how I can -Send a single message to GSM containing multiple commands like(led1 off,led2 on,led3 on)

Do you know how to send ANYTHING now? If not, that's the place to start.

If you do, changing what to send is trivial.

Yes i sent more than ordered and responded with me But I want to send all the commands in a single message

But I want to send all the commands in a single message

You still haven’t shared your code, so all we can do is wish you luck. Good luck.

#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER “”

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];
int led1=13;
int led2=12;
int led3=11;
int led4=10;
int led5=9;
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
}

Serial.println(“SMS Messages Receiver”);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
// connection state
boolean notConnected = true;

// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println(“Not connected”);
delay(1000);
}
}

Serial.println(“GSM initialized”);
Serial.println(“Waiting for messages”);
}

void loop()
{
char c;

// If there are any SMSs available()
if (sms.available())
{
Serial.println(“Message received from:”);
char c;
String received = “”;

while(c=sms.read())
received += c;

if
(received.compareTo(“on lamb”) == 0 )
{
digitalWrite(led1, HIGH); delay (1000);
digitalWrite(led1, LOW);
}
else if(received.compareTo(“off lamb”) == 0)
{
digitalWrite(led1, HIGH);
delay (1000);
digitalWrite(led1, LOW);
}
else if(received.compareTo(“on AC”) == 0)
{
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);
}
else if(received.compareTo(“off AC”) == 0)
{
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);
}
else if(received.compareTo(“on fan”) == 0)
{
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
}
else if(received.compareTo(“off fan”) == 0)
{
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
}
else if(received.compareTo(“on security”) == 0)
{
digitalWrite(led4, HIGH);
delay (1000);
digitalWrite(led4, LOW);
}
else if(received.compareTo(“off security”) == 0)
{
digitalWrite(led4, HIGH);
delay (1000);
digitalWrite(led4, LOW);
}
else if(received.compareTo(“on all”) == 0)
{
digitalWrite(led5, HIGH);
delay (1000);
digitalWrite(led5, LOW);
}
else if(received.compareTo(“off all”) == 0)
{
digitalWrite(led5, HIGH);
delay (1000);
digitalWrite(led5, LOW);
}
else
{
}
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);

// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()==’#’)
{
Serial.println(“Discarded SMS”);
sms.flush();
}

// Read message bytes and print them
while(c=sms.read())
Serial.print(c);

Serial.println("\nEND OF MESSAGE");

// Delete message from modem memory
sms.flush();
Serial.println(“MESSAGE DELETED”);
}

delay(1000);

}

That code is for receiving text messages, not for sending them. Perhaps your thread title is wrong.

String received = "";

while(c=sms.read())
  received += c;

while statements should ALWAYS have curly braces, even if there is only one statement in the block.

After the code ends, there is something in received. What?

if
(received.compareTo("on lamb") == 0 )

The ( goes on the same line as the if statement.

I really don't think sompareTo() is the method you want to use. That tests that received contains exactly "on lamb". Look at the other members in the String class, such as indexOf(). The indexOf() method will tell you if receiver [u]contains[/u] "on lamb", rather than [u]is[/u] "on lamb".

You could send "on lamb; on lamc", and receiver.indexOf("on lamb") would return 0 and reciever.indexOf("on lamc") would return 9, while receiver.indexOf"cake and ice cream") would return -1. Any non-negative value indicates that the string search for was found.