Hello makers. Today i will be showing you how to make a keypad combination lock. This keypad has a clear button as well as the ability to change the combination without reprogramming the Arduino. After testing, this combination lock is foul-proof, unless you break the circuit (DUH!!). So let's get building.

Step 1: Parts and Libraries

To make this project, you need:

- An Arduino.

- An LCD display(this code is for a 16*2 LCD).

- A 4x4 Keypad

- Potentiometer(i used a 50k pot)

- Green and Red LED(Or you can program the output to do anything)

- 220 or 270 ohm resistor.

For the libraries, you need:

- Keypad Library: http://playground.arduino.cc/Code/Keypad

-LCD library: Included with the IDE.

Step 2: Circuitry

Just make the circuit by following the schematic above. There is also a download for the Fritzing file if you can't comprehend the schematic from the image.

Step 3: Code and Customizing It

Here is the code for this project. The default combination is 1-2-3-4. To customize this from the code, you edit the array called "rightnumber". You need to put it the number in decimal ASCII. This is because of how my code and the keypad library works. To edit the amount of numbers in the combination, you edit the variable called "combinationlenght". Just make sure your combination length isn't over 14 digits, as the code isn't programmed to handle such length. Also make sure the combination length provided matches with the amount of number in the "rightnumber" array, as not doing so will mess up the program. If you want custom actions for the right and wrong combination, there is a void at the end of the code called "rightaction" and "wrongaction".

Step 4: Usage

You type the combination by pressing the key one by one like you would in a normal lock. A * should pop up every key press. If it doesn't press that key again. To clear the written number(if you got something wrong), press the D key. If you get the combination right or wrong, press D to go the the home screen and be able to type the combination again. This will also turn off the LED. If you get the combination right, you can press C to change the combination without having to reprogram the Arduino. Simply, after pressing C, type in your combination. Again you can use the D key to clear the written number if you typed in the wrong thing. One the number of key presses reaches the combination length, it will ask you if your sure. To say yes(changing the combination to the one you inputed) and return to the home screen, press A. If you don't want to change it(maybe you accidentally pressed the wring key), press B. This will return to the right combination screen, meaning you have the press C to change the combination or press D to go to the home screen.

Step 5: The End and Future Plans

