bangnaga

Arduino SMS PIR

Oct 10th, 2014
359
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. int ledPin = 13;                // choose the pin for the LED
  3. int inputPin = 6;               // choose the input pin (for PIR sensor)
  4. int pirState = LOW;             // we start, assuming no motion detected
  5. int val = 0;                    // variable for reading the pin status
  6.  
  7.  
  8. #include "SIM900.h"
  9. #include "sms.h"
  10. #include "SoftwareSerial.h"
  11. #include "sms.h"
  12. SMSGSM sms;
  13. int a = 12;    
  14. boolean started=false;
  15. char smsbuffer[160];
  16. char n[20];
  17.  
  18.  
  19. void setup()
  20. {
  21.   pinMode(ledPin, OUTPUT);      // declare LED as output
  22.   pinMode(inputPin, INPUT);     // declare sensor as input
  23.  
  24.  
  25.   pinMode(a,OUTPUT);
  26.  
  27.   Serial.begin(19200);
  28.  
  29.   if (gsm.begin(2400)){
  30.     started=true;
  31.   }
  32.   if(started){
  33.     delsms();
  34.   }
  35.  
  36. };
  37.  
  38. void loop()
  39. {
  40.  val = digitalRead(inputPin);  // Baca Digital Input Dari Sensor PIR
  41.   if (val == HIGH) {            // Jika Nilainya High
  42.     digitalWrite(ledPin, HIGH);  // Nyalakan Led
  43.     if (pirState == LOW) {
  44.       Serial.println("Motion detected!");
  45.         if (sms.SendSMS("+6285299944232", "Ada Orang Terdeteksi"))
  46.         Serial.println("\nSMS sent OK");
  47.       pirState = HIGH;
  48.       delay(2000);
  49.     }
  50.   } else {
  51.     digitalWrite(ledPin, LOW); // turn LED OFF
  52.     if (pirState == HIGH){
  53.       // we have just turned of
  54.       Serial.println("Motion ended!");
  55.        digitalWrite(a,HIGH);
  56.       pirState = LOW;
  57.     }
  58.   }
  59.    if (gsm.begin(2400)){
  60.     started=true;
  61.   }
  62.   int pos=0;
  63.   if(started){
  64.     pos=sms.IsSMSPresent(SMS_ALL);
  65.     if(pos){
  66.       Serial.println("Ada Sms Masuk di no ");
  67.       Serial.println(pos);
  68.       sms.GetSMS(pos,n,smsbuffer,100);
  69.         Serial.println(n);
  70.         Serial.println(smsbuffer);
  71.         delay(2000);
  72.         if(!strcmp(smsbuffer,"alarmoff")){
  73.           digitalWrite(a,LOW);
  74.           sms.SendSMS(n,"Alarm sudah padam");
  75.           Serial.println ("membalas respon");
  76.         }    
  77.         delsms();
  78.  
  79.     }
  80.   }
  81. };
  82.  
  83. void delsms(){
  84.   for (int i=0; i<10; i++){  
  85.       int pos=sms.IsSMSPresent(SMS_ALL);
  86.       if (pos!=0){
  87.         Serial.println ("Hapus SMS");  
  88.         if (sms.DeleteSMS(pos)==1){  
  89.         }
  90.         else
  91.         {
  92.            //ga bisa delete biasanya lampu gsm mati.. pencet tombol reset micro di gsm
  93.         }
  94.       }
  95.     }
  96.  
  97. }
RAW Paste Data