Components and supplies
Keypad
Alphanumeric LCD, 20 x 4
Breadboard (generic)
Tools and machines
Tape, Electrical
Apps and platforms
Arduino IDE
Project description
Code
Code for keypad
c_cpp
1#include <Keypad.h> 2 3const byte ROWS = 4; 4const byte COLS = 4; 5 6char hexaKeys[ROWS][COLS] = { 7 {'1', '2', '3', 'A'}, 8 {'4', '5', '6', 'B'}, 9 {'7', '8', '9', 'C'}, 10 {'*', '0', '#', 'D'} 11}; 12 13byte rowPins[ROWS] = {9, 8, 7, 6}; 14byte colPins[COLS] = {5, 4, 3, 2}; 15 16Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 17 18void setup(){ 19 Serial.begin(9600); 20} 21 22void loop(){ 23 char customKey = customKeypad.getKey(); 24 25 if (customKey){ 26 Serial.println(customKey); 27 } 28} 29#include <Wire.h> 30#include <LiquidCrystal_I2C.h> 31#include <Keypad.h> 32 33const byte ROWS = 4; 34const byte COLS = 4; 35 36char hexaKeys[ROWS][COLS] = { 37 {'1', '2', '3', 'A'}, 38 {'4', '5', '6', 'B'}, 39 {'7', '8', '9', 'C'}, 40 {'*', '0', '#', 'D'} 41}; 42 43byte rowPins[ROWS] = {9, 8, 7, 6}; 44byte colPins[COLS] = {5, 4, 3, 2}; 45 46Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 47 48LiquidCrystal_I2C lcd(0x21, 16, 2); 49 50void setup(){ 51 lcd.backlight(); 52 lcd.init(); 53} 54 55void loop(){ 56 char customKey = customKeypad.getKey(); 57 if (customKey){ 58 lcd.clear(); 59 lcd.setCursor(0, 0); 60 lcd.print(customKey); 61 } 62} 63#include <Wire.h> 64#include <LiquidCrystal_I2C.h> 65#include <Keypad.h> 66 67#define Password_Length 8 68 69int signalPin = 12; 70 71char Data[Password_Length]; 72char Master[Password_Length] = "123A456"; 73byte data_count = 0, master_count = 0; 74bool Pass_is_good; 75char customKey; 76 77const byte ROWS = 4; 78const byte COLS = 4; 79 80char hexaKeys[ROWS][COLS] = { 81 {'1', '2', '3', 'A'}, 82 {'4', '5', '6', 'B'}, 83 {'7', '8', '9', 'C'}, 84 {'*', '0', '#', 'D'} 85}; 86 87byte rowPins[ROWS] = {9, 8, 7, 6}; 88byte colPins[COLS] = {5, 4, 3, 2}; 89 90Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 91 92LiquidCrystal_I2C lcd(0x21, 16, 2); 93 94void setup(){ 95 lcd.init(); 96 lcd.backlight(); 97 pinMode(signalPin, OUTPUT); 98} 99 100void loop(){ 101 102 lcd.setCursor(0,0); 103 lcd.print("Enter Password:"); 104 105 customKey = customKeypad.getKey(); 106 if (customKey){ 107 Data[data_count] = customKey; 108 lcd.setCursor(data_count,1); 109 lcd.print(Data[data_count]); 110 data_count++; 111 } 112 113 if(data_count == Password_Length-1){ 114 lcd.clear(); 115 116 if(!strcmp(Data, Master)){ 117 lcd.print("Correct"); 118 digitalWrite(signalPin, HIGH); 119 delay(5000); 120 digitalWrite(signalPin, LOW); 121 } 122 else{ 123 lcd.print("Incorrect"); 124 delay(1000); 125 } 126 127 lcd.clear(); 128 clearData(); 129 } 130} 131 132void clearData(){ 133 while(data_count !=0){ 134 Data[data_count--] = 0; 135 } 136 return; 137} 138
Code for keypad
c_cpp
1#include <Keypad.h> 2 3const byte ROWS = 4; 4const byte COLS = 5 4; 6 7char hexaKeys[ROWS][COLS] = { 8 {'1', '2', '3', 'A'}, 9 {'4', '5', 10 '6', 'B'}, 11 {'7', '8', '9', 'C'}, 12 {'*', '0', '#', 'D'} 13}; 14 15byte 16 rowPins[ROWS] = {9, 8, 7, 6}; 17byte colPins[COLS] = {5, 4, 3, 2}; 18 19Keypad 20 customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 21 22void 23 setup(){ 24 Serial.begin(9600); 25} 26 27void loop(){ 28 char customKey 29 = customKeypad.getKey(); 30 31 if (customKey){ 32 Serial.println(customKey); 33 34 } 35} 36#include <Wire.h> 37#include <LiquidCrystal_I2C.h> 38#include <Keypad.h> 39 40const 41 byte ROWS = 4; 42const byte COLS = 4; 43 44char hexaKeys[ROWS][COLS] = { 45 46 {'1', '2', '3', 'A'}, 47 {'4', '5', '6', 'B'}, 48 {'7', '8', '9', 'C'}, 49 50 {'*', '0', '#', 'D'} 51}; 52 53byte rowPins[ROWS] = {9, 8, 7, 6}; 54byte colPins[COLS] 55 = {5, 4, 3, 2}; 56 57Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, 58 colPins, ROWS, COLS); 59 60LiquidCrystal_I2C lcd(0x21, 16, 2); 61 62void setup(){ 63 64 lcd.backlight(); 65 lcd.init(); 66} 67 68void loop(){ 69 char customKey 70 = customKeypad.getKey(); 71 if (customKey){ 72 lcd.clear(); 73 lcd.setCursor(0, 74 0); 75 lcd.print(customKey); 76 } 77} 78#include <Wire.h> 79#include 80 <LiquidCrystal_I2C.h> 81#include <Keypad.h> 82 83#define Password_Length 8 84 85int 86 signalPin = 12; 87 88char Data[Password_Length]; 89char Master[Password_Length] 90 = "123A456"; 91byte data_count = 0, master_count = 0; 92bool Pass_is_good; 93char 94 customKey; 95 96const byte ROWS = 4; 97const byte COLS = 4; 98 99char hexaKeys[ROWS][COLS] 100 = { 101 {'1', '2', '3', 'A'}, 102 {'4', '5', '6', 'B'}, 103 {'7', '8', '9', 'C'}, 104 105 {'*', '0', '#', 'D'} 106}; 107 108byte rowPins[ROWS] = {9, 8, 7, 6}; 109byte colPins[COLS] 110 = {5, 4, 3, 2}; 111 112Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, 113 colPins, ROWS, COLS); 114 115LiquidCrystal_I2C lcd(0x21, 16, 2); 116 117void setup(){ 118 119 lcd.init(); 120 lcd.backlight(); 121 pinMode(signalPin, OUTPUT); 122} 123 124void 125 loop(){ 126 127 lcd.setCursor(0,0); 128 lcd.print("Enter Password:"); 129 130 131 customKey = customKeypad.getKey(); 132 if (customKey){ 133 Data[data_count] 134 = customKey; 135 lcd.setCursor(data_count,1); 136 lcd.print(Data[data_count]); 137 138 data_count++; 139 } 140 141 if(data_count == Password_Length-1){ 142 143 lcd.clear(); 144 145 if(!strcmp(Data, Master)){ 146 lcd.print("Correct"); 147 148 digitalWrite(signalPin, HIGH); 149 delay(5000); 150 digitalWrite(signalPin, 151 LOW); 152 } 153 else{ 154 lcd.print("Incorrect"); 155 delay(1000); 156 157 } 158 159 lcd.clear(); 160 clearData(); 161 } 162} 163 164void 165 clearData(){ 166 while(data_count !=0){ 167 Data[data_count--] = 0; 168 } 169 170 return; 171} 172
Downloadable files
Diagram
Diagram
Comments
Only logged in users can leave comments
Tsimm
0 Followers
•0 Projects
Table of contents
Intro
0
0