loading

Do you want to lock your things?

Then this is the choice for you.

You can use a 1 digit pin "code" to 9 digit pin code!

I think that the 9 digit is pretty over reacting but nothing is too safe today.

Watch the video to see how it work's.

Mobile user's go to HERE to see the video right.

Step 1: Parts

You will need Intel Edison (basically any Arduino board should work.), Two led's, some wire, LCD screen and a keypad.

First thing you want to do is to assemble the keypad and figuring out what pin does what. My keypad can and pretty sure it will be different than you might have.

Step 2: Keypad Soldering and Pin Out

First thing that you might want to do is to solder the pins to the keyboard.

To figure out the pin out you will need something to measure the connection. I used a typical ohmmeter to get the reading.

First you need to get a piece of paper and draw the right hand diagram as you see it in the picture 4.

Next, you are going to use your Ohm meter to find out which pins are connected to which keys.

You say WHAAAAT?

1. Connect your Ohm meter leads to pins 1 and 2.

2. Press all the buttons one at a time until you see change in your meter.

3. Write down the pin numbers next to the column and row for the key you just found. For example in the picture 6 you can see that number 1=pin3+pin2. Repeat this with all the pins until you are in the clear with all the buttons.

4. Once you have completely identified all the pins on the diagram then you can just ignore any unused keypad pins since they are not in use. Now follow to the next step to connect it to the Edison

Step 3: Connecting and Testing

Firstly find a library for the keypad since you will be needing it.

The library includes a test code so you can test the keypad.

My connection to the Edison was this.

Edison to keypad

8---------------3

7---------------1

6---------------5

5---------------2

4---------------7

3---------------6

2---------------4

Now test the keypad by uploading the code to the board and turn on the serial monitor. When button is pressed it will show the correct number after pressing the button. If not, i suggest to redo the wiring and measuring.

Step 4: Coding and Final Component Setup.

I connected the LCD display to Edison's connector shield I2C port and the led's to pin13 and pin12

Where green is pin13 and red is pin 12.

And of course the green means open and red closed.

It's easy to change the led's for a relay or a servo motor for example. The led's just indicate whenever there is current or not.

Now for the code.

First definition of the library's and global variables.

This is where you can change the password for anything you like. to change the password simply modify the "Password password = Password("1234"); " to something else like Password("1230985");

#include

#include
#include
#include "rgb_lcd.h"
rgb_lcd lcd;
Password password = Password("1234");

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte greenLed = 13;
byte redLed = 12;

Then do the setup.

void setup(){

lcd.begin(16, 2);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, LOW);
Serial.begin(115200);
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(10);
}

And the loop.

void loop(){
keypad.getKey();

lcd.setCursor(0,0);
lcd.print("Enter pincode");
digitalWrite(redLed,HIGH);

}

Lastly we need to make few event's that you can use in the loop

void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.setCursor(0,1);
lcd.print(eKey);
Serial.print(eKey);
switch (eKey){
case '#': guessPassword();
break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){

digitalWrite(redLed, LOW);
lcd.setCursor(0,0);
lcd.print(" ");
digitalWrite(greenLed,HIGH);
lcd.setCursor(0,0);
lcd.print("Correct.");
Serial.println("Correct.");
lcd.setCursor(0,1);
lcd.print("Unlocked");
password.reset();

delay(10000);
digitalWrite(greenLed,LOW);
lcd.clear();
}

else{
digitalWrite(greenLed, LOW);
digitalWrite(redLed,HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wrong code");
lcd.setCursor(0,1);
lcd.print("Try again.");
Serial.println("Try again");
digitalWrite(redLed, LOW);
delay(100);
digitalWrite(redLed, HIGH);
delay(100);
digitalWrite(redLed, LOW);
delay(100);
digitalWrite(redLed, HIGH);
delay(100);
digitalWrite(redLed, LOW);
delay(100);
digitalWrite(redLed, HIGH);
delay(100);
digitalWrite(redLed, LOW);
delay(100);
digitalWrite(redLed, HIGH);
delay(100);
password.reset();
delay(1000);
lcd.clear();
}
}

Step 5: Test the Lock

That's it. You have now done keypad mapping and some simple coding. Good.

Show of your skills and setup a game where you can set the password and others can guess it.

Or hook up a relay and make it to a real life lock. This is pretty much secure as it can be.

Thank you for reading. I hope you liked my project.

In case that you liked it be sure to read my other project's also!

Just click on that funny looking dog and start browsing.

And also click follow to make sure you have the project's first!

Remember to watch the video on the first step about how the lock works in real.

Happy builds!

About This Instructable

2,260views

44favorites

License:

Bio: I am 26 years old engineering student from Oulu in Finland. Currently living in Joensuu. I make these projects as a hobby, and it would ... More »
More by mkarvonen:PipBoy 3000 (working) DIY Piranha Plant Photo(s) to 3D model 
Add instructable to: