Problems with the "exit button" of an access control system.

Hello,

I’m doing an access control system, I’m having a little problem with the start button.

For the implementation of the system, I put the output button between the voltage source and the electromagnetic lock (view image). The button is normally closed (NC) when pressing the button the electromagnetic lock is turned off and the door is opened (in theory). But in practice it is not so, because the lock has to be unloaded. When the user presses the button, the electromagnetic lock is not discharged in that time interval, so the door is still closed.

In order for the electromagnetic lock to fully discharge the user has to hold the exit button pressed, the problem here is that when the button is released the electromagnetic lock is energized again and as a consequence the user will not be able to leave because the door is closed.

So I’m thinking of putting the start button as the arduino’s input.

The problem of putting the output button on the arduino, is that the arduino freezes when it passes a “switch” instruction. So if at any moment a user or intruder accesses a menu and someone wants to leave the place, it can not leave because the arduino is waiting for the user or intruder to press a button on the keyboard.(Attached code) In the code, I made a interruption but it does not work when the program is in the menu. Because it is waiting for the user to press a key.

It is important that the people who are inside the place can leave at any time.
Someone to help me please?

(translate by: translate.google)

Captura.JPG

sketch_dec10a.ino (2.64 KB)

Image from Original Post so we don’t have to download it. See this Image Guide

Captura.JPG

Program code from Original Post …

#include <Keypad.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

//Definición de filas y columnas
const byte Filas = 4; //Cuatro filas
const byte Cols = 4; //Cuatro columnas

//Definición de los pines
byte Pins_Filas[] = {3, 2, 1, 0}; //Pines Arduino para las filas
byte Pins_Cols[] =  {4, 5, 6, 7}; // Pines Arduino para las columnas


//Definición de las teclas
char Teclas [ Filas ][ Cols ] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

//Se crea una instancia llamada Teclado1 y el cual asignara las teclas que tenemos en el arreglo "Teclas" y le decimos
//que se han conectados los pines de las filas y columnas


Keypad kpd = Keypad(makeKeymap(Teclas), Pins_Filas, Pins_Cols, Filas, Cols);


char Teclado ()
{
  do {

    char Tecla = kpd.getKey();

    if (Tecla != NO_KEY)
    {
      return Tecla;
    }
  } while (1);
}

int Door = A0; 
volatile int ExitBUTTON = LOW; 
const int inputPin= 18;
int value = 0;



void setup() {
 lcd.begin(20, 4); 
 lcd.display(); 
 pinMode(Door, OUTPUT);
 attachInterrupt(5, Exit, RISING); //interrupcion
 
}

void loop() {
 lcd.setCursor(0, 0); lcd.print("Home"); //Imprime en la lcd

  
 if(ExitBUTTON  == HIGH){
      digitalWrite(Door, HIGH);
      delay(100);
      digitalWrite(Door, LOW);
      ExitBUTTON = LOW;
 }


  char Tecla = kpd.getKey();
  
  if (Tecla == '*') {
     Menu();
  }
}

void Menu(){

     lcd.clear();
     lcd.setCursor(0, 0); lcd.print("1. Administrator"); //Imprime en la lcd
     lcd.setCursor(0, 1); lcd.print("2. Users"); //Imprime en la lcd 

     char kp = Teclado ();

      switch (kp) {
        case '1':
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Add user"); //Imprime en la lcd
              lcd.setCursor(0, 1); lcd.print("Delete users"); //Imprime en la lcd
              
              kp = Teclado ();
              switch (kp) {
                case '1':
                  lcd.clear();
                  lcd.setCursor(0, 0); lcd.print("Add user"); //Imprime en la lcd
                  delay(100);
                  lcd.clear();
                break;

                case '2':
                        lcd.clear();
                        lcd.setCursor(0, 0); lcd.print("Delete users"); //Imprime en la lcd
                        delay(100);
                        lcd.clear();
                break;
              }
        break;

        case '2':
              lcd.clear();
              lcd.setCursor(0, 0); lcd.print("Users"); //Imprime en la lcd
              delay(100);
              lcd.clear();
        break;
        
      }

}

//
void Exit() { 
  ExitBUTTON = !ExitBUTTON; 
}

…R

I suspect your Interrupt Service Routine is operating so fast that you can have no idea what value ExitBUTTON has - especially if your switch mechanism bounces and most of them do.

Also, it should be defined as a byte so there is only one read needed in if(ExitBUTTON == HIGH){. When it is an int (2 bytes) one of them could change in the middle of a read,

HOWEVER I can see no reason to need an interrupt to detect a human pushing a button. If the rest of the code is written properly you be perfectly well able to detect the button using digitalRead() and without the complications of debugging an ISR.

Have a look at the demo Several Things at a Time

Another important point, if the EXIT button is a safety feature it should work completely independently of your Arduino. DO NOT make people's safety dependent on your coding skills. All the Arduino may need to know is that it has happened.

...R

You just need a simple 2 - 3 second off delay circuit, you could do that with a 555 timer and not even involve the Arduino.

outsider:
You just need a simple 2 - 3 second off delay circuit, you could do that with a 555 timer and not even involve the Arduino.

I’m trying to do that, with timer 555 in monostable mode, but I do not know how to generate a 5-second delay for the electromagnetic lock to turn off during that time period.

I did the proteus simulation.

Ideal function:

The output button is normally closed, so the electromagnetic lock will always be on, when the output button is pressed it stops feeding the electromagnetic lock for 5 seconds and then turns on the electromagnetic lock again.

My design:

It does not work that way because if I put a normally closed button the electromangetic lock is always on when the button is pressed. (view image diagram)

exit diagram.JPG

And if I put a button normally open, at the moment of being pressed the button the electromagnetic lock will be on for a period of time and then turned off. That’s because the signal is square. (view image 555)

555.png

If anyone can help me, it will be very helpful. Thank you

(translate by google)

Robin2:
I suspect your Interrupt Service Routine is operating so fast that you can have no idea what value ExitBUTTON has - especially if your switch mechanism bounces and most of them do.

Also, it should be defined as a byte so there is only one read needed in if(ExitBUTTON == HIGH){. When it is an int (2 bytes) one of them could change in the middle of a read,

HOWEVER I can see no reason to need an interrupt to detect a human pushing a button. If the rest of the code is written properly you be perfectly well able to detect the button using digitalRead() and without the complications of debugging an ISR.

Have a look at the demo Several Things at a Time

Another important point, if the EXIT button is a safety feature it should work completely independently of your Arduino. DO NOT make people's safety dependent on your coding skills. All the Arduino may need to know is that it has happened.

...R

Interrupts do not work when execute a "switch case"

new99:
Interrupts do not work when execute a "switch case"

I don't understand that. I have never heard that SWITCH/CASE disables interrupts - why would it?

Also, I have no idea what that comment has to do with my Reply #2 which had no mention of SWITCH/CASE

...R