Hello everyone,
I salvaged a 12 button keypad from a digital door lock. I don't have a part number or datasheet but it was fairly easy to work out that pins 1 to 4 relate to the rows and 5 to 7 relate to the columns. e.g. if button "5" is pressed pins 2 and 6 will be connected.
(Throughout this post pin x should be taken to mean the pin on the keypad not an arduino pin. If I wish to talk about an arduino pin I will state it as μC-pin x.)
I wired this keypad up successfully in the way depicted in the schematic. This gives reliable and predictable results. The arduino uno applies 5V to pins 1-4 one at a time and 'listens' for current on pins 5-7 for each cycle. So if 5V is being applied to pin 2 and pin 6 goes high you know that button "5" has been pressed.
I was happy with this until I wondered what would happen if more than one button was pressed. Nothing very untoward happened when I tried this in reality but I became concerned when I ran through a few scenarios with the schematic.
I came to the conclusion that if more than one button was pressed on the same column it would connect a high output pin to a low output pin. As I understand it this would be a particularly bad thing to do as a pin configured as output is in a low-impedance state and as there is very little (practically no) resistance in this situation the pins would draw too much current and will be damaged.
But as I said my arduino is still in one piece and functioning normally after trying this. I had a few ideas as to why this might be:
- A few seconds of two buttons being pressed is not long enough to cause damage
- The arduino is switching the pins from high to low sequentially at a rapid rate (as fast as the microcontroller can) and again not enough time passes for damage to be done
- The keypad has more complicated circuitry than I have modelled in the schematic i.e. regulatory components (perhaps resistors on the pins) to prevent this situation from causing damage to external circuits
I came up with some possible solutions based on these possibilities:
- Only have one pin set as output at any one time and set everything else as input even if they are not being used to read anything. This will put them in a high-impedance state and would prevent an over-current scenario.
- Place current limiting resistors in series with the output pins.
- Leave circuit as it is as damage is unlikely/would take a long time to develop/keypad contains built in regulation.
This has left me with a few questions:
- Are any of the explanations of my observations above valid?
- Would the arduino eventually be damaged if two buttons were pressed together for a longer period of time (such as something heavy resting on the keypad)?
- Are any of my solutions viable and are they even necessary?
I'd appreciate any insight into this situation as I'm trying to deepen my understanding of how simple electronics such as this work before I start any bigger projects.