If you followed the steps correctly, you have successfully made a combination lock. For the future of this project, if there is enough demand or if i just want to it, i will make V2 with more features(maybe add a remote control access i don't know). If you guys find a bug in this code, please tell inform me so i could fix it. If you guys want i could potentially make a video explaining how this project works and the code(how it works and how to customize it). Last, if you guys have an idea for a future projects, leave them bellow. Have fun

<p>I modified the code a bit to work with 4x3 keypads. I also added an rgb led that has 3 states. </p><p>Red= Access Denied</p><p>Green = Access Granted</p><p>Blue = Code change</p><p>I also added an unlock function with a transistor, as seen turning on the board on the right. </p><p>Here's a video of it in action. https://www.youtube.com/watch?v=BzLH9g0wG1E</p><p>The * key is used to change the code and accept. The # sign is used for home. or back if at the code change screen. </p><p>//Begin code: #include&lt;Keypad.h&gt;<br>#include &lt;LiquidCrystal.h&gt;<br><br>const int combinationlenght = 6;<br>int rightnumber[combinationlenght] = {49, 50, 51, 52, 53, 54};//this codes for 1,2,3,4 in ASCII. Had to use it because the library stores the input in decimal ASCII intead of a number.<br><br><br>int newrightnumber[combinationlenght];<br>char number[combinationlenght];<br>int right = 0;<br>int unlock = 2;<br>int green = A1;<br>int red = A2;<br>int blue = A3;<br>int newcomb = 0;<br>byte fulllcd[8] = {B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111,};<br>int newfinalcomb = 0;<br>int kposition = 0;<br>const byte ROWS = 4; //four rows<br>const byte COLS = 3; //four columns<br>char keys[ROWS][COLS] = {<br> {'1','2','3'},<br> {'4','5','6'},<br> {'7','8','9'},<br> {'*','0','#'}<br>};<br>byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad<br>byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad<br><br>Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );<br>LiquidCrystal lcd(13,12,11,10,1,0);<br>void setup() {<br> off();<br> // put your setup code here, to run once:<br> // Serial.begin(9600);<br> pinMode(A1,OUTPUT);<br> pinMode(A2,OUTPUT);<br> pinMode(A3,OUTPUT);<br> pinMode(2,OUTPUT);<br> lcd.createChar(0, fulllcd);<br> lcd.begin(16,2);<br> lcdstartup();<br>}<br><br>void loop() {<br> // put your main code here, to run repeatedly:<br> char k = keypad.getKey();<br> if(k != 0){ //if you press something<br> if(k == 68){<br> kposition = 0;<br> lcdstartup();<br> <br> }<br> else{<br> number[kposition] = k; //save number in array<br> kposition++; //add to the combination digit position<br> lcd.setCursor(kposition - 1,1);<br> lcd.print(&quot;*&quot;); //writes a * each time you enter in a charcter<br> delay(50); //delay just cause i can<br> if(kposition == combinationlenght){ //checks if we pressed 4 numbers<br> kposition = 0; //sets array write position to 0<br> for(int g=0;g&lt;combinationlenght;g++){//if each digit is right, add to the variable &quot;right&quot;<br> if(number[g] == rightnumber[g]){ right++;} //checks if all inputed digits are right<br> }<br> if(right == combinationlenght){<br> rightaction();<br> rightlcd();<br> right = 0;<br> }<br> else{<br> wrongaction();<br> wronglcd();<br> right = 0;<br> }<br> delay(100);<br> }<br> }<br> }<br>}<br>void lcdstartup(){<br> lcd.clear();<br> lcd.setCursor(0,0);<br> lcd.print(&quot;Combination :&quot;);<br> <br>}<br>void lcdenter(){<br> lcd.clear();<br> lcd.print(&quot;Enter new :&quot;);<br>}<br>void lcdgranted(){<br> lcd.clear();<br> lcd.print(&quot;*****ACESS******&quot;);<br> lcd.setCursor(0,1);<br> lcd.print(&quot;****GRANTED*****&quot;);<br>}<br>void rightlcd(){<br> lcdgranted();<br> while(newfinalcomb == 0){<br> delay(10);<br> char o = keypad.getKey();<br> if(o != 0){<br> if(o == 42){<br> digitalWrite(green,HIGH);<br> digitalWrite(unlock,LOW);<br> lcdenter();<br> while(newcomb == 0){<br> enternewcode();}<br> newcomb = 0;<br> }<br> if(o == 35){<br> newfinalcomb = 1;<br> digitalWrite(green,HIGH);<br> digitalWrite(unlock,LOW);<br> }<br> }<br> }<br> newfinalcomb = 0;<br> lcd.clear();<br> lcdstartup();<br>}<br>void enternewcode(){\<br>codeentry();<br> char newk = keypad.getKey();<br> if(newk != 0){<br> newrightnumber[kposition] = newk;<br> kposition++;<br> lcd.setCursor(kposition,1);<br> lcd.print(newk);<br> if(newk == 42){<br> lcd.setCursor(0,1);<br> lcd.print(&quot; &quot;);<br> kposition = 0;<br> }<br> if(kposition == combinationlenght){<br> lcd.setCursor(kposition + 1,1);<br> lcd.write(byte(0));<br> delay(1000);<br> kposition = 0;<br> checknewcode();<br> digitalWrite(blue,HIGH);<br> }<br> }<br>}<br>void checknewcode(){<br> lcd.clear();<br> lcd.print(&quot;Are you sure ?&quot;);<br> while(newcomb == 0){<br> char newc = keypad.getKey();<br> if(newc != 0){<br> if(newc == 42){<br> lcd.clear();<br> lcd.print(&quot;New code&quot;);<br> lcd.setCursor(0,1);<br> lcd.print(&quot;Accepted&quot;);<br> newcomb = 1;<br> newfinalcomb = 1;<br> for(int j=0;j&lt;combinationlenght;j++){<br> rightnumber[j] = newrightnumber[j];<br> }<br> kposition = 0;<br> delay(1500);<br> }<br> if(newc == 35){<br> delay(10);<br> lcdgranted();<br> newcomb = 1;<br> }<br> }<br> }<br>}<br>void wronglcd(){<br>lcd.clear();<br> lcd.print(&quot;*****ACESS******&quot;);<br> lcd.setCursor(0,1);<br> lcd.print(&quot;*****DENIED*****&quot;);<br> while(newfinalcomb == 0){<br> delay(10);<br> char o = keypad.getKey();<br> if(o != 0){<br> if(o == 35){<br> newfinalcomb = 1;<br> }<br> }<br> }<br> newfinalcomb = 0;<br> lcd.clear();<br> lcdstartup();<br> digitalWrite(red,HIGH);<br>}<br><br>void rightaction(){<br> digitalWrite(green,LOW);<br> digitalWrite(unlock,HIGH);<br> digitalWrite(red,HIGH);<br>}<br>void codeentry(){<br> digitalWrite(green,HIGH);<br> digitalWrite(blue,LOW);<br> digitalWrite(red,HIGH);<br>}<br>void wrongaction(){<br> digitalWrite(red,LOW);<br> digitalWrite(green,HIGH);<br>}<br>void off(){<br> digitalWrite(green,HIGH);<br> digitalWrite(blue,HIGH);<br> digitalWrite(red,HIGH);<br><br>}<br>//End Code</p>
<p>Oh. Very nice. Sorry I've been inactive for a while. I like the addition of the unlock function and the ribbon cable on the LCD. </p>
<p>Cool way to make a DIY security system</p>
<p>Thanks :)</p>
<p>Cool way to make a DIY security system</p>

About This Instructable




More by Electro_Dynamic:Keypad Combiation 
Add instructable to: