Introduction: Coding a Keypad
The objective of this project is to take a keypad and code it in such a way that it responds to a certain password which would be pre set in the code itself. I will then use this keypad to place on a pre made model safe. The objective of the project is to have the safe open if and when the right password is typed in. To help make this project I will be using an Arduino to help code the keypad. This way I will be able to set my own password and then have the Arduino perform any command I chose. I am really excited for this project, and am confident that it will work out well.
Step 1: Materials
The following are the material that I would require in order to complete the project.
- Arduino- 1
- Keypad- 1
- Servo Motor
- Arduino wires
- Breadboard
- Laptop (with Arduino application installed)
Step 2: Coding the Keypad
The most important step of this project is to code the keypad in such a way that a computer can read which numbers are being inputted and then tell another source whether it is the correct or incorrect password. For this project I am using Arduino, therefore I used some online resources to try to understand how to wire and then code the keypad to fit the above listed requirements. What I found on the net was that I would have to wire each output on the keypad to a pin number on the Arduino and then the ground output on the keypad to ground on the Arduino. The code I used is attached in the pictures. This code allows the computer to read what numbers are being punched in as well as determine whether the password is right or wrong.
Step 3: Attaching the Servo Motor
Having the computer read inputs and thus determine whether a password is right or wrong is one thing, but then having it perform an action after that would really be cool! In order to achieve this we hooked up a servo motor to the Arduino. The outer most output on the servo goes to 5V whereas the other two go to pin numbers (you can use pins a0 and a1 incase you run out due to the keypad). Once this is done, you put down in your code how much you want the motor to rotate depending on whether a correct or incorrect password is typed in. The code for this is provided in the pictures.
Step 4: EXTRA- Hooking It Up to a Safe
Now that the mechanism is functional, I thought I could take this project a step further by attaching it to an object such as a safe to see if my project can help control the opening and closing of it. I got my hands on a ready made cardboard safe (a school mate of mine had made (Cardboard Safe)) which essentially had a box with a strip of cardboard that would move in and out therefore controlling the possibility of opening or closing the safe. I decided to attach the servo motor to that cardboard strip- which would then control the movement of the strip hence the opening and closing of the safe.
2 Comments
Question 2 years ago on Step 4
Hi i am currently making this but having some trouble.Youll notice some slight changes to yours. My output keeps coming out as:
3
33
333
3333
Wrong Password,
This keeps happening on loop.
Any way you can send me the arduino file? i think in your pictures you are missing a closing bracket at the very end. Thanks
int keys[12];
int currentInput;
String password = "1274";
String current = "";
const int Buzzer = 13;
void setup() {
Serial.begin(9600);
const int Buzzer = 13;
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(Buzzer,OUTPUT);
}
void loop() {
/* int star = digitalRead(2); // keypad pin 2
int seven = digitalRead(3); // keypad pin 3
int four = digitalRead(4); // keypad pin 4
int one = digitalRead(5); // keypad pin 5
int zero = digitalRead(6); // keypad pin 6
int eight = digitalRead(7); // keypad pin 7
int five = digitalRead(8); // keypad pin 8
int two = digitalRead(9); // keypad pin 9
int pound = digitalRead(10); // keypad pin 10
int nine = digitalRead(11); // keypad pin 11
int six = digitalRead(12); // keypad pin 12
int three = digitalRead(13); // keypad pin 13
*/
for (int i=0; i<12; i++)
{
keys[i] = digitalRead(i+2);
}
for (int i=0; i<12; i++)
{
if (keys[i] == 0)
{
switch(i)
{
case 0: current = current + "*"; break;
case 1: current = current + "7"; break;
case 2: current = current + "4"; break;
case 3: current = current + "1"; break;
case 4: current = current + "0"; break;
case 5: current = current + "8"; break;
case 6: current = current + "5"; break;
case 7: current = current + "2"; break;
case 8: current = ""; break;
case 9: current = current + "9"; break;
case 10: current = current + "6"; break;
case 11: current = current + "3"; break;
}
delay(300);
Serial.println(current);
}
if(current.length() == password.length())
{
if(current == password)
{
Serial.println(" Right Password");
current = "";
digitalWrite(Buzzer,HIGH);
delay(2000);
digitalWrite(Buzzer,LOW);
}
else
{
Serial.println("Wrong Password");
current = "";
digitalWrite(Buzzer,HIGH);
delay(250);
digitalWrite(Buzzer,LOW);
delay(250);
digitalWrite(Buzzer,HIGH);
delay(250);
digitalWrite(Buzzer,LOW);
}
}
}
}
Answer 9 months ago
You set your "Three" digital read to pin 13, which you previously defined as an output for the buzzer rather than an input