Custom Keypad with Display

Discussion in 'Embedded Systems and Microcontrollers' started by petro13, Aug 21, 2015.

  1. petro13

    Thread Starter New Member

    Aug 21, 2015
    Hi, i'm a complete novice regarding electronics, so please bear with me.
    I want to make a keypad with a display that will control an electronic lock. I'm talking about a typical 4x4 security keypad and a simple 4-digit display, but i want the keypad to act in a different way. For example, the unlocking code is 1234, but the code numbers (that will be displayed on the screen) will not correspond to the numbers on the keypad, instead they will follow different rules, for example: 1 = 8,2 pressed in succession, 2 = 6, 3 = 4,1,5 pressed in succession etc.
    I would like to know how hard would be to build such a device, and a general idea of how should i go about it, as i'm pretty sure i won't be able to do this myself.
    Thanks in advance.
  2. MaxHeadRoom


    Jul 18, 2013
    Should be fairly trivial for a μp such as a Picmicro a 1 line LCD display and 4x4 keypad.
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    Yeah, should be pretty easy with Arduino. Just take Arduino microcontroller+keypad+lcd. Microcontroller receives input from keypad, based on the input it produces user desired value (number or letter or whatever), then sends the value to the LCD.

    To produce desired value you will probably use several if statements.
    If 1 received from keypad, send 8 to lcd.
    If 2 received from keypad, send 6 to lcd.
    This is the logic of the operation, the code would look something like this:
    Code (Text):
    2. if(keypad_value==1) {lcd.print("8")}
    3. if(keypad_value==2) {lcd.print("6")}
  4. KerryJB

    New Member

    Dec 17, 2012
    Hello there Petro!

    Given the example you mentioned, it sounds like entering the full 4-digit unlocking code could result in as many as 12 digits being displayed on the screen. (Unless you're thinking of having the user-entered digits "scroll as you go" or something.) Does that sound right? If so, I suggest a 12x1 display like the KTM-S1201.

    From here on I'll assume that you plan to use an Arduino or other microprocessor...

    The key processing logic in your program could just store up all of the keystrokes until you hit a special key (like "#") to signal that the entry is complete. (You could even treat a key like "*" as a Backspace.) The logic could then examine the sequence of stored numbers and "translate" it to a sequence of a "unlocking digits". If the sequence can't be translated, or the translated value does not match the unlocking code, you could make a beeping sound or display an error message on the display, etc. (If you think you might get at all fancy with the display, I recommend upgrading to one with more lines. (See

    With things being so slow at work lately, I would be happy to "step through" this project with you. I have a whole stockpile of parts that I can't seem to get my Boy Scouts or other neighborhood kids to take an interest in, so I could probably supply most of what you need for my cost (plus shipping). Let me know!

    absf likes this.
  5. elec_mech

    Senior Member

    Nov 12, 2008
    Welcome to AAC.

    I helped someone here with a similar project using a PICAXE. Check out this post. Includes parts list, schematic, code, and PCB layout. It uses a four digit LED display from Adafruit. You'd just need to change the code to reflect different numbers for the key presses.

    Personally, I like PICAXE's over Arduino's because the code is easier to learn and understand, especially for those new to microcontrollers. However, I'm sure there are people here or on the Arduino forums if you decide to go that route instead.
  6. JohnInTX


    Jun 26, 2012
    @KerryJB @petro13 Welcome aboard!
    I don't know why but KerryJB's pic reminded me of a former client - He came by the office with a box full of just that kind of stuff saying 'Here. You shouldn't have to to charge me much since I've done the hard part for you.'
    I did say 'former client'.
  7. KerryJB

    New Member

    Dec 17, 2012
    After reading your explanation again, I see that I got things a little backwards. It sounds like you don't want to display the next digit on the display until a valid keystroke sequence has been detected. Thinking of it that way, the "4-digit display" makes sense. The user interface may be a little more tricky though.

    Say the user punches in
    8 ... 1 ... (oops, I meant to punch in "8 2") ... 8 ... 2 ...
    • Does the program "beep" as soon as the user punches in the 1, to let them know that "8 1" is an invalid sequence? (Providing "hints" like that could help a determined hacker eliminate a lot of invalid sequences quickly.)
    • With long-ish key sequences, the user can get lost more easily. Does it make sense to provide a Backspace key when they can't see what they've entered so far -- or would it be better to have a "start over on the current digit" key?
    The nice thing about using a microcontroller for projects like this is that you can often fix (or completely change) the underlying logic without having to desolder / rewire / resolder. Of course, micros come with their own challenges....
    absf likes this.
  8. jayanthd

    Active Member

    Jul 4, 2015

    I can do this with a PIC12F1840. It is an 8 pin microcontroller. I will write code in mikroC PRO PIC / AVR Compiler. I will use one ADC pin to interface 4x4 keypad. You will need 8 diff value resistors 1% type to convert 8 pin keypad to 1 pin ADC keypad. I will use I2C LCD 16x2 or 16x1 or 8x1. I have written the I2C LCD library for mikroC Compilers. If you want to use 8 pin keypad then also it is possible. I will use mikroC Keypad and my I2C LCD library. You will then need a 14 pin PIC microcontroller. 8 pins of the PIC goes for keypad, 2 pins for power supply, 2 I2C pins (software I2C can be used if HW I2C is not available in the PIC) for the LCD.
  9. BR-549

    Distinguished Member

    Sep 22, 2013
    I believe I would do it a little differently. I would connect the four horizontal keyboard wires to the first four inputs on port A. And connect the four vertical keyboard wires to the first four inputs on port B. (this can all be done on port A, but I want to eliminate any confusion)

    I would use these 2 bit patterns to index a 4X4 memory array that contains the characters of the key.

    Then I would set up an interrupt to occur with any change on the first four input pins on port A.

    The interrupt will read both ports.......go to specified array location, and send character to display.

    Now you have a regular keyboard and display.

    Now you can write and add a security subroutine to the regular keyboard routine.

    For instance, you could check for characters, like say for 4, 8s then 4, 4s in a lock the keyboard.

    And another routine where only 9, 9s will unlock it.

    You could add second functions to the keyboard too.

    Just an idea.
    absf likes this.
  10. petro13

    Thread Starter New Member

    Aug 21, 2015
    Thank you all for your replies.

    You got it pretty much right, except that i'm expecting the program to beep only on valid sequences, and yes, a restart button is preferred.
    Giving hints is not a problem as the purpose of the keylock is not security, i actually plan to incorporate it in an interactive game.
  11. Art

    Distinguished Member

    Sep 10, 2007
    Pick a micro controller and commit!
    Once you can properly scan a keypad and do a display, you’ll most likely be able to do the rest.
    It’s just a matter of which micro, and this is a job suitable for even the cheapest and simplest.

    A lot of development boards have keypads and displays and some outputs,
    so you’d probably get away with doing no electronics at all for a one off unit.

    Everyone has an opinion about which micro to use, but that’s no so important.
    (and secretly everyone knows that pics are the best :D )

    Generally you’d rotate a full code into a buffer and check all digits once the
    enter key is pressed so as not to give the code away with timing and power attacks.
    absf likes this.