GSM Kontrol

SMS ile Ev Otomasyonu

SMS ile Otomasyon

SMS Gönder

/*
www.gsmkontrol.com
D11 Buton 1 
D12 Buton 2 
D13 Buton 3 
Buton pinleri Normalde HIGH, Butona basılınca LOW 

Belirlenen numaraya sms gönderir.

D8  Röle 1
D9  Röle 2
D10 Röle 3

Röle 1'i  açmak için R1A, Kapatmak için R1K
Röle 2'yi açmak için R2A, Kapatmak için R2K
Röle 3'ü  açmak için R3A, Kapatmak için R3K
*/

#include <GSM.h>
#define PINNUMBER ""   //Pin numarası aktifse "1234" şeklinde yazın. Aktif değilse aynen kalabilir
GSM3ShieldV1DirectModemProvider modemAccess;

GSM gsm;
GSM_SMS sms;
char remoteNum[20] = "0542*******";   // SMS Gönderilecek numara 
String y;
int i=0;

#define RELAY1 8
#define RELAY2 9
#define RELAY3 10

#define BUTON1 11
#define BUTON2 12
#define BUTON3 13

int BUTON1_Durum, BUTON2_Durum, BUTON3_Durum;
int BUTON1_Sayac=0, BUTON2_Sayac=0, BUTON3_Sayac=0;

void SEND_SMS(char metin[200]) 
{
  sms.beginSMS(remoteNum);
  sms.print(metin);
  sms.endSMS();
  delay(1000);              // Sonraki sms e kadar bekleme süresi
}

void SMS_OKU ()
{ 
 char c; 
  if (sms.available())
  {
    c = sms.read();
    if(c == 'R')
      { 
       c = sms.read();
       
//*********Röle 1 Aç/Kapat***********
        if(c == '1')
          {
            if(sms.peek() == 'A')
              {
                digitalWrite(RELAY1, LOW);
                SEND_SMS("ROLE 1 ACILDI");
              }
            if(sms.peek() == 'K')
              {
                digitalWrite(RELAY1, HIGH);
                SEND_SMS("ROLE 1 KAPATILDI");
              }
            sms.flush();
          }
          
//*********RELAY2 Aç/Kapat***********   
         if(c == '2')
           {
            if(sms.peek() == 'A')
              {
                digitalWrite(RELAY2, LOW);
                SEND_SMS("ROLE 2 ACILDI");
              }
            if(sms.peek() == 'K')
              {
                digitalWrite(RELAY2, HIGH);
                SEND_SMS("ROLE 2 KAPATILDI");
              }
            sms.flush();
          }
          
//*********RELAY3 Aç/Kapat***********
         if(c == '3')
           {
            if(sms.peek() == 'A')
              {
                digitalWrite(RELAY3, LOW);
                SEND_SMS("ROLE 3 ACILDI");
              }
            if(sms.peek() == 'K')
              {
                digitalWrite(RELAY3, HIGH);
                SEND_SMS("ROLE 3 KAPATILDI");
              }
            sms.flush();
          }
          
        sms.flush();
      }
  }
}

void setup()
{
  pinMode(BUTON1,INPUT_PULLUP);    
  pinMode(BUTON2,INPUT_PULLUP);    
  pinMode(BUTON3,INPUT_PULLUP);     
  pinMode(RELAY1,OUTPUT);   
  pinMode(RELAY2,OUTPUT);    
  pinMode(RELAY3,OUTPUT);
  digitalWrite(RELAY1, HIGH);
  digitalWrite(RELAY2, HIGH);
  digitalWrite(RELAY3, HIGH);  
  gsm.begin();  //Modemi aç 
  delay(1000);
  sms.print("AT+QMGDA=\""); 
  delay(5);
  sms.println("DEL ALL\"");
  delay(3000);
  SEND_SMS("SISTEM BASLATILDI");
  delay(1000);
}

void loop()
{
      SMS_OKU();
      delay(100);
      
    //********BUTON1 Sensörü***********
       BUTON1_Durum = digitalRead(BUTON1);
       if (BUTON1_Durum == LOW && BUTON1_Sayac == 0)   
           {
             delay(100);
             if (BUTON1_Durum == LOW)
             {
               BUTON1_Sayac=1;
               SEND_SMS("DIKKAT: BUTON 1'E BASILDI");
             }
           }
           else if(BUTON1_Durum == HIGH)
                   BUTON1_Sayac=0;
                   
    //*********BUTON2 Sensörü*********              
       BUTON2_Durum = digitalRead(BUTON2);
       if (BUTON2_Durum == LOW && BUTON2_Sayac == 0)     
           {
             delay(100);
             if (BUTON2_Durum == LOW)
             {
               BUTON2_Sayac=1;
               SEND_SMS("DIKKAT: BUTON 2'YE BASILDI");
             }
           }
           else if(BUTON2_Durum == HIGH)
                   BUTON2_Sayac=0;
    
    //**********Kapı Sensörü**********              
       BUTON3_Durum = digitalRead(BUTON3);
       if (BUTON3_Durum == LOW && BUTON3_Sayac == 0)   
           {
             delay(100);
             if (BUTON3_Durum == LOW)
             {
               BUTON3_Sayac=1;
               SEND_SMS("DIKKAT: BUTON 3'E BASILDI");
             }
           }
           else if(BUTON3_Durum == HIGH)
                   BUTON3_Sayac=0;
}