GSM control statements

Can anyone advise how to control the GSM + arduino module with regards to reading SMS messages and using a simple push button?

I want the GSM to output HIGH to an LED, after receiving an SMS message, until the push button is pressed, and then the LED will turn off until another text is sent.

I have tried various else...if/switch case statements but cannot get it to respond when the push button is pressed.

Any help much appreciated

Rosanna

I have tried various else...if/switch case statements but cannot get it to respond when the push button is pressed.

It? What is it?

Post some code, and a description of, a schematic of, or a picture of (or all three) how the switch is connected.

This could be a hardware problem (switch not connected correctly, no pull-up or pull-down resistor, etc.) or a software problem.

/*
 *  SMS with GSM Playground - GSM Shield for Arduino
 *  Released under the Creative Commons Attribution-Share Alike 3.0 License
 *  http://www.creativecommons.org/licenses/by-sa/3.0/
 *  www.hwkitchen.com
 */


/*
  Important:
  ==========
  This sketch step by step reads and erases all SMSs from your SIM
  card so if there are some important SMSs stored in your
  SIM card please backup them up before inserting SIM card
  to the GSM Playground
*/
int ledPin = 13;
int ledPin2 = 12;
int ledPin3 = 11;
#include "GSM.h"  

// max length for SMS buffer(including also string terminator 0x00)
// here SMS can have max. 99 characters (1 character is reserved for
// string termination 0x00)
#define SMS_MAX_LEN 100

// definition of instance of GSM class
GSM gsm;




int pos = 0;

// variables used for timing
unsigned long   previous_timer;
byte timer100msec;

int val;
char string[30];
char position;          
char phone_number[20];      // array for the phone number string
char sms_text[SMS_MAX_LEN]; // array for the SMS text
char *ch;                   // pointer to the character


void setup()
{
  pinMode (ledPin, OUTPUT);
  pinMode (ledPin2, OUTPUT);
  pinMode (ledPin3, OUTPUT);
  // initialization of serial line
  gsm.InitSerLine(115200);     
  // turn on GSM module
  gsm.TurnOn();
  // set direction for GPIO pins
  gsm.SetGPIODir(GPIO10, GPIO_DIR_OUT);
  gsm.SetGPIODir(GPIO11, GPIO_DIR_OUT);
  
  // periodic timer initialization
  timer100msec = 0;
  previous_timer = millis();
  // we are not registered so far => disable button
  gsm.DisableUserButton();

}

