0

I have built a system to identify motions and fire alerts. System can send a SMS in case if it's identify such alerts.

System consist of two parts,

Part 1: Armed and Disarmed using a PIN (Using Arduino Uno)

This Module Consists with 4*4 PIN PAD, I2C Module, 2 LEDs and Arduino UNO This part works fine

Part 2: Sensor Systems and SMS System

This module consists of Arduino NANO, MQ135 Gas Sensor, PIR Sensor, SIM 800L Module, Tamper Switches This part also works, but in every 55 minutes it generates a false motion alert and I could not troubleshoot the issue.

Schematics is attachedSchematics.

Codes as Below,

Part 1: Test6-LCD_Intigrated_Working_Temper.ino

#include <Keypad.h>
#include<EEPROM.h>
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
char password[4];
char pass[4],pass1[4];
int i=0;
int k=0;
char customKey=0;
byte col = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};


byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {13, 12, 11, 10}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
void setup()
{
  lcd.begin();

  Serial.begin(9600);
  pinMode(4, INPUT);      // Tamper Signal
  pinMode(3, OUTPUT); //Armed 
  pinMode(2, OUTPUT); //Disarmed

  lcd.setCursor(0, 0);
  lcd.print ("--SECURE ROOM!--");
  Serial.print("Server Room");
  lcd.setCursor(0, 1);
  lcd.print ("PLEASE ENTER PIN");
  Serial.print("\n*********Keypad Lock********* ");
  delay(2000);
  Serial.println("\n*********Enter Ur Passkey:*********");

  for(int j=0;j<4;j++)
    EEPROM.write(j, j+49);
  for(int j=0;j<4;j++)
    pass[j]=EEPROM.read(j);
}

void Armed(){

  digitalWrite(3, HIGH);
  digitalWrite(2, LOW);
  Serial.println("\n***System is Armed***");
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("--SYSTEM ARMED--");
  lcd.setCursor(0, 1);
  lcd.print("-SENSORS ACTIVE-");
  delay (2000);
  lcd.noBacklight();
  i=0;
  customKey=0;

  }

void change()
{
  int j=0;
 lcd.backlight();
  Serial.println("\n*********UR Current Passk*********");
  lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print("   CURRENT PIN   ");

  while(j<4)
  {
    char key=customKeypad.getKey();
    if(key)
    {
      pass1[j++]=key;

      Serial.print(key);
      lcd.setCursor(j+6, 1);
      lcd.print(key);


    }
    key=0;
  }
  delay(500);

  if((strncmp(pass1, pass, 4)))
  {


    Serial.println("\n*********Wrong Passkey*********");
    lcd.clear(); 
    lcd.setCursor(0, 0);
      lcd.print("  UNAUTHORIZED  ");

    Serial.println("\n*********UNAuthorized Access*********");
      lcd.setCursor(0, 1);
      lcd.print(" ACCESS  DENIED ");
    delay(10000);
  }
  else
  {
    j=0;


    Serial.println("\n*********Enter New Passk: *********");
      lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print(" ENTER NEW PIN! ");

    while(j<4)
    {
      char key=customKeypad.getKey();
      if(key)
      {
        pass[j]=key;

        Serial.print("*");
        EEPROM.write(j,key);
        lcd.setCursor(j+6, 1);
        lcd.print(key);
        j++;

      }
    }

    Serial.println("*********Done*********");
    lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print("----UPDATED!----");
    delay(1000);
  }


  Serial.println("\n*********Enter Ur Passk: *********");
  lcd.clear(); 

      lcd.setCursor(2, 0);
      lcd.print ("SECURE ROOM!");
      lcd.setCursor(0, 1);
      lcd.print ("PLEASE ENTER PIN");
      lcd.noBacklight();
  customKey=0;
}


void tamper(){
  Serial.println("\n***System is Tampered***");
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("--TAMPERED--");
  lcd.setCursor(0, 1);
  lcd.print("WARN COMPROMISED");
  delay (2000);
  lcd.backlight();
  i=0;
  customKey=0;

  }

void loop()
{ 
  Serial.println(digitalRead(4));
  customKey = customKeypad.getKey();
  if(customKey=='A')
    Armed();

    if(customKey=='C')
    change();
   /* 
    if(digitalRead(4)==LOW)
    tamper();
 */
  if (customKey)
  {
    lcd.backlight();
    password[i++]=customKey;

    Serial.print("*");
    lcd.setCursor(0, 0);
    lcd.print("    PIN INPUT    ");
    lcd.setCursor(0,1);
    lcd.print("       ----     ") ;
    lcd.setCursor(i+6, 1);
    lcd.print("*");


      }




  if(i==4)
  {
    delay(200);
    for(int j=0;j<4;j++)
      pass[j]=EEPROM.read(j);
    if(!(strncmp(password, pass,4)))
    {

      Serial.println("\n*********Passkey Accepted*********");
    lcd.clear(); 
    lcd.setCursor(0, 0);
    lcd.print("---AUTHORIZED---");
    lcd.setCursor(0, 1);
    lcd.print("SYSTEM  DISARMED");

      delay(1000);
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      i=0;

    }
    else
    {

      Serial.println("\n*********Access Denied*********");
      lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print("  UNAUTHORIZED  ");
      lcd.setCursor(0, 1);
      lcd.print(" ACCESS  DENIED ");

      delay (5000);

      Serial.println("\n*********Enter Passkey: *********");
      lcd.clear(); 
      lcd.setCursor(0, 0);
      lcd.print ("--SECURE ROOM!--");
      lcd.setCursor(0, 1);
      lcd.print ("PLEASE ENTER PIN");
      lcd.noBacklight();

      i=0;

    }
  }
}

Part 2: Test7_Tested_Tamper_Smoke_PIR_GSM.ino.ino

/*
    Arduino with PIR motion sensor and MQ 135 Smoke Detector with SMS Alert
    Developed By Vinod Amarathunga 18.09.2019
    DMS Electronics (Pvt) Ltd
*/


#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 5); //SIM800L Rx Tx
char msg;
String textMessage;

int smokeA0 = A0;            // MQ135 Analog Input
int led = 13;                // the pin that the LED is atteched to
int priState = LOW;             // by default, no motion detected
int TampSignal = 11;       // Tamper 5V Signal
int sensorThres = 150; //Smoke Air Quality Threshold
int pretamper = LOW;
bool premotion = false;
bool prefire = false;

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(3, INPUT);    // initialize sensor as an input
  pinMode(TampSignal, OUTPUT); // Tamper Drive Signal as Output
  pinMode(10, INPUT);    // Tamper Alert
  Serial.begin(9600);        // initialize serial
  mySerial.begin(9600);
}


void SmokeSMS()
{
  Serial.println("Warning!! Secure Room Fire Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+xx\"\r");
  delay(1000);
  mySerial.println("Warning!! Secure Room Fire Detected");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  delay(5000);

  Serial.println("Warning!! Secure Room Fire Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+xx2\"\r");
  delay(1000);
  mySerial.println("Warning!! Secure Room Fire Detected");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

}

void MotionSMS()
{
  Serial.println("Warning!! Secure Room Motion Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"xx\"\r");
  delay(1000);
  mySerial.println("PIN 3 HIGH");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  delay(5000);
/*
  Serial.println("Warning!! Secure Room Motion Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"xx2\"\r");
  delay(1000);
  mySerial.println("Warning!! Secure Room Motion Detected");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");
*/

}

void TamperSMS()
{


  Serial.println("Warning!! System Tamper Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"xx2\"\r");
  delay(1000);
  mySerial.println("Warning!! System Tamper Detected");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  delay(5000);

  Serial.println("Warning!! System Tamper Detected");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"xx\"\r");
  delay(1000);
  mySerial.println("Warning!! System Tamper Detected");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

}


void loop() {
  int analogSensor = analogRead(smokeA0);
  digitalWrite(TampSignal, HIGH); // Drive Signal Always High
  //val = digitalRead(3);   // read sensor value
  //  ReceiveMessage(); //System Recive Messages
  //Serial.print("Smoke Level:");
  //Serial.println(analogSensor);
  Serial.println(digitalRead(3));
  if (analogSensor > sensorThres  ) {           // check if the sensor is HIGH and Armed Status
    digitalWrite(led, HIGH);   // turn LED ON
    Serial.print("\nSmoke Alert....!!!");
    SmokeSMS(); // Smoke SMS Alert
    delay(100);                // delay 100 milliseconds

  }

  else if ( priState == LOW && digitalRead(3) == HIGH && digitalRead(7) == HIGH ) {

    digitalWrite(led, HIGH);   // turn LED ON
    Serial.println("Motion detected!");
    MotionSMS(); //Motion SMS
    priState = HIGH; // Previous Motion Status set to High

    delay(15000);


  }


  else if ( digitalRead(7) == HIGH && digitalRead(10) == LOW )
  {

    digitalWrite(led, HIGH);   // turn LED ON and Temper Alarm On
    Serial.println("One of the TIP Switches being Trigered");
    if ( pretamper == LOW ) {
      TamperSMS(); // Tamper SMS
      pretamper  = HIGH;
      delay(15000);
    }

  }



  else {
    digitalWrite(led, LOW); // turn LED OFF
    digitalWrite(11, HIGH); // Tamper Signal
    delay(200);             // delay 200 milliseconds
    pretamper = LOW;
    //Serial.print("\n.....Normal.....");

    if (priState == HIGH) {
      Serial.println("Motion stopped!");
      priState = LOW;       // update variable state to LOW

    }
  }

}

I am loosing my mind because I could not find the problem of getting false alert in every 55 minutes.

I am very grateful any one can help.

  • I see nothing in the code that could cause a signal exactly every 55 minutes. -- Is it possible to detach the motion sensor from the NANO, to try out if the signal also appears stand alone. Eventually you attach the Data output of the sensor to a bi stable flip flop, that drives an LED. To find out if the motion detector triggers e.g a test signal every 55 minutes. You could also try to hide the sensor from ambient light. Perhaps there is a light source that flashes IR light every 55 minutes and interferes with the sensor in any way. – Peter Paul Kiefer Nov 4 at 8:33
  • Hi @PeterPaulKiefer, Thanks. Actually there is no light emits in every 55 minute. I am testing it in a closed box. I am going to try it in a stand alone as suggested. But I am in a doubt hot to get the alert to inspect – Vinod Amarathunga Nov 4 at 9:03
  • If you still get no findings then, it would be helpful to see the Serial print outs of at least two different test runs. i.e power the alarm system wait 3 x 55 minutes (so the false trigger happens 3 times). Switch the power off wait 30 minutes and do the same again. The output must contain timestamps. That 55 minutes interval is really strange. I would be interesting if these are relative intervals or absolute time points, hence the second test run. – Peter Paul Kiefer Nov 4 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.