Saturday, August 16, 2008
For the recent upgrade to the Toriton, I used a digital method and an Arduino board to ‘scan’ the twelve-button keypad (0-9, *, #). Previously, I had used a set of resistors acting as an array of interconnected voltage dividers, all going to a single analog input to read. Of course, this ‘analog method’ of reading the keypad is annoying to build, use and program, but it is a situation where I just didn’t know any better at the time, and used the resources and skills available to me back then.
The idea of the digital scanning of a keypad is very simple. The keypad in question has twelve buttons, set up in four rows of three (like a phone keypad, for example). Each button has two connection points – one point goes to a row pin, and one point goes to a column pin. Therefore, seven pins are connected between the keypad and the Arduino – four for the rows and three for the columns. When a button is pushed, it connects the two points – a column pin and a row pin.
By setting a row pin ‘high’ (in this case, to 5V as opposed to ground which would be considered ‘low’), and reading the digital state of the columns, and then repeating this process for the four rows, it is possible to see which button on the keypad is pressed at a given point in time.
The hardware setup is very simple – only the keypad and three resistors are required. Connect Arduino digital i/o pins 2 to 8 to the keypad. Pins 2 – 5 are for rows 1 – 4 respectively and pins 6 – 8 are for columns 1 – 3 respectively.