void loop()
{
  // -------------------
  // timing of main loop
  // -------------------
  if ((unsigned long)(millis() - previous_timer) >= 100) { 
    previous_timer = millis();  

    //*******************************
    //****** EVERY 100msec. *********
    //*******************************
    if (gsm.IsUserButtonEnable() && gsm.IsUserButtonPushed()) {
      // operation with the user button is enabled and user button
      // is pushed => send SMS
      // and disable user button until SMS is not sent 
      gsm.DisableUserButton();
      gsm.TurnOffLED();

      // read temperature
      val = gsm.GetTemp();
      if (val > -1000) {
        // temperature is OK -> send SMS to the specified 
        // phone number
        // ----------------------------------------------
        
        // prepare a string which will be send by the SMS:
        // "Temperature: 25 C"  
        sprintf(string, "Temperature: %i C", val/10);

        // in case you want to send SMS to the specific number
        // change 123456789 to your phone number
        // gsm.SendSMS("123456789", string); 

        // in case you want to send SMS to the specific SIM phonebook position
        // here we send to the first SIM phonebook position
        gsm.SendSMS(1, string);
      }
    }
    
    //*******************************
    //****** EVERY 200msec. *********
    // %2 means every 200 msec.
    // +1 means - 100msec. "before" a previous 100msec. action
    // so the processor power is better spreaded
    //  
    // in case +1 is not used but only: if (timer100msec % 2 == 0)  
    // then this action will also executed every 200msec.
    // but previous EVERY 100msec. and this EVERY 200msec.
    // is executed in the same 100msec. point so the processor
    // time is not used so effectively
    //*******************************
    if ((timer100msec+1) % 2 == 0) {
      // here it is possible to place your code which will be executed
      // each 200 msec.
      // ---------------------------------------------------------
    }
    
    //*******************************
    //****** EVERY 500msec. *********
    // %5 means every 500 msec.
    // +2 means - 200msec. "before" a first 100msec. action
    // so the processor power is better spreaded
    //*******************************
    if ((timer100msec+2) % 5 == 0) {
      // here it is possible to place your code which will be executed
      // each 500 msec.
      // ---------------------------------------------------------
    }
    

    //*******************************
    //****** EVERY 1 sec. ***********
    // %10 means every 1000 msec. = 1sec.
    //*******************************
    if ((timer100msec+3) % 10 == 0) {

      // is the GSM module registered?
      // -----------------------------
      gsm.CheckRegistration();
      if (gsm.IsRegistered()) {

        // GSM modul is still registered
        // -----------------------------
        gsm.EnableUserButton();
        gsm.TurnOnLED();
      }
      else {
        // not registered - so disable button
        // ----------------------------------
        gsm.DisableUserButton();
        gsm.TurnOffLED();
      }
    }


    //*******************************
    //****** EVERY 3 sec. ***********
    // %30 means every 3000 msec. = 3sec.
    //*******************************
    if ((timer100msec+4) % 30 == 0) {

      // is there a new UNREAD SMS ?
      // if YES - SIM position > 0 is returned
      // -------------------------------------
      if (gsm.IsRegistered()) {
        // GSM module is registered

        // Note: if there is new SMS before IsSMSPresent() is executed
        // this SMS has a status UNREAD
        // after calling IsSMSPresent() method status of SMS
        // is automatically changed to READ
   
        position = gsm.IsSMSPresent(SMS_ALL);
        if (position > 0) {
          // we have new SMS 
          // now we will make authorization with SIM phonebook pos. 1,2,3
          // ------------------------------------------------------------
          if (GETSMS_AUTH_SMS == gsm.GetAuthorizedSMS(position, phone_number, sms_text, SMS_MAX_LEN,
                                                      0, 0)) {

            // SMS comes from authorized phone number 
            // so lets check SMS text
            // --------------------------------------

            // 1) e.g. text "Temp?"
            // --------------------
            ch = strstr(sms_text, "Happy Birthday");
            if (ch != NULL) {
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            }
            ch = strstr(sms_text, "Hello");
            if (ch != NULL) {
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            }
            ch = strstr(sms_text, "Hello again");
            if (ch != NULL) {
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            }
             
             
             
             gsm.DeleteSMS(position);            
            
                     
           loop (); 
             
            }
           }
        }            
                    
          
         


          // and delete received SMS 
          // to leave place for next new SMS's
          // ---------------------------------
          gsm.DeleteSMS(position);
      
       
  }
    }
  
    
        


    
    
    
    //********************************************
    //********WRAP AROUND COUNTER 10 sec. ********
    //********************************************
    timer100msec = (timer100msec + 1) % 100;
    }

This is essentially the code I have created that I am starting with. I have the switch connected correctly, tested with the Digital Read Serial code. I want simply to set the LED to LOW when a LOW is read from a push button switch, and repeated within each 'if' statement that reads the different SMS messages.

The push button is going into Pin 2, and will change state when the lid of a box is lifted, which is when I want the LED from Pin 13 to be switched off until the correct text message is sent again.

Thanks for your help

Rosanna

In my site www.open-electronics.org you can find a shield using a GSM module and some example. There is a simple library to use it. The library come from HWKitchen library

OpenElectronics: In my site www.open-electronics.org you can find a shield using a GSM module and some example. There is a simple library to use it. The library come from HWKitchen library

i'm using newSoftSerial library and i'm going no where. I'm using Arduino ATmega8 board amd SIM300 GSM modem,

Connections: 1) GSM modems Tx --> pin 2 on Arduino 2) GSM modems Rx --> pin 3 on Arduino

i even changed the connections of Rx an TX, no result.

modem is working fine when i use HyperTerminal(MS) , but i'm not able to communicate GSM modem through Arduino board. Need help.

Hello, Just a simple question. Can you get communicate with module? I mean, when you dial the module, can you receive RING string accuratelly? and can you hang up the phone with atd command via Arduino? reha

Yes off course you can control the module with the GSM library http://www.open-electronics.org/arduino-gsm-shield/

Rosanna,

there is a related tutorial beginning at http://tronixstuff.wordpress.com/2011/01/19/tutorial-arduino-and-gsm-cellular-part-one/