Arduino powered locking and alarm system.

Hey,
As an assignment at college me and some friends are working together to build an Arduino powered Locking and alarm system with a keypad for interfacing. This is my first Arduino project so I thought I’d post our progress on here.

Today I finished programming the prototype keypad system as seen in the image bellow.

We are using:
An Arduino Duemilanova
A Matrix keypad with 4 5.6 Kohm resistors on the rows.
2 Ultrabright 5v LEDs (Green and Red) to indicate locked/unlocked status.
The code I wrote is as follows.

#include <Keypad.h>
const byte rows = 4;
const byte cols = 3;
int red = 12;
int green = 11;
char keys[rows][cols] = 
{
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[rows] = {5, 4, 3, 2};
byte colPins[cols] = {8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
void setup()
{
  Serial.begin(9600);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
}
void loop()
{
  char key1;
  char key2;
  char key3;
  char key4;
  digitalWrite(red,HIGH);
  digitalWrite(green,LOW);
  do
  {
    key1 = keypad.getKey();
    if(key1 != NO_KEY)
    {
      if(key1 == '*')
      {
        asm volatile ("jmp 0x0000");
      }
      do
      {  
        key2 = keypad.getKey();
        if(key2 != NO_KEY)
        {
          if(key2 == '*')
          {
            asm volatile ("jmp 0x0000");
          }
          do
          {
            key3 = keypad.getKey();
            if(key3 != NO_KEY)
            {
              if(key3 == '*')
              {
                asm volatile ("jmp 0x0000");
              }
              do
              {
                key4 = keypad.getKey();
                if(key4 == '*')
                {
                  asm volatile ("jmp 0x0000");
                }
              } while (key4 == NO_KEY);
            }
          } while (key3 == NO_KEY);
        }        
      } while (key2 == NO_KEY);
    } 
  }while (key1 == NO_KEY);
  if(key1 == '1' && key2 == '3' && key3 == '3' && key4 == '7')
  {
    digitalWrite(red,LOW);
    digitalWrite(green,HIGH);
    delay(3000);
  }
}

In summary this code expects the 4 digit key “1337” and changes the states of the LEDs acordingly. I then used

if(keyX == '*')
          {
            asm volatile ("jmp 0x0000");
          }

as a method of using the asterix key to clear the pressed keys, it simply jumps to the 1st instruction.

Upcoming additions:
An alarm system that would sound if the internal sensors are tripped.
Possibly using ultra-sound or light sensors with a laser.
We will be fashioning an enclosure for the keypad that will allow the Arduino to simply slot in as if it were a CPU socket.

Any suggestions are welcome and so are any queries.

Daniel Taylor

Why the assembly?...

I'm sorry, what do you mean by "Assembly"?

asm volatile ("jmp 0x0000");

I'm wondering why you went the assembly way, instead of using a non-blocking input gathering routine and a simple if check to lock / unlock the system.

Just wondering, really.

Oh right, I understand. Well, while searching for a way to "Soft Reset" the Arduino to clear the keys this method seemed like the easiest at the time that didn't involve re-writing any of the program.