4-digit Password Access System
Arduino 4-digit password access system.
Components and supplies
1
Jumper wires (generic)
1
Buzzer
1
Arduino UNO
4
Resistor 1k ohm
1
LED, Green
4
Tactile Switch, Top Actuated
1
LED, Red
1
Breadboard (generic)
3
Resistor 220 ohm
1
Alphanumeric LCD, 16 x 2
Apps and platforms
1
Arduino IDE
Project description
Code
Code:
arduino
1/* Arduino 4-digit password access system. 2 3 Components: 4 - Arduino Uno 5 - Push button tactile switch (x 4) 6 - 1kOhm resistor (x 4) 7 - 220Ohm resistor (x 3) 8 - 10kOhm potentiometer 9 - Passive buzzer 10 - Red LED 11 - Green LED 12 - LCD 13 - Some jumper wires 14 15 Libraries: 16 - LiquidCrystal library 17 18 Documentations: https://en.wikipedia.org/wiki/Telephone_keypad 19 20 Created on 19 June 2022 by c010rblind3ngineer 21*/ 22 23const int btn1 = A1; 24const int btn2 = A2; 25const int btn3 = A3; 26const int btn4 = A4; 27const int redLED = A0; 28const int buzzerPin = A5; 29const int greenLED = 6; 30 31int notes[] = {1209, 1336, 1477, 1633}; // frequencies referenced from wikipedia link above 32int userInput [5] ; 33int password [5] = {2, 3, 4, 1}; 34// TAKE NOTE: The number of 'beeps' correspond to the MISMATCHED user input and password, 35// Example... User input = 1, 2, 4, 3.... 36// The number '4' here is at the same position as the password array number '4', 37// so the beep will happen only 3 times during "Access Denied" since the rest of the 38// numbers in the array doesn't match each other. 39int keyCounter = 0; 40 41char entryOK [] = "Access Granted"; 42char entryNOTOK [] = "Access Denied"; 43 44#include <LiquidCrystal.h> 45 46LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 47 48void setup() { 49 pinMode(btn1, INPUT); 50 pinMode(btn2, INPUT); 51 pinMode(btn3, INPUT); 52 pinMode(btn4, INPUT); 53 pinMode(redLED, OUTPUT); 54 pinMode(greenLED, OUTPUT); 55 pinMode(buzzerPin, OUTPUT); 56 57 lcd.begin(16, 2); 58 lcd.setCursor(0, 0); 59} 60 61void loop() { 62 lcd.print("Enter 4-digit"); 63 lcd.setCursor(0, 1); 64 lcd.print("password: "); 65 lcd.blink(); 66 67 // 'for' loop ensures the User only press 4 buttons 68 for (int i = 0; i < 4;) { 69 70 if (digitalRead(btn1) == HIGH) { // button 1 pressed 71 digitalWrite(redLED, HIGH); 72 tone(buzzerPin, notes[0]); 73 74 lcd.print("1"); 75 userInput[i] = 1; 76 i++; 77 delay(250); 78 } 79 else if (digitalRead(btn2) == HIGH) { // button 2 pressed 80 digitalWrite(redLED, HIGH); 81 tone(buzzerPin, notes[1]); 82 83 lcd.print("2"); 84 userInput[i] = 2; 85 i++; 86 delay(250); 87 } 88 else if (digitalRead(btn3) == HIGH) { // button 3 pressed 89 digitalWrite(redLED, HIGH); 90 tone(buzzerPin, notes[2]); 91 92 lcd.print("3"); 93 userInput[i] = 3; 94 i++; 95 delay(250); 96 } 97 else if (digitalRead(btn4) == HIGH) { // button 4 pressed 98 digitalWrite(redLED, HIGH); 99 tone(buzzerPin, notes[3]); 100 101 lcd.print("4"); 102 userInput[i] = 4; 103 i++; 104 delay(250); 105 } 106 else { 107 digitalWrite(redLED, LOW); 108 digitalWrite(btn1, LOW); 109 digitalWrite(btn2, LOW); 110 digitalWrite(btn3, LOW); 111 digitalWrite(btn4, LOW); 112 noTone(buzzerPin); 113 } 114 } 115 lcd.noBlink(); 116 lcd.clear(); 117 noTone(buzzerPin); 118 digitalWrite(redLED, LOW); 119 120 // 'for' loop check if the 4-digit password is the same as User input 121 for (int j = 0; j < 4; j++) { 122 if (userInput[j] == password[j]) { 123 keyCounter++; 124 //...Access Granted... 125 if (keyCounter == 4) { 126 digitalWrite(greenLED, HIGH); 127 tone(buzzerPin, 2000); 128 delay(100); 129 noTone(buzzerPin); 130 delay(100); 131 tone(buzzerPin, 2000); 132 delay(100); 133 noTone(buzzerPin); 134 lcd.noBlink(); 135 lcd.print(entryOK); 136 delay(2000); 137 keyCounter = 0; 138 lcd.clear(); 139 } 140 } 141 //...Access Denied... 142 else { 143 digitalWrite(redLED, HIGH); 144 lcd.noBlink(); 145 lcd.print(entryNOTOK); 146 delay(100); 147 tone(buzzerPin, 500); 148 delay(250); 149 noTone(buzzerPin); 150 keyCounter = 0; 151 lcd.clear(); 152 } 153 } 154 // reset LCD 155 digitalWrite(greenLED, LOW); 156 digitalWrite(redLED, LOW); 157 lcd.clear(); 158 delay(500); 159} 160
Repository link:
Code:
arduino
1/* Arduino 4-digit password access system. 2 3 Components: 4 - Arduino Uno 5 - Push button tactile switch (x 4) 6 - 1kOhm resistor (x 4) 7 - 220Ohm resistor (x 3) 8 - 10kOhm potentiometer 9 - Passive buzzer 10 - Red LED 11 - Green LED 12 - LCD 13 - Some jumper wires 14 15 Libraries: 16 - LiquidCrystal library 17 18 Documentations: https://en.wikipedia.org/wiki/Telephone_keypad 19 20 Created on 19 June 2022 by c010rblind3ngineer 21*/ 22 23const int btn1 = A1; 24const int btn2 = A2; 25const int btn3 = A3; 26const int btn4 = A4; 27const int redLED = A0; 28const int buzzerPin = A5; 29const int greenLED = 6; 30 31int notes[] = {1209, 1336, 1477, 1633}; // frequencies referenced from wikipedia link above 32int userInput [5] ; 33int password [5] = {2, 3, 4, 1}; 34// TAKE NOTE: The number of 'beeps' correspond to the MISMATCHED user input and password, 35// Example... User input = 1, 2, 4, 3.... 36// The number '4' here is at the same position as the password array number '4', 37// so the beep will happen only 3 times during "Access Denied" since the rest of the 38// numbers in the array doesn't match each other. 39int keyCounter = 0; 40 41char entryOK [] = "Access Granted"; 42char entryNOTOK [] = "Access Denied"; 43 44#include <LiquidCrystal.h> 45 46LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 47 48void setup() { 49 pinMode(btn1, INPUT); 50 pinMode(btn2, INPUT); 51 pinMode(btn3, INPUT); 52 pinMode(btn4, INPUT); 53 pinMode(redLED, OUTPUT); 54 pinMode(greenLED, OUTPUT); 55 pinMode(buzzerPin, OUTPUT); 56 57 lcd.begin(16, 2); 58 lcd.setCursor(0, 0); 59} 60 61void loop() { 62 lcd.print("Enter 4-digit"); 63 lcd.setCursor(0, 1); 64 lcd.print("password: "); 65 lcd.blink(); 66 67 // 'for' loop ensures the User only press 4 buttons 68 for (int i = 0; i < 4;) { 69 70 if (digitalRead(btn1) == HIGH) { // button 1 pressed 71 digitalWrite(redLED, HIGH); 72 tone(buzzerPin, notes[0]); 73 74 lcd.print("1"); 75 userInput[i] = 1; 76 i++; 77 delay(250); 78 } 79 else if (digitalRead(btn2) == HIGH) { // button 2 pressed 80 digitalWrite(redLED, HIGH); 81 tone(buzzerPin, notes[1]); 82 83 lcd.print("2"); 84 userInput[i] = 2; 85 i++; 86 delay(250); 87 } 88 else if (digitalRead(btn3) == HIGH) { // button 3 pressed 89 digitalWrite(redLED, HIGH); 90 tone(buzzerPin, notes[2]); 91 92 lcd.print("3"); 93 userInput[i] = 3; 94 i++; 95 delay(250); 96 } 97 else if (digitalRead(btn4) == HIGH) { // button 4 pressed 98 digitalWrite(redLED, HIGH); 99 tone(buzzerPin, notes[3]); 100 101 lcd.print("4"); 102 userInput[i] = 4; 103 i++; 104 delay(250); 105 } 106 else { 107 digitalWrite(redLED, LOW); 108 digitalWrite(btn1, LOW); 109 digitalWrite(btn2, LOW); 110 digitalWrite(btn3, LOW); 111 digitalWrite(btn4, LOW); 112 noTone(buzzerPin); 113 } 114 } 115 lcd.noBlink(); 116 lcd.clear(); 117 noTone(buzzerPin); 118 digitalWrite(redLED, LOW); 119 120 // 'for' loop check if the 4-digit password is the same as User input 121 for (int j = 0; j < 4; j++) { 122 if (userInput[j] == password[j]) { 123 keyCounter++; 124 //...Access Granted... 125 if (keyCounter == 4) { 126 digitalWrite(greenLED, HIGH); 127 tone(buzzerPin, 2000); 128 delay(100); 129 noTone(buzzerPin); 130 delay(100); 131 tone(buzzerPin, 2000); 132 delay(100); 133 noTone(buzzerPin); 134 lcd.noBlink(); 135 lcd.print(entryOK); 136 delay(2000); 137 keyCounter = 0; 138 lcd.clear(); 139 } 140 } 141 //...Access Denied... 142 else { 143 digitalWrite(redLED, HIGH); 144 lcd.noBlink(); 145 lcd.print(entryNOTOK); 146 delay(100); 147 tone(buzzerPin, 500); 148 delay(250); 149 noTone(buzzerPin); 150 keyCounter = 0; 151 lcd.clear(); 152 } 153 } 154 // reset LCD 155 digitalWrite(greenLED, LOW); 156 digitalWrite(redLED, LOW); 157 lcd.clear(); 158 delay(500); 159} 160
Downloadable files
Schematic:
Schematic:

Circuit:
Circuit:

Circuit:
Circuit:

Schematic:
Schematic:

Comments
Only logged in users can leave comments