Add a reset botton to a lock system

I am new in this domain and i need some help in my new project, So i wanted to do a security thing with a keypad and a lcd but i don’t know how to code a reset botton,
the code is attached, pleas help me and thank you for your time.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
 
const byte ROWS = 4;
const byte COLS = 4;
 
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
 
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
 
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
 
LiquidCrystal_I2C lcd(0x3F, 16, 2);  
 
void setup(){
  lcd.backlight();
  lcd.init(); 
}
 
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    lcd.clear();
    lcd.setCursor(0, 0); 
    lcd.print(customKey);
void resetPassword(){
 } }

sketch_jul08a.ino (1.46 KB)

if you are physically attaching a button, look at the button example in the IDE (File-Examples->02.Digital->Button) then add that code into your sketch. If you want to make it even easier, connect one side of the button to ground and the other side to your pin. Then, declare that pin as type INPUT_PULLUP so you do not need any external resistors. Note that this will change the logic of your button. When it is PRESSED, it will read LOW (since it is shorted to ground) and when NOT PRESSED it will read HIGH (since the internal pull-up resistor is doing its job)

thank you sir, but the problm isn’t the botton sir, i just don’t know how to code it so when i press the dedicated botton the program will ask me to set a new pass word.

omardzgamer:
thank you sir, but the problm isn't the botton sir, i just don't know how to code it so when i press the dedicated botton the program will ask me to set a new pass word.

You were told exactly where to look for code. Since you haven't added any button code at all to your sketch, it's impossible to help you. Go look at the example you were directed to, add the same kind of code to your sketch, and then post that here if you have problems.

Sir i am using a matrix, and i know how to read the input, but i don't know how to make the password rest.

omardzgamer:
Sir i am using a matrix, and i know how to read the input, but i don’t know how to make the password rest.

So, you want one of the keypad keys to perform this reset? Which one? You confused everyone by saying you wanted to “code a button”.

hhh sorry sir am not very good with english, and i just need like the bit where i press X botton and the program will allow me to change the pass word

Okay, first post something that will actually compile without errors.

it's fixed

Thank you, but next time you make a change, don't go back and edit previous posts. It makes the replies look like nonsense to people that come and read it later.

I doubt very much that you tried to compile this:

void loop(){
  char customKey = customKeypad.getKey();
 
  if (customKey){
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(customKey);
void resetPassword(){
 } }

You can't have a function definition inside a function. So please try again. Compile your program, make sure there are no errors, and then add it as a new post here.

thank you sir, and i'll do my best to post it by tomorow.