Introduction
In this article, I have explained about locking the door by keypad using
Arduino. Do not worry, it's easy to implement. If we have this setup then it can be used for home security. It can be used to open and close the door by password through the keypad.
Parts Of List
- Arduino
-
4*4 Matrix Keypad
-
Servo
-
2k ohm Resistor
-
Red Led
-
Green Led
-
Hookup wires.
Keypad
Figure 1: Keypad
-
It is a miniature keyboard.
-
This is the keypad of the 3*4 matrix.
-
It consists of buttons for operating a portable electronic device, telephone, or other equipment.
- The keypad consists of numeric numbers for the door password.
Servo
Figure 2: Servo
Connection From Keypad To Arduino
-
The connection from the * is to the digital pin 09,08 to the Arduino board.
-
The connection from the 0 is to the digital pin 07,06 to the Arduino board.
-
The connection from the # is to the digital pin 05,04 to the Arduino board.
-
The connection from the D is to the digital pin 03,02 to the Arduino board.
Connection From Servo To Arduino
Connection from LED to Arduino
-
The red led can be connected to the positive pin of digital pin 12 to the Arduino board and negative pin to the Gnd.
-
The green led can be connected to the positive pin of digital pin 11 to the Arduino board and negative pin to the Gnd.
Instruction
Before starting add the library of the following:
Programming
- #include < password.h >
- #include < keypad.h >
- #include < servo.h >
-
- password = Password("0000");
- const byte ROWS = 4;
-
-
-
- char keys[ROWS][COLS] =
- {
- {
- '1',
- '2',
- '3'
- },
- {
- '4',
- '5',
- '6'
- },
- {
- '7',
- '8',
- '9'
- },
- {
- '*',
- '0',
- '#'
- }
- };
-
-
- rowPins[ROWS] =
- {
- 9,
- 8,
- 7,
- 6
- };
- colPins[COLS] = {
- 5,
- 4,
- 3
- };
-
- Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
- void setup()
- {
- Serial.begin(9600);
- Serial.write(254);
- Serial.write(0x01);
- delay(200);
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- myservo.attach(13);
- }
- void loop()
- {
- keypad.getKey();
- myservo.write(0);
- }
-
- {
- switch (keypad.getState())
- {
- case PRESSED:
- Serial.print("Enter:");
- Serial.println(eKey);
- delay(10);
- Serial.write(254);
- switch (eKey)
- {
- case '*':
- checkPassword();
- delay(1);
- break;
- case '#':
- password.reset();
- delay(1);
- break;
- default:
- password.append(eKey);
- delay(1);
- }
- }
- }
- void checkPassword()
- {
- if (password.evaluate())
- {
-
- Serial.write(254);
- delay(10);
- digitalWrite(11, HIGH);
-
- digitalWrite(11, LOW);
- }
- else
- {
- Serial.println("Denied");
- delay(10);
- digitalWrite(12, HIGH);
-
- digitalWrite(12, LOW);
- }
- }
Explanation
-
This implementation can be used for home security by door locking using servo meter.
-
The programming will work in a way when the password is correct then the green light will turn on and the door opens.
-
When the password is wrong it can't open the door and the red led turn on.
-
You can also set the delay time for 5 seconds.
Read more articles on Arduino: