For building 12 button key-lock you don’t need microcontroller with many ports. Ivica Novakovic has a nice demonstration on how low pin count microcontroller with ADC can be used to read many keys. Key-lock itself is simple. It controls two relays where electromagnets or motors can be attached.
In key-lock circuit there are only one one wire used to read buttons. Of course there are also VCC and GND (power supply) needed. Author also included simple piezo buzzer for sounding keys. Each keypad is positioned between resistor voltage dividers so when one of buttons is pressed, ADC reads a voltage drop. This way each button provides different voltages when pressed. As there is 10 bit ADC used, there can be 1024 different voltages read, but in reality there has to be voltage range left for one button, because voltage may fluctuate. For 12 buttons each button has 85 value range what is enough for reliable operation. With more precise resistors and stabile power supply there can be more buttons interfaces if needed. Project files and firmware are available for download.[via]