Alarm System v1.0

This is a project Ive just completed, that was requested by my parents. Back home, we have a shop that we like to keep locked. The keys are on certain keyrings though, and there are lots of people around that need to go in and out. Hence this keyless entry kind of system was born.

It features a 16x2 white-on-blue LCD, 4x3 keypad, and an electric door strike to “unlock” the door, along with a custom PCB. When the correct passcode is entered, it powers the door strike for 5 seconds, then goes back to being locked. The power-off state of the strike is locked, and we have a key as a fail-safe.

Ive also added a timeout feature, so if input isnt received for five seconds, the display shuts off. It turns back on on the next keypress. Hopefully this will prolong the life of the little display.

Now all Ive got to do is figure out a nice mounting box. Something weatherproof would be nice. Anyone know of a good way to weatherproof the standard 4x3 SparkFun keypads?

Anyway, picture time:

Hooked up:

Front of PCB (power supply section in the bottom right has been reworked - bottom header is for the keypad, top-left header is for the LCD):

Back of PCB:

Demo video (sorry it’s sideways, facebook tells me I have no permission to rotate my video…):

Unfortunately my Eagle files are still at school so I will post them when I am there tomorrow morning.

Here is the code:

/*
 Alarm System v1.0
 by J Skoba
 parkinglotlust@gmail.com
 
 =======================================================
 
 Some internal comments, because CTRL+T messes up arrays
 
 byte rowPins[ROWS] = {3, 8, 7, 5};
 byte colPins[COLS] = {4, 2, 6};
 char keys[ROWS][COLS] = 
 {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
 };
 
 // passcode vars
 byte passcode[] = { 1, 2, 3, 4 }; // the passcode
 byte enteredPasscode[] = { 0, 0, 0, 0 }; // an empty array to hold the entered passcode
 
 */

#include <Keypad.h>
#include <ShiftRegLCD.h>

// keypad vars
byte rowPins[ROWS] = {3, 8, 7, 5};
byte colPins[COLS] = {4, 2, 6};
char keys[ROWS][COLS] = 
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
 
// passcode vars
byte passcode[] = { 1, 2, 3, 4 }; // the passcode
byte enteredPasscode[] = { 0, 0, 0, 0 }; // an empty array to hold the entered passcode

// lcd vars
long timeoutInterval = 5000; // length of lcd timeout in mS
long previousMillis = 0;

// character-hiding vars
bool hidePrevious = false; // whether or not to hide the previous value
int timeAtSend; // timer value when call to hide a character was made
double hideInterval = 700; // length of pause until previous password digit is hidden in mS

// unlock time vars
float unlockTime = 5; // time to keep the door unlocked for (in seconds)
float downStep = 0.5; // seconds per tick for ^^

// declarations
ShiftRegLCD lcd(9, 10, 11, 2);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// pin assignments
int relayPin = 12; // pin output relay is connected to (permanent)
int backlightPin = 13; // pin lcd backlight is connected to (permanent)

void setup()
{
  pinMode(relayPin, OUTPUT);
  pinMode(backlightPin, OUTPUT);
  initialize();
}

void loop()
{
  waitForPasscode();
  validatePasscode();
}

void initialize()
{
  digitalWrite(backlightPin, LOW);
  aboutScreen();
  delay(1000);
  digitalWrite(backlightPin, HIGH);
  delay(4000);
}

void waitForPasscode()
{
  lcd.noBlink();
  lcd.clear();
  lcd.print("Please enter the");
  lcd.setCursor(0,1);
  lcd.print("passcode:");
  lcd.setCursor(10,1);
  lcd.blink();

  // 10 is first dash coord
  for (int i = 0; i < 4; i++)
  {
    char key = keypad.getKey();
    previousMillis = millis();

    while (key == NO_KEY)
    {
      key = keypad.getKey();
      if (i > 0)
        hidePreviousDigit(i);
      if (millis() - previousMillis > timeoutInterval)
        timeout();
    }

    lcd.setCursor((i + 10),1);
    lcd.print(key);
    lcd.setCursor((i + 11),1);
    timeAtSend = millis();
    hidePrevious = true;
    lcd.setCursor((i + 11),1);
    enteredPasscode[i] = key - 48;
    delay(200);
  }

  lcd.noBlink();
}

void timeout()
{
  digitalWrite(backlightPin, LOW);
  lcd.noDisplay();
  char temp = keypad.getKey();

  while (temp == NO_KEY)
    temp = keypad.getKey();

  digitalWrite(backlightPin, HIGH);
  lcd.display();
  previousMillis = millis();
}

void hidePreviousDigit(int i)
{  
  if ((millis() - timeAtSend > hideInterval) && hidePrevious)
  {
    lcd.noBlink();
    lcd.setCursor((i + 9),1);
    lcd.print("*");
    lcd.setCursor((i + 10),1);
    hidePrevious = false;
    lcd.blink();
  }
}

