Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <Servo.h>
- #include <Keypad.h>
- #include <MFRC522.h>
- #include <LiquidCrystal_I2C.h>
- #define SS_PIN 10
- #define RST_PIN 9
- int signalPin = A0;
- #define Password_Length 8
- char Data[Password_Length];
- char Master[Password_Length] = "123A456";
- byte data_count = 0, master_count = 0;
- bool Pass_is_good;
- char customKey;
- const byte ROWS = 4;
- const byte COLS = 4;
- char hexaKeys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {A3, 8, 7, 6};
- byte colPins[COLS] = {5, 4, 3, A2};
- Servo myServo;
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- Serial.begin(9600);
- SPI.begin();
- mfrc522.PCD_Init();
- pinMode(signalPin, OUTPUT);
- digitalWrite(signalPin, LOW);
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Starting");
- myServo.attach(2);
- myServo.write(0);
- delay(5000);
- Serial.println("Scanning Card...");
- Serial.println();
- }
- void loop() {
- lcd.setCursor(0, 0);
- lcd.print("Enter Password:");
- customKey = customKeypad.getKey();
- if (customKey) {
- Data[data_count] = customKey;
- Serial.print(Data[data_count]);
- lcd.setCursor(data_count, 1);
- lcd.print(Data[data_count]);
- data_count++;
- }
- if (data_count == Password_Length - 1) {
- lcd.clear();
- if (!strcmp(Data, Master)) {
- Serial.println();
- // Open Door: Servo + Solienoid
- openDoorAction();
- }
- else {
- Serial.println();
- // Close Door: Servo + Solienoid
- closeDoorAction();
- }
- lcd.clear();
- }
- if ( ! mfrc522.PICC_IsNewCardPresent()) {
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial() ) {
- return;
- }
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++) {
- Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- Serial.println();
- content.toUpperCase();
- if (content.substring(1) == "14 65 FE 2B" || content.substring(1) == "39 B1 28 C2")
- {
- // Open Door: Servo + Solienoid
- openDoorAction();
- }
- else
- {
- // Close Door: Servo + Solienoid
- closeDoorAction();
- }
- }// end of LOOP
- void clearData1() {
- while (data_count != 0) {
- Data[data_count--] = 0;
- }
- return;
- }
- void openDoorAction() {
- Serial.println("Access Granted");
- lcd.setCursor(0, 1);
- lcd.print("Access Granted");
- digitalWrite(signalPin, HIGH);
- myServo.write(90);
- delay(5000);
- digitalWrite(signalPin, LOW);
- myServo.write(0);
- clearData1();
- lcd.clear();
- }
- void closeDoorAction() {
- Serial.println("Access Denied");
- lcd.setCursor(0, 1);
- lcd.print("Access Denied");
- myServo.write(0);
- delay(1000);
- clearData1();
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement