Need help on Matrix Keypad Interface Logic

Discussion in 'General Electronics Chat' started by Parth786, Jun 25, 2017.

  1. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    I am looking help on matrix keypad. I searched on internet and having difficulty to understand logic of matrix keypad. Matrix keypad use a combination of four rows and four columns to provide button states to the device ( microcontroller). Each key is a push button, with one end connected to one row, and the other end connected to one column.
    keypad.jpg
    this is component from Proteus. I was looking datasheet but I couldn't found. How does keypad work with microcontroller. what is basic logic of Matrix keypad?
     
  2. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    9,737
    2,351
    The micro writes a given logic level to each column (or row) in turn and, while the written-to column (or row) is held at that logic level, reads each row (or column) in turn to determine which one or more has that logic level.
     
  3. Sensacell

    Moderator

    Jun 19, 2012
    2,343
    751
    It's a scanning process, the switches are read row-by-row.

    Energize one row, read the state of the 4 columns, then do the next one.
    Reads 16 switches with one 8 bit port.
     
  4. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    any help with example. By seeing definition only its difficult for me to understand operation of keypad. there are 8 inputs connected to microcontroller. 4 column inputs and 4 row inputs My basic confusion is that I don't understand on which logic this keypad work?
     
  5. EM Fields

    Active Member

    Jun 8, 2016
    583
    154
    Google keypad and click on "images".
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    18,235
    5,597
    Last edited: Jun 25, 2017
  7. Picbuster

    Well-Known Member

    Dec 2, 2013
    916
    119
    Attached an example. Next thing to do is to grab a PIC and write the codes to read matrix.
    Picbuster
     
  8. LesJones

    Well-Known Member

    Jan 8, 2017
    2,134
    636
    You need 4 bits of one port set as outputs driving say the X axis of the keyboard and 4 bits of another port configured as inputs looking ast the 4 bits from the Y axis.You set one bit of the X axis high the read the Y axis and see which bit is high. If you see a high on any of the 4 bits then you know the button that was pressed. You then repeat the process with the other 3 bits on the X axis high in turn. You will then have tested all 16 keys. With the logic working the way round as I described it you will need pull down resistors on the logic inputs.

    Les.
     
    EM Fields likes this.
  9. MaxHeadRoom

    Expert

    Jul 18, 2013
    18,235
    5,597
    ... Or you can use one port for both as in the N.Goodwin example.;)
    Max.
     
  10. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    I am referring my diagram.
    did you mean like this

    X port as output 1234
    Y port as input ABCD

    set one bit of the X axis high the read the Y axis and see which bit is high
    if bit 1 is high

    1=1 2=0 3=0 4=0

    A=1 B= C=0 D=0---------- How to know that which button was pressed
    A=0 B=1 C=0 D=0-------- How to know that which button was pressed
    A=0 B=0 C=1 D=0---------How to know that which button was pressed
    A=0 B=0 C=0 D=1---------How to know that which button was pressed

    if bit 2 is high
    1=0 2=1 3=0 4=0

    A=1 B= C=0 D=0----------How to know that which button was pressed
    A=0 B=1 C=0 D=0--------How to know that which button was pressed
    A=0 B=0 C=1 D=0------- How to know that which button was pressed
    A=0 B=0 C=0 D=1---------How to know that which button was pressed

    how to know which button was pressed ?
     
  11. MaxHeadRoom

    Expert

    Jul 18, 2013
    18,235
    5,597
    It is all there in the Goodwin example, you take one row low at a time (output) and read each column (input), this detects each independant switch/P.B/matrix.
    Max.
     
Loading...