Sabri GENÇ
Published © GPL3+

Door Security System

With the door security system, you can control it through the interface on the arduino.

IntermediateFull instructions provided1 hour646
Door Security System

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Grove - 12-Channel Capacitive Touch Keypad (ATtiny1616)
Seeed Studio Grove - 12-Channel Capacitive Touch Keypad (ATtiny1616)
4x4 keypad is used in this project
×1
9V battery (generic)
9V battery (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1

Hand tools and fabrication machines

Servo Motor, Premium Male/Male Jumper Wires
Servo Motor, Premium Male/Male Jumper Wires
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Schematics

PROJECT CİRCUİT

Code

PROJECT CODE

Arduino
/*
    Hello, welcome to my code world, my project today is the door security system project.
    I am writing the codes on the project myself,
    I may have deficiencies, you can correct me and improve me,
    thank you in advance.

    My nickname is gncmuh and my name is Sabri GENC

    Good work on your code world :)

*/

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <Wire.h>

Servo servo;
const byte servo_pin PROGMEM=3;
const byte rows PROGMEM=4;
const byte cols PROGMEM=4;

struct pins {
  const byte pinler[1]={2};
  byte row_pins[rows]={11,10,9,8}; 
  byte col_pins[cols]={7,6,5,4};
};
struct pins pin;
char key_board[rows][cols]={
  {'1','2','3','A'},          //A this character left direction  and  B this character right direction
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
LiquidCrystal_I2C lcd(0x27,16,2);
Keypad key=Keypad(makeKeymap(key_board),pin.row_pins,pin.col_pins,rows,cols);
char memory[4];
char direction_characters[4]={'<','>','N','Y'}; 
bool flag=false;
char incoming_key;
unsigned long timer=0;
byte counter=7; 
byte memory_counter=0;
char password[]="1998";  //  <-- In this project in real password
bool out_password=false;
void setup()
{
  Serial.begin(9600);
  Wire.begin(); 
  servo.attach(servo_pin);servo.write(0);
  screen_start();
}

void loop()
{
  screen_management();
  delay(1);
 
  
}
void screen_start() {
  if(!bool(0))
  {
    lcd.init();lcd.backlight();lcd.setCursor(1,0);
    lcd.print(F("GNCMUH PROTECH"));
    lcd.setCursor(4,1);
    for(int i=1; i<=8; i++) 
    {
      lcd.print(F("*"));delay(80); 
    }
    delay(1000);lcd.clear();
  }
}
void screen_management() {
  
  if(!bool(0))
  {
    if(flag==false)
    {
      first_page();
      flag=!flag;
    }
    if(flag==true)
    {
      here2:
      if(millis()-timer>2500)
      {
        timer=millis();
        lcd.setCursor(counter,1);lcd.blink();
      }
      incoming_key=key.getKey();
      lcd.setCursor(counter,1);
      if(incoming_key=='A' or incoming_key=='B' or incoming_key=='C' or incoming_key=='D')
      {
        if(incoming_key=='A') 
        {
          counter--;
          if(counter<6) counter=7;           
        }
        if(incoming_key=='B')
        {
          counter++;
          if(counter>8) counter=7;
        }       
        if(incoming_key=='D' and counter==8)
        {
          here:
          counter=7;
          lcd.clear();
          lcd.setCursor(0,1);lcd.print(direction_characters[0]);
          lcd.setCursor(6,1);lcd.print(direction_characters[2]);
          lcd.setCursor(8,1);lcd.print(direction_characters[3]);
          lcd.setCursor(15,1);lcd.print(direction_characters[1]);
          lcd.setCursor(1,0);
          lcd.print(F("ENTER PASSOWORD"));
          do
          { 
            incoming_key=key.getKey();
            lcd.setCursor(counter,1);
            if(incoming_key=='A')
            {
              counter--;
              if(counter<6) counter-=5;
              else if(counter==14) counter=7;
            }
            if(incoming_key=='B')
            {
              counter++;
              if(counter>8) counter+=6;
              else if(counter==1) counter=7;
            }
            if(incoming_key=='D' and counter==8)
            {
              second_page();
              if(atoi(memory)==atoi(password))
              {
                lcd.clear();lcd.print(F("CORRECT PASSWORD"));
                delay(500);lcd.clear();
                lcd.print(F("DOOR OPEN"));
                servo.write(90);
                delay(3000);
                lcd.clear();lcd.print(F("LOCKED"));
                delay(1000);
                first_page();
                goto here2;
              }
              else
              {
                lcd.clear();lcd.print(F("WRONG PASSWORD"));
                delay(1000);
                first_page();
                goto here2;
              }
            }
            if(incoming_key=='D' and counter==6)
            {
              first_page();
              break;
            }
            if(incoming_key=='D' and counter==15)
            {
              counter=7;
              lcd.clear();lcd.setCursor(1,0);
              lcd.print(F("CHANGE PASSWORD"));
              lcd.setCursor(0,1);lcd.print(direction_characters[0]);
              lcd.setCursor(6,1);
              for(int i=2; i<=3; i++)
              {
                lcd.print(direction_characters[i]);lcd.print(F(" "));
              }
              if(!bool(0))
              {
                while(true)
                {
                  incoming_key=key.getKey();
                  if(incoming_key=='A')
                  {
                    counter--;
                    if(counter<6) counter=0;
                  }
                  if(incoming_key=='B')
                  {
                    counter++;
                    if(counter>8) counter=7;
                    else if(counter==1) counter=7;
                  }
                  if(incoming_key=='D' and counter==0)
                  {
                     counter=7;
                     goto here;
                  }
                  if(incoming_key=='D' and counter==6)
                  {
                    counter=7;
                    goto here;
                  }
                  if(incoming_key=='D' and counter==8)
                  {
                    third_page();
                    delay(2000);
                    counter=7;
                    first_page();
                    goto here2;
                  }
                  lcd.setCursor(counter,1);
                  delay(1);
                }
                
              }
            }
            if(incoming_key=='D' and counter==0)
            {
              counter=7;
              first_page();
              break;
            }
            delay(5);
            
          }while(!bool(0));
        }
      }
    }
  }
}
void first_page() {
  servo.write(0);lcd.clear();
  lcd.setCursor(3,0);
  lcd.print(F("HOME PAGE"));lcd.setCursor(6,1);
  for(int i=0; i<4; i++) 
  {
    if(i!=2 and i!=3)
    {
      lcd.print(direction_characters[i]);lcd.print(F(" "));
    }
    delay(1);
  }
  lcd.blink();
}

void second_page() {
  lcd.clear();lcd.noBlink();
  lcd.setCursor(1,0);
  lcd.print(F("ENTER PASSWORD"));
  memory_counter=0;
  if(!bool(0))
  {
    while(memory_counter<4)
    {
      char incoming_character=key.getKey();
      if(incoming_character)
      {
        lcd.setCursor(memory_counter+5,1);
        lcd.print(F("*"));
        memory[memory_counter]=incoming_character;
        memory_counter++;
      }
      delay(1);
    }
    memory_counter=0;
    counter=7;
    delay(300);
  }
}
void third_page() {
  memory_counter=0;
  lcd.clear();lcd.noBlink();
  lcd.print(F("CURRENT PASSWORD"));
  while(memory_counter<4)
  {
      char incoming_character=key.getKey();
      if(incoming_character)
      {
        lcd.setCursor(memory_counter+5,1);
        lcd.print(F("*"));
        memory[memory_counter]=incoming_character;
        memory_counter++;
      }
      delay(1);
  }
  delay(300);
  if(atoi(password)==atoi(memory))
  {
    memory_counter=0;
    lcd.clear();lcd.setCursor(1,0);lcd.print(F("CORRECT PASSWORD"));
    delay(1000);
    lcd.clear();lcd.print(F("NEW PASSWORD"));
    while(memory_counter<4)
    {
      char incoming_character=key.getKey();
      if(incoming_character)
      {
        lcd.setCursor(memory_counter+5,1);
        lcd.print(F("*"));
        memory[memory_counter]=incoming_character;
        memory_counter++;
      }
      delay(1);
    }
    for(int i=0; i<4; i++)
    {
      password[i]=memory[i];
    }
    delay(300);
    memory_counter=0;
    delay(500);
    lcd.clear();lcd.setCursor(0,0);
    lcd.print(F("PASSWORD CHANGED"));counter=7;
  }
  else
  {
    lcd.clear();lcd.print(F("PASSWORD INCORRECT"));
    delay(1000);
    counter=7;
    first_page();
  }
}

Credits

Sabri GENÇ

Sabri GENÇ

0 projects • 0 followers

Comments