keypad door lock override button

I’m quite new to this stuff so I don’t really know that much, but I’ve recently made a servo door lock controlled with a keypad, the keypad is located on the outside of the room so you can enter, but I didn’t think about how to lock/unlock it from the inside of the room, so i want to add a button on the inside of the room as well as the keypad on the outside that can be used to lock and unlock the door but I do not know how to write the code for it.
I’ve attached the code i’m using

Please help, would be greatly appreciated

door_lock.ino (975 Bytes)

wire a button on the inside of the room to pin 2 of your arduino (to trigger an interrupt). You can either wire it so that when the button is pressed, the voltage drops to zero (pin High by default) or to 1 (pin low by default). Ensure you use proper wiring and pull up/down.

At the begining of your sketch declare a

volatile boolean needToUnlockFromInside = false;

in the setup, attach an interrupt function that will get triggered by pressing the button

pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), unlockDoorFromInside, mode); // mode to match your button wiring

then write a function

void unlockDoorFromInside()

which will Debounce (check in the last time this function was called is more than 50ms ago for example, I let you explore how you do this) and if yes, set the

needToUnlockFromInside = true; // button is pressed from the inside, need to unlock

then in the main loop add a piece of code checking that needToUnlockFromInside flag and trigger unlocking if true (and don't forget to also reset the flag to false once done)

you could improve your code a bit to accept variable length password by not hardwiring the 3 and use instead of

if (position == 3)

with something like

if (position == (sizeof(password) - 1))

You could also keep a global boolean variable to hold the status of the door (locked or unlocked) so that you don't send unnecessary commands to the servo if you are already in the correct position when you press '*' or '#'

did you implement this? would be curious to see a photo of your set up! seems fun (and don't get locked into the room because you have no power supply.... always have a manual way to exit the room!)