After my son discovered that disclosing your PIN for a hard coded alarm is not such a great idea, we have embarked on moving our alarm system to a micro-controller which can then be programmed to allow the user to change the PIN at run-time. Our microcontroller of choice is the PICAXE which is available here. For this project, I chose the PICAXE 20M, but this was a bad idea as the memory on this device is much too small for this kind of project as I will show later. In addition to the 20M, I also ordered the AXE029 breadboard adapter, the AXE033 Serial LCD module and a 4×3 matrix keypad for data entry. I also should mention that the service from tech supplied in the U.K. is very good – I live in Germany and the package was dispatched the same day and arrived two days later.
Our first job in this project was to interface the keypad and LCD module to the microcontroller. In this post I will describe how the keypad can be interfaced to the 20M and in a later post I will describe the LCD module and post the code for the first version of the alarm. The pins on the keypad are arranged as follows (reading left to right and looking at the keys): (1) Not Connected (2) Column 2 (3) Row 1 (4) Column 1 (5) Row 4 (6) Column 3 (7) Row 3 (8) Row 2 (9) Not Connected. The row pins (R1 – R4) should be connected to output pins of the 20M as follows: (1) Output0 -> R1 (2) Output1 -> R2 (3) Output2 -> R3 (4) Output3 -> R4. The column pins of the keypad (C1 – C3) should be connected to the input pins of the 20M as follows: (1) C1 -> input0 (2) C2 -> input1 (3) C3 -> input2. Don’t forget that the input pins 0 – 2 on the PICAXE have to be pulled down to 0v using 10k resistors so that the pins aren’s floating when no input is present from the keypad. The circuit described above can be seen in the following schematic.
The next step is to program the microcontroller so that it scans the key pad. To do this, simply loop through the rows one at a time (output0 – output3) and test which column is set. Below is the code I developed to do this. In a nutshell, the main routine loops across all of the row pins and sets them high one by one. The keyscan routine is called for each row scan and it checks if a column pin is high – if true, it calculates the key number using the simple calculation row * 3 + column and waits until the key is released. The displayKey routine displays the number on an LCD module.