Muhammad_Munir
Published © GPL3+

How to make keypad door lock

How to make Password based door lock at home

BeginnerFull instructions provided455
How to make keypad door lock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
L298n Motor Driver
×1
3x4 Keypad
×1
RGB LED
×1
Jumper Wires
×1
Car door lock actuator
×1
Plastic Tie
×1
Screws
×1
3.7 volt Battery
×3
12 volt Battery Holder
×1

Story

Read more

Code

Code

Arduino
#include <Keypad.h>

int lock_pin = A0; 
int unlock_pin = A1;
int green_led = 11; 
int blue_led = 12; 
int red_led = 13;
int j = 0;

const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 3; //three columns

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

const String password = "432"; // change your password here
String input_password;

void setup() {

  pinMode(lock_pin, OUTPUT); 
  pinMode(unlock_pin, OUTPUT);
  pinMode(green_led, OUTPUT); 
  pinMode(blue_led, OUTPUT);
  pinMode(red_led, OUTPUT);

  Serial.begin(9600);
  input_password.reserve(32); // maximum input characters is 33, change if needed
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    Serial.println(key);

    if (key == '*') {
      input_password = ""; // clear input password
    } else if (key == '#') {
      if (password == input_password) {
        Serial.println("password is correct");
Serial.println(input_password);
        if (j == 0)
        {
          digitalWrite(lock_pin, HIGH); 
          digitalWrite(green_led, HIGH);
          delay(1000);
          digitalWrite(lock_pin, LOW);
          digitalWrite(green_led, LOW);
          j = 1;
        }
        else if (j == 1)
        {
          digitalWrite(unlock_pin, HIGH);
          digitalWrite(blue_led, HIGH); 
         delay(500);
          digitalWrite(unlock_pin, LOW);
          digitalWrite(blue_led, LOW);
          j = 0;
        }

      } else {
        Serial.println("password is incorrect, try again");
         digitalWrite(red_led, HIGH); //..the green LED not..
         delay(500);
          digitalWrite(red_led, LOW);
      }

      input_password = ""; // clear input password
    } else {
      input_password += key; // append new character to input password string
    }
  }
}

Credits

Muhammad_Munir
79 projects • 50 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments