Zamek drzwi

Zamek drzwi 






// Include the libraries:
// LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

int lock_pin = A0;
int unlock_pin = A1;
int green_led = 11;
int blue_led = 12;
int red_led = 13;
int j = 0;
int x = 0;

const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 3; //three columns

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
const String password = "432"; // change your password here
String input_password;

void setup() {

  pinMode(lock_pin, OUTPUT);
  pinMode(unlock_pin, OUTPUT);
  pinMode(green_led, OUTPUT);
  pinMode(blue_led, OUTPUT);
  pinMode(red_led, OUTPUT);

  Serial.begin(9600);
  input_password.reserve(32); // maximum input characters is 33, change if needed
  lcd.init();                    // initialize the lcd
  lcd.backlight();
  lcd.setCursor(4, 0);
  lcd.print("Wel Come");
  lcd.setCursor(1, 1);
  lcd.print("Enter Password");
}

void loop() {
  char key = keypad.getKey();

  if (key) {

    Serial.println(key);

    if (key == '*') {
      input_password = ""; // clear input password
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Password Clear");
      lcd.setCursor(0, 1);
      lcd.print("Enter Again !");
      x = 0;

    } else if (key == '#') {

      if (password == input_password) {
        Serial.println("password is correct");
        Serial.println(input_password);
        if (j == 0)
        {
          digitalWrite(lock_pin, HIGH);
          digitalWrite(green_led, HIGH);
          delay(1000);
          digitalWrite(lock_pin, LOW);
          digitalWrite(green_led, LOW);
          j = 1;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("CORRECT!");
          lcd.setCursor(0, 1);
          lcd.print("DOOR LOCKED!");
        }
        else if (j == 1)
        {
          digitalWrite(unlock_pin, HIGH);
          digitalWrite(blue_led, HIGH);
          delay(500);
          digitalWrite(unlock_pin, LOW);
          digitalWrite(blue_led, LOW);
          j = 0;
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("CORRECT!");
          lcd.setCursor(0, 1);
          lcd.print("DOOR UNLOCKED!");
        }

      } else {
        Serial.println("password is incorrect, try again");
        digitalWrite(red_led, HIGH); //..the green LED not..
        delay(500);
        digitalWrite(red_led, LOW);

        lcd.setCursor(0, 0);
        lcd.print("INCORRECT!");
        lcd.setCursor(0, 1);
        lcd.print("ACCESS DENIED!");

        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
        delay(300);
        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
        delay(300);
        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
        delay(300);
        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
        delay(300);
        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
        delay(300);
        lcd.setBacklight(LOW);
        delay(300);
        lcd.setBacklight(HIGH);
         lcd.setCursor(0, 0);
        lcd.print("Please Enter");
        lcd.setCursor(0, 1);
        lcd.print("Correct Password!");
        
      }

      input_password = ""; // clear input password
      x = 0;
    } else {
      if (x == 0)
        lcd.clear();
      x = 1;
      input_password += key; // append new character to input password string
      lcd.setCursor(input_password.length(), 0); // move cursor to new position
      lcd.print('*');                 // print * key as hiden character
    }
  }
}

Diagram



Komentarze