Entrance system activated by PIR

I'm trying to use a 16x2 LCD and a 4x4 Keypad for an entry control.
This is located outside the house and should be activated through the PIR.
So if PIR detects motion LCD should power on and you should be able to enter your code. After some time, if there is no more motion or Key presses, LCD should be powered off again.
The code for LCD and keypad works - I just don't know the PIR part. Anybody did something similar already?

@andyk85
See if you can make this work

What have you tried so far and to what extent doesn't it work as intended?

can we see it ?

/*************************(Importieren der genutzten Bibliotheken)*************************/
#include <Keypad_I2C.h>  
#include <Keypad.h>      
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/****************************(Definieren der Globale Variablen)***************************/
#define I2CADDR 0x20                          // I2C Adresse vom PCF8574
#define LED13 13
const byte anzZeilen = 4;                        //Anzahl Zeilen 
const byte anzSpalten = 4;                       //Anzahl Spalten
#define Password_Lenght 7
char Data[Password_Lenght];
char Master[Password_Lenght] = "999999";
byte data_count = 0, master_count = 0, pass_good = 0;
bool Pass_is_good;
char customKey;

char tastenLayout[anzZeilen][anzSpalten] = {
  {'D','#','0','*'}, 
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};

String todo = "";
//Hier definieren wie das Keypad mit den IO Pins vom PCF8574 verdrahtet ist.
byte zeilenPins[anzZeilen] = {0, 1, 2, 3};       //Zeilen Pins
byte spaltenPins[anzSpalten] = {4, 5, 6, 7};     //Spalten Pins

//Initialisierung von Keypad & LCD
 
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
Keypad_I2C kpd = Keypad_I2C( makeKeymap(tastenLayout), zeilenPins, spaltenPins, anzZeilen, anzSpalten, I2CADDR );
 
void setup(){
  Wire.begin();
  Serial.begin(9600);
  kpd.begin();
  lcd.init();                      // initialize the lcd 
  lcd.init();
  lcd.backlight();
  
  pinMode(LED13, OUTPUT);  
}
 
void loop(){
  char key = kpd.getKey();
  lcd.setCursor(0, 0);
  lcd.print("Code eingeben");
  if (key){
    Serial.println(todo);
    todo = todo + key;
     Data[data_count] = key;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;
    if (key == '#'){ 
              
      if (todo == "1234#" ) {
          pass_good = 1;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Code User1");
          lcd.setCursor(0, 1);
          lcd.print("Eingang korrekt");
          delay(2000);
          }
          else
      if (todo == "1111#") {
          pass_good = 1;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Code User1");
          lcd.setCursor(0, 1);
          lcd.print("Garage korrekt");
          delay(2000);
          }
          else
      if (todo == "2222#") {
          pass_good = 1;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Code User2");
          lcd.setCursor(0, 1);
          lcd.print("Eingang korrekt");
          delay(2000);
          }
          else
      if (todo == "3333#") {
          pass_good = 1;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Code User2");
          lcd.setCursor(0, 1);
          lcd.print("Garage korrekt");
          delay(2000);
          }
          else
      if (pass_good == 0) {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Falsch");
          delay(2000);
      }
      todo = "";
      key = ' '; 
          delay(1000);
    lcd.clear();
    clearData();
    pass_good = 0;
      }
    if (key == '*'){
       todo = "";
       key = ' ';
           delay(1000);
    lcd.clear();
    clearData();
    pass_good = 0;
    }


  }
}


void led13() {
  digitalWrite(LED13, HIGH);
  delay(2000);
  digitalWrite(LED13, LOW);
  }

void clearData()
{
  while (data_count != 0)
  { // This can be used for any array size,
    Data[data_count--] = 0; //clear array for new data
  }
  return;
}

I just don't know how to handle the PIR.
I mean this whole thing should be triggered when motion is detected, like person is approaching entry it should power up.
If i trigger this only by motion like:

if (val == HIGH) {           // check if the sensor is HIGH
    Serial.println("Motion detected!"); 
    char key = kpd.getKey();
  lcd.setCursor(0, 0);
  lcd.print("Code eingeben");
  if (key){ //Keypad Function here....
    }
  }

how do I stop the PIR for triggering?

/*************************(Importieren der genutzten Bibliotheken)*************************/
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/****************************(Definieren der Globale Variablen)***************************/
#define I2CADDR 0x20                          // I2C Adresse vom PCF8574
#define LED13 13
const byte PIRpin = 12;  //  kann natürlich angepasst werden
const byte anzZeilen = 4;                        //Anzahl Zeilen
const byte anzSpalten = 4;                       //Anzahl Spalten
#define Password_Lenght 7
char Master[Password_Lenght] = "999999";

char tastenLayout[anzZeilen][anzSpalten] = {
  {'D', '#', '0', '*'},
  {'C', '9', '8', '7'},
  {'B', '6', '5', '4'},
  {'A', '3', '2', '1'}
};

//Hier definieren wie das Keypad mit den IO Pins vom PCF8574 verdrahtet ist.
byte zeilenPins[anzZeilen] = {0, 1, 2, 3};       //Zeilen Pins
byte spaltenPins[anzSpalten] = {4, 5, 6, 7};     //Spalten Pins

//Initialisierung von Keypad & LCD

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
Keypad_I2C kpd( makeKeymap(tastenLayout), zeilenPins, spaltenPins, anzZeilen, anzSpalten, I2CADDR );

void setup() {
  Wire.begin();
  Serial.begin(115200);
  kpd.begin();
  lcd.init();                      // initialize the lcd
  lcd.init();
  pinMode(PIRpin, INPUT);
  pinMode(LED13, OUTPUT);
}

void loop() {
  if (digitalRead(PIRpin))PIR();
}

bool PIR() {
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Code eingeben");
  lcd.setCursor(0, 1);
  bool pass_good = false;
  char Data[Password_Lenght];
  byte data_count = 0;
  unsigned long OldMillis=millis();
  while (!pass_good) {
    char key = kpd.getKey();
    if (key) {
      OldMillis=millis();
      Serial.println(key);
      lcd.print(key);
      if (key == '#') {
        lcd.clear();
        Data[data_count] = '\0';
        if (!strcmp(Data, "1234") ) {
          pass_good = 1;
          lcd.print("Code User1");
          lcd.setCursor(0, 1);
          lcd.print("Eingang korrekt");
        }
        else if (!strcmp(Data, "1111")) {
          pass_good = 1;
          lcd.print("Code User1");
          lcd.setCursor(0, 1);
          lcd.print("Garage korrekt");
        }
        else if (!strcmp(Data, "2222")) {
          pass_good = 1;
          lcd.print("Code User2");
          lcd.setCursor(0, 1);
          lcd.print("Eingang korrekt");
        }
        else if (!strcmp(Data, "3333")) {
          pass_good = 1;
          lcd.print("Code User2");
          lcd.setCursor(0, 1);
          lcd.print("Garage korrekt");
        }
        delay(2000);
      }
      if (key == '*') break;
      Data[data_count] = key;
      data_count++;
    }
    if(millis()-OldMillis>=15000)break;
  }
  delay(1000);
  lcd.clear();
  lcd.noBacklight();
  if (pass_good)led13();
}

void led13() {
  digitalWrite(LED13, HIGH);
  delay(2000);
  digitalWrite(LED13, LOW);
}

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