A PROJECT SUMMARY
Hey folks, I hope everything is going well. Today, we’re going to showcase a fantastic project that uses an Arduino keypad and password to lock a door. In order to enter the passcode and gain access to the system, we are employing a keypad for this project. This project is suitable for usage in both homes and workplaces. This security system is excellent and robust.
COMPONENTS REQUIRED
- ARDUINO NANO
- I2C LCD DISPLAY MODULE
- L293D MOTOR DRIVER MODULE
- 12V DOOR LOCK ACTUATOR
- 4X4 KEYPAD
- DOT PCB BOARD
- MALE AND FEMALE BERG STRIP
- CONNECTING WIRES
- 10K RESISTOR
- 10K NETWORK RESISTOR
Link to Buy Products mentioned in the video – https://eagleelectronicsonline.com/in…
HARDWARE CONNECTIONS
————————————————————–
1.16×2 I2C LCD TO Arduino Nano Connection
GND-Connect to Nano GND
VCC-Connect to Nano 5V
SDA-Connect to Nano Pin No-A4
SCL-Connect to Nano Pin No-A5
————————————————————–
2.4×4 Keypad To Arduino Nano Connection
Keypad R1 connect to Nano Pin No-12
Keypad R2 connect to Nano Pin No-11
Keypad R3 connect to Nano Pin No-10
Keypad R4 connect to Nano Pin No-9
Keypad C1 connect to Nano Pin No-8
Keypad C2 connect to Nano Pin No-7
Keypad C3 connect to Nano Pin No-6
Keypad C4 connect to Nano Pin No-5
Note:
Nano Pin No-12 connect 10K Reistor to Gnd
Nano Pin No-11 connect 10K Reistor to Gnd
Nano Pin No-10 connect 10K Reistor to Gnd
Nano Pin No-9 connect 10K Reistor to Gnd
————————————————————–
3. Push Switch To Arduino Nano Connection
Switch One end connect to Nano Pin 3.3V
Switch another end connect to Nano pin No-A0
Note:
Nano Pin No-A0 connect 10K Reistor to Gnd
————————————————————–
4. L293D Motor Driver To Arduino Nano Connection
12V Pin Connect To Battery Positive
Gnd Pin Connect To Battery Negative
IN-1 Pin Connect To Nano Pin No-2
IN-2 Pin Connect To Nano Pin No-3
————————————————————–
5.L293D Motor Driver To Lock Connection
Connect Lock to the Motor-1 (Terminal Block)
————————————————————–
6.Battery To Arduino Nano Connection
Battery Positive Terminal Connect To Nano pin-VIN
Battery Negative Terminal Connect To Nano pin-GND
————————————————————–
CODE FOR I2C ADDRESS SCANNER
#include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("I2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found"); else Serial.println("done"); delay(5000); // wait 5 seconds for next scan }
CODE FOR DIGITAL LOCK
#include <Keypad.h> #include <EEPROM.h> #include <LiquidCrystal_I2C.h> #define Solenoid 2 //Actually the Gate of the transistor that controls the solenoid #define Solenoid1 3 #define O_Button A0 //Push Button #define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; char keypressed; //Where the keys are stored it changes very often char code[]= {'0','0','0','0'}; //The default code, you can change it or make it a 'n' digits one char code_buff1[sizeof(code)]; //Where the new key is stored char code_buff2[sizeof(code)]; //Where the new key is stored again so it's compared to the previous one short a=0,i=0,s=0,j=0; //Variables used later byte rowPins[numRows] = {12,11,10,9}; //Rows 0 to 3 //if you modify your pins you should modify this too byte colPins[numCols]= {8,7,6,5}; //Columns 0 to 3 LiquidCrystal_I2C lcd(0x27,16,2); Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); void setup() { lcd.begin (); //lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.noBacklight(); lcd.home (); lcd.print("Press * to enter"); //What's written on the LCD you can change pinMode(Solenoid,OUTPUT); pinMode(Solenoid1,OUTPUT); // pinMode(motor1,OUTPUT); pinMode(O_Button,INPUT); // digitalWrite(motor1 , LOW); // for(i=0 ; i<sizeof(code);i++){ //When you upload the code the first time keep it commented // EEPROM.get(i, code[i]); //Upload the code and change it to store it in the EEPROM // } //Then uncomment this for loop and reupload the code (It's done only once) } void loop() { keypressed = myKeypad.getKey(); //Constantly waiting for a key to be pressed if(keypressed == '*'){ // * to open the lock lcd.clear(); lcd.backlight(); lcd.setCursor(0,0); lcd.print("Enter code"); //Message to show GetCode(); //Getting code function if(a==sizeof(code)) //The GetCode function assign a value to a (it's correct when it has the size of the code array) OpenDoor(); //Open lock function if code is correct else{ lcd.clear(); lcd.print("Wrong"); //Message to print when the code is wrong } delay(2000); lcd.clear(); lcd.print("Press * to enter"); lcd.noBacklight();//Return to standby mode it's the message do display when waiting } if(keypressed == '2'){ //To change the code it calls the changecode function ChangeCode(); lcd.clear(); lcd.print("Press * to enter"); //When done it returns to standby mode lcd.noBacklight(); } int sensorValue = analogRead(O_Button); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); if(voltage > 3) { //Opening by the push button digitalWrite(Solenoid,HIGH); delay(1000); //Opens for 3s you can change digitalWrite(Solenoid,LOW); delay(10000); digitalWrite(Solenoid1,HIGH); delay(1000); //Opens for 3s you can change digitalWrite(Solenoid1,LOW); } } void GetCode(){ //Getting code sequence i=0; //All variables set to 0 a=0; j=0; while(keypressed != '#'){ //The user press A to confirm the code otherwise he can keep typing keypressed = myKeypad.getKey(); if(keypressed != NO_KEY && keypressed != '#' ){ //If the char typed isn't A and neither "nothing" lcd.setCursor(j,1); //This to write "*" on the LCD whenever a key is pressed it's position is controlled by j lcd.print("*"); j++; if(keypressed == code[i]&& i<sizeof(code)){ //if the char typed is correct a and i increments to verify the next caracter a++; //Now I think maybe I should have use only a or i ... too lazy to test it -_-' i++; } else a--; //if the character typed is wrong a decrements and cannot equal the size of code [] } } keypressed = NO_KEY; } void ChangeCode(){ //Change code sequence lcd.clear(); lcd.backlight(); lcd.print("Changing code"); delay(1000); lcd.clear(); lcd.print("Enter old code"); GetCode(); //verify the old code first so you can change it if(a==sizeof(code)){ //again verifying the a value lcd.clear(); lcd.print("Changing code"); GetNewCode1(); //Get the new code GetNewCode2(); //Get the new code again to confirm it s=0; for(i=0 ; i<sizeof(code) ; i++){ //Compare codes in array 1 and array 2 from two previous functions if(code_buff1[i]==code_buff2[i]) s++; //again this how we verifiy, increment s whenever codes are matching } if(s==sizeof(code)){ //Correct is always the size of the array for(i=0 ; i<sizeof(code) ; i++){ code[i]=code_buff2[i]; //the code array now receives the new code EEPROM.put(i, code[i]); //And stores it in the EEPROM } lcd.clear(); lcd.print("Code Changed"); delay(2000); } else{ //In case the new codes aren't matching lcd.clear(); lcd.print("Codes are not"); lcd.setCursor(0,1); lcd.print("matching !!"); delay(2000); } } else{ //In case the old code is wrong you can't change it lcd.clear(); lcd.print("Wrong"); delay(2000); } } void GetNewCode1(){ i=0; j=0; lcd.clear(); lcd.print("Enter new code"); //tell the user to enter the new code and press A lcd.setCursor(0,1); lcd.print("and press #"); delay(2000); lcd.clear(); lcd.setCursor(0,1); lcd.print("and press #"); //Press A keep showing while the top row print *** while(keypressed != '#'){ //A to confirm and quits the loop keypressed = myKeypad.getKey(); if(keypressed != NO_KEY && keypressed != '#' ){ lcd.setCursor(j,0); lcd.print("*"); //On the new code you can show * as I did or change it to keypressed to show the keys code_buff1[i]=keypressed; //Store caracters in the array i++; j++; } } keypressed = NO_KEY; } void GetNewCode2(){ //This is exactly like the GetNewCode1 function but this time the code is stored in another array i=0; j=0; lcd.clear(); lcd.print("Confirm code"); lcd.setCursor(0,1); lcd.print("and press #"); delay(3000); lcd.clear(); lcd.setCursor(0,1); lcd.print("and press #"); while(keypressed != '#'){ keypressed = myKeypad.getKey(); if(keypressed != NO_KEY && keypressed != '#' ){ lcd.setCursor(j,0); lcd.print("*"); code_buff2[i]=keypressed; i++; j++; } } keypressed = NO_KEY; } void OpenDoor() { //Lock opening function open for 3s lcd.clear(); lcd.print("Door Opened"); //With a message printed digitalWrite(Solenoid,HIGH); delay(1000); //Opens for 3s you can change digitalWrite(Solenoid,LOW); delay(10000); lcd.clear(); lcd.print("Door Closed"); digitalWrite(Solenoid1,HIGH); delay(1000); //Opens for 3s you can change digitalWrite(Solenoid1,LOW); }