5×4 20 Key Matrix Keyboard Electronic Lock

20 key keypad

The code for this project can be found on my GitHub page here.

See also the post describing the simple program to read this keypad here.

This project illustrates the use of the 20 key matrix keyboard shown in an earlier blog here. These keyboards can be obtained on eBay, often for £1 but don’t lend themselves to being used for calculators. However, they make an ideal data entry pad for something like an electronic lock.

I have chosen not to include any electronics such as relays or servo motors as these can easily be added to suit the individual needs. There are two locks, each with their own password, selected by pressing either F1 or F2. The password is a four digit number, although it can be increased by changing the variable maxNumber. Other non digit keys (except for the arrow keys) have various functions. Ent is used to lock the current Lock. Esc will abort code entry in the case that a wrong digit was entered (this could be useful if the number of incorrect code entries is limited before no further entries were allowed). # will show the current state of both locks and finally * will lock both locks at once, regardless of their current state.

The output is sent to the Serial Monitor and the on board LED is lit if the current Lock is closed.

The circuit:

The connection diagram is shown below, the keyboard uses nine digital pins and pin 13 is used to show the status of the current lock. This leaves two digital pins and the four Analog pins to operate relays, servo motors etc. Connection data is provided in the sketch.

One thought on “5×4 20 Key Matrix Keyboard Electronic Lock”

Leave a comment