Advertisement
Guest User

Arduino passcode with lcd screen

a guest
Mar 31st, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <Password.h>
  2.  
  3. #include <Wire.h>
  4. #include <LCD.h>
  5. #include <LiquidCrystal.h>
  6. #include <LiquidCrystal_I2C.h>
  7. #include <LiquidCrystal_SI2C.h>
  8.  
  9.  
  10. #include <Keypad.h>
  11. #include <Servo.h>
  12.  
  13. int greenLight = 11;
  14. int redLight = 12;
  15. int servoPin = 3;
  16. int amount1 = 0;
  17.  
  18. #define int servoPin = 13;
  19. #define I2C_ADDR 0x27
  20. #define BACKLIGHT_PIN 3
  21. #define En_pin 2
  22. #define Rw_pin 1
  23. #define Rs_pin 0
  24. #define D4_pin 4
  25. #define D5_pin 5
  26. #define D6_pin 6
  27. #define D7_pin 7
  28.  
  29. const byte rows = 4; //four rows
  30. const byte cols = 4; //three columns
  31. char keys[rows][cols] = {
  32. {'1','2','3', 'A'},
  33. {'4','5','6', 'B'},
  34. {'7','8','9', 'C'},
  35. {'*','0','#', 'D'}
  36. };
  37.  
  38. byte rowPins[rows] = {9,8,7,6}; //connect to the row pinouts of the keypad
  39. byte colPins[cols] = {5,4,3,2}; //connect to the column pinouts of the keypad
  40. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
  41.  
  42. Servo Servo1;
  43.  
  44. LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  45.  
  46. void setup()
  47. {
  48. lcd.begin(16,2);
  49. Serial.begin(9600);
  50. lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  51. lcd.setBacklight(HIGH);
  52. Servo1.attach(servoPin);
  53. Servo1.write(0);
  54. }
  55.  
  56.  
  57. void loop()
  58. {
  59. char key = keypad.getKey();
  60. String pass = "";
  61. String realPass = "2601";
  62.  
  63. lcd.setCursor(0, 0);
  64. lcd.print("Enter Password:");
  65. lcd.setCursor(0, 1);
  66.  
  67. if(key != NO_KEY)
  68. {
  69. if(amount1 >= 3)
  70. {
  71. amount1 = 0;
  72. if(pass == realPass)
  73. {
  74. pass = "";
  75. lcd.setCursor(0,0);
  76. lcd.print("Correct! ");
  77. digitalWrite(greenLight, HIGH);
  78. delay(1500);
  79. digitalWrite(greenLight, LOW);
  80. }
  81. else
  82. {
  83. pass = "";
  84. lcd.setCursor(0,0);
  85. lcd.print("Incorrect! ");
  86. lcd.setCursor(0,1);
  87. lcd.print("");
  88. digitalWrite(redLight, HIGH);
  89. delay(1500);
  90. digitalWrite(redLight, LOW);
  91. }
  92. }
  93. else
  94. {
  95. Serial.println(key);
  96. amount1++;
  97. pass = pass + key;
  98. lcd.setCursor(0,1);
  99. lcd.print(pass);
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement