Keypad Door Lock

Figure 3. Keypad Door Lock


1. Designing the circuit
Design the circuit as shown  using Proteus 8. We  need  to select below  components.
i. Arduino Pro Mini
ii 4x4 Keypad
iii.Servo Motor
iv. LEDs
v. Resistors


2. Write the program
 Write the  program as shown using Arduino IDE. But before that you needed to download the required Arduino Libraries

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

Servo myservo;
// set LED
int LED_G=12;
int LED_R=13;

//set password
char* passcode="1234";
int currentPossition=0;

//define keypad
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {5,4,3,2}; //Rows 0 to 4
byte colPins[numCols]= {6,7,8,9}; //Columns 0 to 4

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
pinMode(LED_G,OUTPUT);
pinMode(LED_R,OUTPUT);
digitalWrite(LED_R,LOW);
digitalWrite(LED_G,LOW);
myservo.attach(11);
myservo.write(0);

}


void loop()
{

char keypressed = myKeypad.getKey();

if (int(keypressed)!=0){
  if (keypressed== passcode[currentPossition]){
    ++currentPossition;
  
    if (currentPossition==4){
      digitalWrite(LED_G,HIGH);
      delay(500);
      digitalWrite(LED_R,LOW);
      delay(500);
      myservo.write(170);
      currentPossition=0;

    }
  }
  else {
    digitalWrite(LED_R,HIGH);
    delay(500);
    digitalWrite(LED_G,LOW);
    delay(500);
    myservo.write(10);
    currentPossition=0;
    }
}

}




3. Simulate the circuit
After placing all the components on the Proteus it should be wired as shown in Figure 3.1 Red and Green LEDs are connected to pin no 13,12 accordingly. Servo motor  wires should connected to the following pins of Arduino mini pro. Orange -pin D11 (Data), Red -  Vcc pin (+) and Brown - GND pin (-). The actual keypad i used is slightly different than the keypad which is available in Proteus. The data signal should be connected to a PWM of arduino to rotate the motor according to the given angle.

Note - 1 , 2 , 3 , 4 keys of actual keypad will be replaced by ON/C , 0 , = , 1 of Proteus keypad

Rows and Columns are connected with digital pis D2, D3,D4,D5,D6,D7,D8, D9.




before simulate
when correct keys are pressed
when wrong key is pressed


4. Bred board Circuit


5. PCB Design and Populate


6. Fix it in to a proper housing

No comments:

Post a Comment