
In today’s life everything becomes simple and advanced, previously to lock something we used to have padlocks, combination locks. But due to the increase in theft and technology, new types of locks such as electronic locks, smart locks have been invented and people are widely using them to protect their property.
In this project, we will build a password-based door lock system by interfacing the Micro:bit board with a 4×4 keypad to enter the password.
We use a sliding door opening or closing by horizontal translation thanks to a 5V DC motor.
With this project we can build a security system that works with a password.
connecting wires
We connect the 8 outputs of the keyboard to the 8 pins of the Arduino (from 2 to 9).
For the I2C LCD 1602 display we connect:
the SDA pin to the A4 pin of Arduino
the SCL pin to the A5 pin of Arduino
the GND pin to the GND pin of Arduino
the VCC pin to the 5V pin of Arduino
Connect pin 4 of the Arduino to the ENA pin of the L298N module.
Connect pin 3 of the Arduino to pin IN1 of the L298N module.
Connect pin 2 of the Arduino to pin IN2 of the L298N module.
Connect the GND pin of the Arduino to the GND pin of the L298N module.
Connect the GND pin of the Arduino to the (-) terminal of the 9V battery
Connect the 12V pin of the L298N module to the (+) terminal of the 9V battery
Connect the two motor terminals to the two pins OUT1 and OUT2 of the L298N module
Here is the Arduino program that allows the door to be opened or closed by the Arduino card.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#include <LiquidCrystal_I2C.h> #include <Keypad.h> const int ROW_NUM = 4; //four rows const int COLUMN_NUM = 4; //four columns LiquidCrystal_I2C lcd(0x27, 20, 4); char keys[ROW_NUM][COLUMN_NUM] = { {'1','2','3', 'A'}, {'4','5','6', 'B'}, {'7','8','9', 'C'}, {'*','0','#', 'D'} }; String code=""; 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, 2}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); int enA = 10; int in1 = 11; int in2 = 12; void setup(){ lcd.init(); // display initialization lcd.clear(); lcd.backlight(); // activate the backlight lcd.setCursor(0, 0); // stand in the front line pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); analogWrite(enA, 65); } void loop(){ char key = keypad.getKey(); if(key) // You press a key on the matrix keyboard { lcd.print(key); // Display the entered character on the LCD display code+=key; delay(100); } if ((code.length()==4)){ if (code=="2356") { lcd.clear(); lcd.print("valid code"); delay(2000); //the motor turns to open the door digitalWrite(in1, HIGH); digitalWrite(in2, LOW); delay(700); //stop le moteur digitalWrite(in1, LOW); digitalWrite(in2, LOW); lcd.clear(); code=""; } else if (code=="1111"){ delay(2000); digitalWrite(in1, LOW); //the motor rotates in the opposite direction to close the door digitalWrite(in2, HIGH); delay(700); //stop le moteur digitalWrite(in1, LOW); digitalWrite(in2, LOW); lcd.clear(); code=""; } else { lcd.print("invalid code"); delay(2000); lcd.clear(); code=""; } } } |