GSM text turn on led / relay

Hi all

iv got my GSM Shield up and running , im getting text comming in sooo that is all fine but

i would like to send a message with the word "on" in it and it would then turn on a led or relay

here is my code , i hope that some one could help me

#include "SIM900.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int backLight = 13;    // pin 13 will control the backlight
int ledpin = 11;
char msg[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[12];
int lcd_key = 0;
int adc_key_in = 0;
char nr = 4040xxxx;

void setup()
{
      //LCD Setup
      pinMode(backLight, OUTPUT);
      digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
      lcd.begin(16,2); // columns, rows.  use 16,2 for a 16x2 LCD, etc.
      lcd.print("Starting up");  // start with a "blank screen"
      // Tricker setup
      pinMode(ledpin,   OUTPUT);
      
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          lcd.setCursor(0,0);           // set cursor to column 0, row 0 (the first row)
          lcd.print("\nstatus=READY");
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");
            lcd.setCursor(0,0);           // set cursor to column 0, row 0 (the first row)
            lcd.print("\nstatus=READY");

     if(started) {
          //Enable this two lines if you want to send an SMS.
          //if (sms.SendSMS("4040xxxx", "Arduino SMS"))
          Serial.println("Ready To Send");
          lcd.setCursor(0,0);           // set cursor to column 0, row 0 (the first row)
          lcd.print("Ready to send");
     }
}

void loop()
{
     //lcd.setCursor(9,1); // place cursor
     //lcd.print(millis()/1000); // display seconds 
     lcd.setCursor(0,1); // move cursor
     lcd_key = analogRead(0); // read the buttons

     if (lcd_key<50){
        if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("4040xxxx", "Button Right"))
          Serial.println("\nSMS sent OK");
          lcd.setCursor(0,0);           // set cursor to column 0, row 1 (the first row)
          lcd.print("Ready to send");
          lcd.setCursor(0,1);           // set cursor to column 0, row 1 (the first row)
          lcd.print("SMS sent OK");
      
     }
     } 
     else if (lcd_key<250){
        if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("4040xxxx", "Button UP"))
          Serial.println("\nSMS sent OK");
          lcd.setCursor(0,0);           // set cursor to column 0, row 0 (the first row)
          lcd.print("Ready to send");
          lcd.setCursor(0,1);           // set cursor to column 0, row 1 (the first row)
          lcd.print("SMS sent OK");
      
     }
     } 
     else if (lcd_key<450)
     {
     
               lcd.setCursor(0,0);           // set cursor to column 0, row 1 (the first row)
               lcd.print("Ready to send");
               lcd.setCursor(0,1);           // set cursor to column 0, row 1 (the first row)
               lcd.print("                ");         
     }
     else if (lcd_key>550)
     {
     if(started) {
          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer,160,n,12)) {
               Serial.println(n);
               Serial.println(smsbuffer);
               lcd.setCursor(0,0);           // set cursor to column 0, row 1 (the first row)
               lcd.print("                 ");
               lcd.setCursor(0,0);           // set cursor to column 0, row 1 (the first row)
               lcd.print(n);
               lcd.setCursor(0,1);           // set cursor to column 0, row 1 (the first row)
               lcd.print(smsbuffer);
               
              
          }
           if(gsm.readSMS(smsbuffer,160,n,12) == 'On, +454040xxxx')
            {
              Serial.println("led on");
              analogWrite(ledpin, 255);  
            }
            }        
          delay(1000);
            }
     }

char nr = 4040xxxx;

If that value is redacted, I'm wondering if the value actually fits in a char.

            lcd.print("\nstatus=READY");

Does the LCD really know what to do with a carriage return?

          if (sms.SendSMS("4040xxxx", "Button Right"))

Hmmm. There's that same value, this time as a string. Makes me even more suspicious that the char nr statement is crap.

          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer,160,n,12)) {
               Serial.println(n);
               Serial.println(smsbuffer);

So, if you send a text message to the Arduino, what gets printed? It would make a lot more sense, to me at least, to print the message with an identifier and between markers so I could see EXACTLY what was in smsbuffer.

Serial.print("Text message received: [");
Serial.print(smsbuffer);
Serial.println("]");

Text message received: [on]

is not the same contents as

Text message received: [on
]

It makes a difference how you attempt to deal with the data in smsbuffer.

Once we know exactly what you sent, and exactly what is in smsbuffer, we can help with using the received data to perform an action.

strcmp(), strtok(), strstr() are some of the functions that can be used to deal with the contents of smsbuffer.

ok thx for reply

4040xxxx is my number so in the code there is a function pus a button to send sms

and what ever faults there is with my LCD is not the problem , it is working fine... but

what i cant make it to do is make the pin 11 go HIGH

what i would like is if i send ledON it will turn the pin11 HIGH

i did not write the code my self i only added the LCD part and Buttons....

the code is an example from GSM-GPRS-GPS-Shield-GSMSHIELD SIM900.cpp

i have only been toyring around with this about a year now

what i would like is if i send ledON it will turn the pin11 HIGH

So, what is stopping you? I have no idea what is ACTUALLY in smsbuffer when you send the Arduino a text message, and you apparently don't know, either, or won't share what you do know.

Is pin 11 used by any other device? If so, you will need to use another pin. Print out what is captured to the serial monitor is important for trouble shooting.

@PaulS

i only know what my display type ... it is the picture i attached.. the number in the top is part of my number. and the text on the buttom is the text i sendt to the arduino but the display add the ting in the end of my text.

@zoomkat
the pin11 is only used by the led

i did not write the code... and i have no skills in c/c++ just the basic stuff , that is why i ask in here
this is a printout from the serial monitor when it gets a sms
ATT: +CMGL
RIC:
+CMGL: 1,"REC UNREAD","+454040xxxx","","15/10/31,20:25:37+04"
Test

OK

ATT: OK
RIC:
OK

+454040xxxx // Serial.println(n);
Test // Serial.println(smsbuffer);

ATT: +CMGL
RIC:
OK

this is a printout from the serial monitor when it gets a sms

And which part of that is actually in smsbuffer? I asked you to change the code to make that clear. You couldn't be bothered, so I can't anymore, either.

@PaulS

in the print out there is standing what is smsbuffer

soo i guess i did not understand you question.....

+454040xxxx // Serial.println(n);
Test // Serial.println(smsbuffer); this is what is in the buffer

sooo Paul sorry that im not as god as you and i guess englis is you main langue.... mine is not

Simple serial example code that captures serial input and then looks to see if "on" is present to control an arduino pin.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

//A very simple example of sending a string of characters 
//from the serial monitor, capturing the individual 
//characters into a String, then evaluating the contents 
//of the String to possibly perform an action (on/off board LED).

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(2);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if(readString.indexOf("on") >=0)
    {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }

    if(readString.indexOf("off") >=0)
    {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }

    readString="";
  } 
}

Hi

Have a look at this topic:

http://forum.arduino.cc/index.php?topic=356494.msg2458955#msg2458955

I have a prototype SIM800 GSM module application running that can receive instructions via text messages and take actions within the Arduino application (e.g. switch a pin on or off to control an external device). It also sends text message responses.

If you need help I may be able to assist.

Catweazle NZ

@CatweazleNZ....

that would be great......

@zoomkat

thx ill try to use the code you sendt... i can turn on the led with it and it works
but how do i get it to work with the gsm module

Hi

I have placed my Arduino GSM800 development application source code in the PUBLIC folder on the SD Card web page of my Arduino home automation system at http://www.2wg.co.nz/ - look for the file GSM_TEST.INO

The code is just work-in-progress - it is full of rubbish but I think well written in any case.

Have a look at the procedure CheckSMSReceived() which looks for incoming and unprocessed text messages (only the first one is processed each time CheckSMSReceived() is called).

Have a look at the procedure ProcessSMSReceived() which parses and processes an unprocessed text message.

Have a look at the procedure ProcessCommandRequest() - it calls one of many subprocedures to process specific incoming text message commands.

Have a look at the procedure DeviceCommand() - for specific devices on specific pins this procedure will set digital pins HIGH or LOW in response to incoming text message requests/commands.

I don't expect you will need to understand much of the remaining code. However try to understand the procedure ENDF2 - it is a could way to parse incoming SMS messages to break them up into the various parts and to "read" the actual message content.

I hope this helps.

Cheers

Catweazle NZ

@CatweazleNZ

thx super great... ill take a look at it