Double_G

GSM garage door opener (Siemens TC35i + Arduiono mini pro)

Jun 22nd, 2018
278
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None
  1. #include <SoftwareSerial.h>                     //Including Sotware Serial lib for second serial port to connect Siemens TC35i
  2.  
  3. String tel_1 = "+11221234567";                  //Telephone number 1
  4. String tel_2 = "+11227654321";                  //Telephone number 2
  5.  
  6. String temp;                                    //Define temp string
  7.  
  8. int rxpin = 9;                                  //Define rx and tx pin
  9. int txpin = 8;
  10.  
  11. byte door = 10;                                 //Relay output
  12.  
  13. SoftwareSerial serial2(rxpin,txpin);            //RX,TX
  14.  
  15. void setup() {
  16.  
  17.     pinMode(door, OUTPUT);                      //Set relay port to output
  18.     digitalWrite(door, HIGH);                   //Set relay port to high (switch relay default state)
  19.  
  20.     Serial.begin(115200);                       //Initialize HW serial port for debug
  21.     serial2.begin(57600);                       //Initialize SW serial port for communicat with modem
  22.  
  23.     Serial.println("Starting....");             //Program starting
  24.  
  25.     delay(120000);                              //Waiting for modem (120sec is enough)
  26.     serial2.println("at");                      //Send AT Command
  27.     Serial.println("at");
  28.     temp = serial2.readString();
  29.     Serial.print(temp);
  30.     delay(1000);
  31.  
  32.     Serial.println("at+clip=1");                //Send AT Command to receiving caller ID
  33.     serial2.println("at+clip=1");
  34.     temp = serial2.readString();
  35.     Serial.println(temp);
  36.     delay(1000);
  37.  
  38.   Serial.println("Enter to loop...");           //Loop is stating...
  39.  
  40. }
  41.  
  42. void loop() {
  43.  
  44.       digitalWrite(door, HIGH);                 //Set relay outpout to high (relay normal state)
  45.  
  46.     if (serial2.available()) {                  //Wait for SW Serial communication is active
  47.         String str = serial2.readString();      //Read out full string from SW serial
  48.         temp = (str.substring(18,30));          //Parser out from onyl Caller ID
  49.         Serial.println(str.substring(18,30));   //Show Caller ID (only ID, without any text. Example: RING ect..
  50.      
  51.      
  52.      if (temp == tel_1)                         //Find caller id in database
  53.      {
  54.         Serial.println("Telephone number 1");   //Print caller id in debug port
  55.         serial2.println("AT H");                //Hang up the call/ring    
  56.     dooropen();                                 //Open the door
  57.      }
  58.      
  59.      if (temp == tel_2)                         //Find caller id in database
  60.      {
  61.         Serial.println("Telephone number 2");   //Print caller id in debug port
  62.         serial2.println("AT H");                //Hang up the call/ring  
  63.     dooropen();                                 //Open the door
  64.      }
  65.  
  66.    
  67.      else {
  68.         Serial.println("Unknow number door sill locked"); //Print to debug port
  69.         serial2.println("AT H");                //Hang up the call/ring  
  70.         temp = serial2.readString();            //Eliminate "OK" feedback to AT H command
  71.        
  72.      }
  73.  
  74.    }
  75.  
  76. }
  77.  
  78. void dooropen()
  79. {
  80.   Serial.println("Opening the door");           //Print to debug port
  81.   digitalWrite(door, LOW);                      //Set relay output LOW, activate the relay
  82.   delay(1000);                                  //Wait 1 sec
  83.   digitalWrite(door, HIGH);                     //Set relay output HIGH, relay normal state
  84. }
RAW Paste Data Copied