STEMpedia
Published © CC BY

Password Protected Door Locking System

This project will show you how to make your own password-based door lock.

IntermediateFull instructions provided4 hours860
Password Protected Door Locking System

Things used in this project

Hardware components

evive
STEMpedia evive
×1
evive IoT Kit
STEMpedia evive IoT Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram

Code

Arduino Code for the Door Locker

Arduino
#include <Adafruit_NeoPixel.h>
#include<evive.h>
#include<Keypad.h>

void(* resetFunc)(void) =0;

// neo pixel init

#ifdef __AVR__
  #include <avr/power.h>
#endif

#define number_of_neo_pixel 4

unsigned int  neo_pixel_pin= 10;


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(number_of_neo_pixel,neo_pixel_pin, NEO_GRB + NEO_KHZ800);

// keypad init
const byte ROWS = 4;       //four rows
const byte COLS = 4;      //four columns

char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {6, 7, 8,9}; //connect to the column pinouts of the kpd

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// solenoid lock init
int lockbuttongnd = 28;
int lockbuttoncontrol = 29; 
int lockenable=44;

char key =0;
int check =0;
unsigned int temp =1;

char password[4] = {'1', '2', '3', '4'}; //Any password must have 4 digits      
char inputCode[4] = {'0', '0', '0', '0'};

void setup()
   {
      // put your setup code here, to run once:
  
      Serial.begin(9600);
      pixels.begin(); // This initializes the NeoPixel library
      pixels.show();
    
      // lock button initialization
    
       pinMode(lockenable,OUTPUT);
       pinMode(lockbuttongnd,OUTPUT);
       pinMode(lockbuttoncontrol,OUTPUT);
        
       analogWrite(lockenable,255);
       digitalWrite(lockbuttongnd,LOW);
       digitalWrite(lockbuttoncontrol,LOW);

       tft_init(INITR_BLACKTAB);
       tft.setRotation(1);
       tft.fillScreen(ST7735_BLACK);

       start_screen();

  }

void loop()
   {
       // put your main code here, to run repeatedly:
       if(temp ==1)
          {
             Serial.println(" ENTER PASSWORD");

        tft.setCursor(40,75);
        tft.setTextSize(1);
        tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
        tft.print("ENTER PASSWORD     ");  
             
             temp=2;
             for(unsigned int i=0;i<4;i++)
                {
                   pixels.setPixelColor(i,pixels.Color(150,150,150));
                }
             pixels.show();
             delay(2000);
              for(unsigned int i=0;i<4;i++)
                {
                   pixels.setPixelColor(i,pixels.Color(0,0,0));
                }
             pixels.show();
             
          }
       key = keypad.getKey();

       if(key)
          {
              inputCode[check++] = key;
              pixels.setPixelColor(check-1,pixels.Color(0,0,150));
              pixels.show();
       
          }

        if(check==4)
        {
          check =0;
          delay(200);
          char password[4]= {'1','2','3','4'};

          if((strncmp(inputCode,password,4)==0))
          {
            Serial.println(" access granted ");
            for(unsigned int i=0;i<4;i++)
            {
               pixels.setPixelColor(i,pixels.Color(0,150,0));
            }
            pixels.show();
            digitalWrite(lockbuttoncontrol,HIGH);
            tft.setCursor(40,75);
            tft.setTextSize(1);
            tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
            tft.print("ACCESS GRANTED     ");  
             
            delay(3000);
            resetFunc();
           
          }
          else
          {
            Serial.println(" access denied ");
            tft.setCursor(40,75);
            tft.setTextSize(1);
            tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
            tft.print("ACCESS DENIED       ");  
             
            for(unsigned int i=0;i<4;i++)
            {
              pixels.setPixelColor(i,pixels.Color(150,0,0));
            }
            pixels.show();
            delay(3000);
             for(unsigned int i=0;i<4;i++)
            {
              pixels.setPixelColor(i,pixels.Color(0,0,0));
            }
            pixels.show();
            check=0;
            temp=1;
          }
        }

   }
void start_screen()
    {
        tft.fillScreen(ST7735_BLACK);

        tft.setCursor(25,10);
        tft.setTextSize(2);
        tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
        tft.print("STEMpedia");

        tft.setCursor(28,35);
        tft.setTextSize(1);
        tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
        tft.print("KEYPAD SAFE LOCKER");

        tft.setCursor(60,60);
        tft.setTextSize(1);
        tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
        tft.print("STATUS");  

        tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
        tft.setCursor(0,105);
        tft.setTextSize(1.8);
        tft.print("FOR MORE INFORMATION VISIT");
        tft.setCursor(30,115);
        tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
        tft.print("thestempedia.com");
        
    }
   

evive Library

C/C++
No preview (download only).

Credits

STEMpedia
42 projects • 170 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.
Contact

Comments

Please log in or sign up to comment.