GSM shield repeatedly sends sms...


gsm shield repeatedly sends sms.
how make send 1 sms when buttonstate high?
thank you.


here's code.
code: [select]
char rx_data[50];
unsigned char rx_index = 0;
int = 0;
char msg[160];
int sig;
const int buttonpin = 2;
const int buttonpin1 = 4;
const int buttonpin2 = 6;
const int ledpin = 12;// number of pushbutton pin
const int ledpin1 = 13;
const int ledpin2 = 11;
const int buzzerpin = 8;
// number of led pin

// variables change:
int buttonstate = 0;
int buttonstate2 = 0;// variable reading pushbutton status
int buttonstate3 = 0;

void setup() {
  serial.begin(38400);
  // initialize led pin output:
  pinmode(ledpin, output);  
  pinmode(ledpin1, output);
  pinmode(ledpin2, output);
  pinmode(buzzerpin, output);  
  // initialize pushbutton pin input:
  pinmode(buttonpin, input_pullup);
  pinmode(buttonpin1, input_pullup);
  pinmode(buttonpin2, input_pullup);  
}

void loop(){
  // read state of pushbutton value:
  buttonstate = digitalread(buttonpin);

  // check if pushbutton pressed.
  // if is, buttonstate high:
  if (buttonstate == high  && buttonstate2 == low) {    
    // turn led on:    
    digitalwrite(ledpin, high);
    sendtextmessage();
    serial.println("alert level 1!");
delay(150);


  }
  else {
    // turn led off:
    digitalwrite(ledpin, low);
  }
  buttonstate2 = digitalread(buttonpin1);
  if (buttonstate2 == high  && buttonstate3 == low) {    
    // turn led on:    
    digitalwrite(ledpin1, high);
    sendtextmessage();
  serial.println("alert level 2!");  
delay(150);  
}
  else {
    // turn led off:
  
    digitalwrite(ledpin1, low);
  }
  buttonstate3 = digitalread(buttonpin2);
  if (buttonstate3 == high) {    
    // turn led on:    
    digitalwrite(ledpin2, high);
    digitalwrite(buzzerpin, high);
    sendtextmessage();
  serial.println("alert level 3!");  
 delay(150);
  }
  else {
    // turn led off:
  
    digitalwrite(ledpin2, low);
    digitalwrite(buzzerpin, low);
  }
}
//**********************************************************
void sendtextmessage()
{
 serial.print("at+cmgf=1\r");
 delay(100);
 serial.println("at + cmgs = \"09108690901\"");
 delay(100);
 serial.println("warning!");
 delay(100);
 serial.println((char)26);
 delay(100);
 serial.println();
}

up


Arduino Forum > Using Arduino > Programming Questions > GSM shield repeatedly sends sms...


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code