void validatePasscode()
{
  int times = 0;

  for (int i = 0; i < 4; i++)
  {
    if (enteredPasscode[i] == passcode[i])
      times++;
  }

  if (times == 4) // passed
  {
    lcd.clear();
    lcd.home();
    lcd.print("    Passcode");
    lcd.setCursor(0,1);
    lcd.print("    accepted!");
    delay(1500);
    digitalWrite(relayPin, HIGH);
    delay(500);
    lcd.clear();
    lcd.home();
    lcd.print(" You have");
    lcd.setCursor(0,1);
    lcd.print("seconds to enter");
    lcd.setCursor(10,0);
    float time = unlockTime;
    lcd.print(time);
    delay(750);
    while (time >= downStep)
    {
      time -= downStep;
      lcd.setCursor(10,0);
      lcd.print(time);
      delay(downStep * 1000);
    }
    digitalWrite(relayPin, LOW);
    delay(1000);
  }
  else // failed
  {
    lcd.clear();
    lcd.print("    Incorrect");
    lcd.setCursor(0,1);
    lcd.print("    passcode!");
    delay(2000);
  }
}

void aboutScreen()
{
  lcd.clear();
  lcd.print("Alarm System 1.0");
  lcd.setCursor(3,1);
  lcd.print("By J Skoba");
}

Wow 160 reads and not one compliment. I see it very well done . Hope you will post finished item and report success. I would like to see the full lock circuit so I can copy it and maybe a parts list so I can buy some.

Perhaps a clear rubber sheet over keypad set in timber or plastic box?Recessed in wall to prevent removal . How will you stop people tampering with keypad?

Nicely done!

Not really sure about the waterproofing, but you can get waterproofed ones for a reasonable price, a tamper proof one might be worthwhile too specially if its going to be subjected to constant use.

I would call it a door entry system, rather than an alarm :P.

Nice!

I did something similar, albeit without the display (I used idiot lights), there's a post in this forum somewhere.

Good choice of TV viewing going on in the background of that video BTW ;D

Nice Job, what a good use of your skills to overcome a need.

Quite a few years ago we manufactured a card access controller, that had the same problem, of excluding moisture. We mounted the display behind a piece of lexan (clear plastic) that was sealed against the box. The display was mounted to the plastic (which was oversize), and the plastic glued to the front panel using RTV....no mounting holes.

We used either a rubber keypad, or a vandal resistant version, purchased through RS Components, which mounted on the outside, and was sealed at the top and side (so any moisture drained out).

The only problem we had was with the vandal keypad (metal keys) when it was cold. It seems that the keypad off resistance dropped, and the interface IC detected it as an ON, even though it was no where near the On detect resistance. (We fixed that with pullup resistors).

Any keypad that uses a continuous rubber membrane should be moisture proof from the front. Its not always moisture getting in thats the problem, its making sure it can drain out.

The commercial access units often have a cover, which stops most water, ... and vandals.

Good luck

Mark

april, I was thinking the same thing! I was going to get some thick plastic and put it between the case and the keypad (with the keypad mounting inbehind). I also like markB's idea of mounting the display behind lexan - this will waterproof it and i can just glue it. Awesome!

Also, about the name, it was originally intended to be an alarm but repurposed midway through. I think a "Keyless Entry" system would be a better name.

As for tamper-proof keypads, I dont need to go to that much trouble. To make a long story short, pesticide regulations now require that all doors to pesticide rooms (agricultural, anyway) be locked at all times. This can be somewhat of an inconvenience, needing to go in and out several times a day.

With a Keyless Entry system, the room is still 'secure' but you need only enter a passcode, rather than have a physical key. This way, anyone who knows the passcode can get in, without having to borrow/duplicate the key.

Thanks for all the warm comments!

SpikedCola

I also like markB's idea of mounting the display behind lexan - this will waterproof it and i can just glue it. Awesome!

My memory is slowing come back...well bits and bytes

The keypad mounting screws also provided a holder for the display. Generally we found the RTV sufficient, as the size past the display opening was about the same as the height (if my bits and bytes aren't mixed up)

Mark

I'm also working on something similar like AdeV, but seeing how that LCD looks I might have to reconsider the interface :) Very well done! I look forward to seeing the finished project and enclosure

Very cool work!

Any chance for a link for the strikeplate? Where'd you get it? Does it have a datasheet I can check out?

Looks nice :)

one thing I noticed from the video was, that when you type in part of the passcode without completing it, the display will wake up again with the last keypresses still present.

If it was me, i'd make sure to clear away any inputs when i switch off the screen, so any almost typed in passcode will not reamin there (making it easier for any intruders to guess the right digit to unlock the door).

very cool project though. I hope you'll make a little writeup, and let us know how it comes along 8-)

Look for a outside mounted garage door keypad.

They are usually housed in a plastic box with a flip up lid. Gravity helps keep it closed, and the rain out.

Nice work by the way.

one thing I noticed from the video was, that when you type in part of the passcode without completing it, the display will wake up again with the last keypresses still present.

I haven't watched the video, but if he is displaying the keypresses, he should change this.

Perhaps to displaying asterisks instead of the numbers, or displaying the number briefly (.5 seconds), then overlaying it with an asterisk...

That would be better security (and yes, the code should be cleared if the timeout occurs).

displaying the number briefly (.5 seconds), then overlaying it with an asterisk...

I've watched the video, that's what it does.

Yup, thats exactly what it does!

I didnt want to display the numbers until the full passcode had been entered, so that someone couldnt watch, but a way to confirm what youd entered would be nice - hence the asterisk method.

The code clearing when a timeout occurs is also an excellent idea! Ill modify the code straight away! It may take me a little while to finish up the project, but I will certainly update this post with finished pictures and stuff when its all said and done.

Here is the door strike I purchased: http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=320507458492&ssPageName=STRK:MEWNX:IT