Pir gsm alarm


hello everybody
i have problem in arduino code gsm module not receiving msg make alarm project complete... if me.

code: [select]

#include<softwareserial.h>
softwareserial myserial(8, 9);//pin 9,10 used rx , tx
int ledpin = 13;                // choose pin led
int inputpin = 2;               // choose input pin (for pir sensor)
int pirstate = low;             // start, assuming no motion detected
int val = 0;                    // variable reading pin status
int pinspeaker = 10;           //set speaker on pwm pin (digital 9, 10, or 11)
int sms_count=0;
void setup() {
  pinmode(ledpin, output);      // declare led output
  pinmode(inputpin, input);     // declare sensor input
  pinmode(pinspeaker, output);
  myserial.begin(9600);
  serial.begin(9600);
}

void loop(){
 
  val = digitalread(inputpin);  // read input value
  if (val == high) {            // check if input high
    digitalwrite(ledpin, high);  // turn led on
    playtone(300, 160);
    delay(150);
  while(sms_count<2) //number of sms alerts sent limited @ 2
    { 
      sendtextmessage(); // function send @ commands gsm module
    }
   
    if (pirstate == low) {
      // have turned on
   
      // want print on output change, not state
      pirstate = high;
    }
  } else {
      digitalwrite(ledpin, low); // turn led off
      playtone(0, 0);
      delay(300);   
      if (pirstate == high){
      // have turned of
     
      // want print on output change, not state
      pirstate = low;
    }
  }
}
void sendtextmessage()
{
  myserial.println("at+cmgf=1");    //to send sms in text mode
  delay(1000);
  myserial.println("at+cmgs=\"+212642543498\"\r"); //phone no
  delay(1000);
  myserial.println("quelqu'un dans la maison");//content of message
  delay(200);
  myserial.println((char)26);//stopping character
  delay(500);
  sms_count++;
}
// duration in msecs, frequency in hertz
void playtone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalwrite(pinspeaker,high);
        delaymicroseconds(period / 2);
        digitalwrite(pinspeaker, low);
        delaymicroseconds(period / 2);
        elapsed_time += (period);
    }
}

softwareserial myserial(8, 9);//pin 9,10 used rx , tx
seems either stupid comment or bug...


that send twice in row  because of while
code: [select]
  while(sms_count<2) //number of sms alerts sent limited @ 2
    { 
      sendtextmessage(); // function send @ commands gsm module
    }



code: [select]
  myserial.println("at+cmgf=1");    //to send sms in text mode
  delay(1000);
  myserial.println("at+cmgs=\"+212642543498\"\r"); //phone no
  delay(1000);
  myserial.println("quelqu'un dans la maison");//content of message
  delay(200);
  myserial.println((char)26);//stopping character

remember println() add \r\n @ end of printed (so double check means at+cmgs

you should use write instead of println send ctrl-z


this code
code: [select]
    int period = (1.0 / freq) * 1000000;would better written as
code: [select]
    int period = (1000000 / freq); , int might not appropriate representing result



--- please follow forum rules, read messages @ top of forum ---
please correct post above , add code tags around code:
[code] // code here [/code].

it should this:
code: [select]
// code here
(also press ctrl-t (pc) or cmd-t (mac) in ide before copying indent code properly)



Arduino Forum > Using Arduino > Programming Questions > Pir gsm alarm


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???