Introduction: Microcontroller's Based Password Locker

Hello Everybody , the goal of this instructables is to learn how to do a simple locker for your room, or anything which need to be safe.

I've made it on a non-soldering card but there is the PCB if you want to make it ! 

Here is the list of differents components that we will need:

- A Microchip microcontroller 16F88 (but all mid-range of microchip will be good)

- Some wires

- 2 LEDs (a green for granted access and a red for denied access, i'm using a pcb with 3 leds the third if when the keypad wait)

- A keypad 3x4 (I'm using an old one but you will find it in every electronics shop)

- 3 Pull-up resistor 47Kohms (needed to make a logical "low")

- 2 resistors for the Leds (221 ohm will be enough)

- A 9 V battery (with the connector) and a regulator MCP 1702 (from microchip)

- 4 capacitors 100µF 16V / 10µF 16V / 100nF / 100nF

- A way to program the 16f88 ( like https://www.instructables.com/id/All-pic-programmer/ or buy a pickit http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010053 )

(The components like the 16F88 and the MCP 1702 can be obtained by asking samples from microchip)

OPTIONAL : A multimeter to test the circuit.
                      Other components if you want to had a sound when the code is wrong (like a buzzer)

So if you're ready , Let's Go ! 

Step 1: The Regulator Parts

We need to build the regulator part which will power the microcontroller !

So take the following components : 

- MCP 1702 Regulator

- The 4 capacitors (100nF, 100nF , 10µF 16V , 100µF 16V)

- Some little wires

- The male connector

- The battery connector

And finally the non-soldering board (or something similar)

------------------------------------------------------------------------------------------------------------

At first place the MCP on the board, like on the picture,
then put the 4 capacitors between the Vin and the Ground,the Vout and the ground following the schematics.

Now just put the +5V away with a wire, we will connect it to the microcontroller later.

Step 2: The Keypad

Now that we have our power supply for the microcontroller we need to know how to put the keypad. 

Keypad can be used with a decoder to know the number of the key pressed but I've choosed to do it by programmation, so it's simple because it's similar with a simple push button.

As you can see, the keypad is divided in columns (X1 X2 X3) and lines (Y1 Y2 Y3 Y4)
I know that every keypad are different so check the datasheet to see how the wire are soldered.

On this keypad the 7 wires at the bottom correspond to the 4 lines and the 3 column ! 

Even if yours isn't the same, the principle is the same ! 
(Picture 1)

So now we will choose the different Input/output of the microcontroller :


My choice was made for the non-soldering board so I choosed I/0 wich are close,
Pin B7 <-> Y1
Pin B6 <-> Y2
Pin B5 <-> Y3
Pin B4 <-> Y4

Pin A0 <-> X1
Pin A7 <-> X2
Pin A6 <-> X3

Let's check the picture of the microcontroller. (Picture 2)

So the board will be like that. (Picture 3)
If you didn't understand how to do it just check this schematic (picture 4)

Step 3: Power the Microcontroller and Put the Leds

In this part, we have to put 3 wires,on the picture the red is the +5V, blue is the ground and the green is for desactivate the reset, even if you don't use THIS microcontroller you'll have to put this 3 wires . (picture 1 & 2)

After that we need to connect the leds. Let's see the pictures 3, 4, 5 & 6.

If you don't really see how to connect these wire, see the schematic (picture 7).

Step 4: Let's Do Some Programming

So now that we have the circuits, the hard work is there ^^ !

I'm using a pic 16F88 from microchip so I will use the MPLAB IDE to program, the language used is the C, MPLAB need a special compiler (shareware) named CCS but you can write the program in assembler (i'm not gonna teach how to do it in asm).

 Here is the fonctions and the several definition of each lines :

#include <16F88.h>
#fuses INTRC,NOPROTECT,NOWDT,NOLVP
#use Delay(Clock=4000000)

#define Y1 pin_B7
#define Y2 pin_B6
#define Y3 pin_B5
#define Y4 pin_B4

#define X1 pin_A0
#define X2 pin_A7
#define X3 pin_A6

#define LED_OK pin_A1
#define LED_NO pin_A2

#define A 10
#define ZERO 11
#define B 12

int L1=0,L2=0,L3=0,L4=0;

void Clavier()
{
L1=0;L2=0;L3=0;L4=0;
output_high(Y1);
output_low(Y2);
output_low(Y3);
output_low(Y4);


if (input(X1))
{
L1=7;
}
else if (input(X2))
{
L1=8;

}
else if (input(X3))
{
L1=9;
}


output_low(Y1);
output_high(Y2);
output_low(Y3);
output_low(Y4);


if (input(X1))
{
L2=4;
}
else if (input(X2))
{
L2=5;
}
else if (input(X3))
{
L2=6;
}


output_low(Y1);
output_low(Y2);
output_high(Y3);
output_low(Y4);


if (input(X1))
{
L3=1;
}
else if (input(X2))
{
L3=2;
}
else if (input(X3))
{
L3=3;
}

output_low(Y1);
output_low(Y2);
output_low(Y3);
output_high(Y4);


if (input(X1))
{
L4=A; //Lettre A
}
else if (input(X2))
{
L4=ZERO; //chiffre 0
}
else if (input(X3))
{
L4=B; //Lettre B
}



}


void Code()
{

if(L1==7 && L2==5 && L3==2 && L4==A)
{
output_high(LED_OK);
output_low(LED_NO);
L1=0;L2=0;L3=0;L4=0;
delay_ms(1000);
output_low(LED_NO);
output_low(LED_OK);
}
else if (L1==0 || L2==0 || L3==0 || L4==0)
{
output_low(LED_NO);
output_low(LED_OK);
}
else if (L1!=7 && L2!=5 && L3!=2 && L4!=A)
{
output_high(LED_NO);
output_low(LED_OK);
delay_ms(1000);
output_low(LED_NO);
output_low(LED_OK);
L1=0;L2=0;L3=0;L4=0;
}

}



And here we have the main program which call the fonction that we seen 

#include "fonctions.h"


void main()
{


 while(1)
 {
Clavier();
Code();

 }

}

We read the keypad, each line by each line and then we search if the code is the right one ! 


That's all Folks !!! 
Good luck 


Microcontroller Contest

Participated in the
Microcontroller Contest