Zabezpečovací systém přidání deaktivace

Ahoj, našel jsem si na netu zabezpečovačku řešenou pomocí Arduina a modulu SIM800L. Ale chybí mi tam jedna docela důležitá věc, a to deaktivace. Napadlo mě změnit kód tak aby po detekci otevřených dveří nebo detekci pohybu byl ještě čas cca 15s so doby než se odešle sms. Po tu dobu by se dal systém deaktivovat na klávesnici číselným kódem a potvrzením #. Ještě by mohly být zahrnuty dvě ledky z nichž jedna by signalizovala že je systém aktivní a druhá že je systém neaktivní. A následně zase aktivovat při odchodu se stejným časovým odstupem. Byl by prosím někdo tak ochotný a upravil mi kód tak aby fungoval podle mých představ? Děkuji mnohokrát
Zde je odkaz na projekt
https://www.engineersgarage.com/arduino ... ed-switch/

Přesunul jsem vaše téma do příslušné kategorie fóra @alexandrmusil94.

V budoucnu si prosím věnujte čas a vyberte kategorii fóra, která nejlépe odpovídá předmětu vašeho tématu. V horní části každé kategorie je téma „About the _____ category", které vysvětluje její účel.

Toto je důležitá součást zodpovědného používání fóra, jak je vysvětleno v příručce „How to get the best out of this forum" guide. Průvodce obsahuje spoustu dalších užitečných informací. Prosím přečtěte si to.

Předem děkujeme za spolupráci.

Please use something like google translate:

This would be a poor solution because it uses delay(); a solution with a millis() based timing and a finite statemachine will be better (I just don't have the time now).

void loop()
{
  int S1 = 0, S2 = 0;
  S1 = digitalRead(Door);
  S2 = digitalRead(Out);

  static bool triggered = false;

  if(triggered == false && S1 == HIGH && S2 == LOW)
  {
    triggered = true;
  }

  if(triggered == true)
  {
    delay(15000);
    if(S1 == HIGH && S2 == LOW)
    {
      // send sms
    }
    triggered = false;
  }
}

You will need to decide under which conditions triggered needs to be cleared again (set to false).

I tried to modify the code according to my requirements.
Please check.

#include <Keypad.h>

const byte ROWS = 4; // Define the number of rows on the keypad
const byte COLS = 3; // Define the number of columns on the keypad
char keys[ROWS][COLS] = { // Matrix defining character to return for each key
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pins (R0-R3) of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pins (C0-C2) of the keypad
//initialize an instance of class
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int Door = 9;   //Door contact sensor pin connected to digital pin-9 of arduino
const int PIR = 10;   //PIR output pin connected to digital pin-10 of arduino 
const int LED_Active = 11; // Pin for active LED
const int LED_Inactive = 12; // Pin for inactive LED
const unsigned long activationDelay = 15000; // 15 seconds in milliseconds

bool systemActive = true;
unsigned long lastActivationTime = 0;

void setup() {
  pinMode(Door, INPUT);  // Door contact sensor as input  
  pinMode(PIR, INPUT);   // PIR motion sensor as input
  pinMode(LED_Active, OUTPUT); // Active LED pin as output
  pinMode(LED_Inactive, OUTPUT); // Inactive LED pin as output
  
  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  unsigned long currentTime = millis();

  // Read sensors
  int doorState = digitalRead(Door);
  int motionState = digitalRead(PIR);

  // Check if the system should be activated
  if (!systemActive && currentTime - lastActivationTime >= activationDelay) {
    systemActive = true;
    digitalWrite(LED_Active, HIGH); // Turn on active LED
    digitalWrite(LED_Inactive, LOW); // Turn off inactive LED
  }

  // Check for door opening or motion detection
  if ((doorState == HIGH || motionState == HIGH) && systemActive) {
    // Wait for activation delay
    delay(activationDelay);
    
    // Check for keypad input during activation delay
    char key = '\0';
    unsigned long activationStartTime = millis();
    while (millis() - activationStartTime < activationDelay) {
      key = keypad.getKey();
      if (key == '#') {
        if (checkPasscode()) {
          systemActive = false;
          lastActivationTime = currentTime;
          digitalWrite(LED_Active, LOW); // Turn off active LED
          digitalWrite(LED_Inactive, HIGH); // Turn on inactive LED
          break;
        } else {
          sendSMS("Incorrect passcode entered!");
        }
      }
    }

    // If no correct passcode entered during activation delay, send SMS
    if (systemActive && key != '#') {
      sendSMS("Intrusion detected!");
    }
  }
}

bool checkPasscode() {
  // Replace this with your own passcode checking logic
  // For demonstration purposes, always return true
  return true;
}

void sendSMS(String message) {
  // Replace this with your SMS sending code
  // For demonstration purposes, just print the message to serial monitor
  Serial.println("Sending SMS: " + message);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.