Home Alarm with a 3 wire 4x3 analog keypad nearly done but need some help please

Edit: Removed

Good! Yes, that feature can be turned on and off inside the alarm case. I don't kow what you exactly wanted.

Hi liudr. What I wanted is to attach a PIR sensor and have the value it senses for movement set the alarm buzzer off for say 30 seconds. The keypad needs the correct code to disarm the alarm buzzer and ignore the PIR sensing or turn off the PIR sensor using a transistor. If i use a PNP transistor setting a digital pin HIGH via a resistor to the base of the transistor would cut the power to the PIR sensor.

 if (pointer==5)
      {
        buffer[pointer]=0;
        pointer=0;
        if (!strcmp(buffer,password))
        {
          Serial.println("Authenticated!");
          system_state=cleared;
          cleared_starting=millis();
II hope this is a help
Jeremy
          // Open a door or something
          digitalWrite (tripped,LOW);
          digitalWrite(alarmOff,HIGH);
        }
   
        }
        
        else
        {
          Serial.println("Unauthorized!");
          system_state=alarm;
          alarm_starting=millis();
          digitalWrite(alarm_pin,HIGH);
          digitalWrite(tripped,HIGH);
          digitalWrite (alarmOff,LOW);
        }
      }
    }[code]

[/code]

HazardsMind:

Yeah right, so what's the problem?

Well any number you put in for the 5th digit, will be changed to zero, thats not a problem?
You enter 12345, the code after that part sees 123450. I can't test it myself, but thats what I see from this.

Again I can't test it, but if it works then it works.

No. Reread the code. More importantly, get the C from ground up by the author I recommended you.

I don't have a PIR sensor so I can't help with that. I recommend you read my code a few times, find out how it is able to sound alarm/LED for 30 seconds while monitoring keypad input. Then you can change it to do your PIR logic. I imagine if someone walks up to the PIR sensor, it sounds the alarm. then they type in the code to disarm it? It's all your call how to do this.

liudr:

HazardsMind:

Yeah right, so what's the problem?

Well any number you put in for the 5th digit, will be changed to zero, thats not a problem?
You enter 12345, the code after that part sees 123450. I can't test it myself, but thats what I see from this.

Again I can't test it, but if it works then it works.

No. Reread the code. More importantly, get the C from ground up by the author I recommended you.

HazardsMind,

Sorry I issued the RTFM on this. I should have pointed out what the code does:

  1. It fills the buffer with up to 5 characters from the keypad (password).
  2. It then terminates the string in the buffer with \0
  3. It then performs a string comparison with the password using strcmp(), which requires a zero terminated C-string, thus step 2.
  4. It then decides whether to sound the alarm or to clear the alarm.

My step 2 was not necessary if I set the C-string's 5th location to zero in setup like buffer[5]=0 or have char buffer[10]=" ". But if I move the code to a different project, that line is very likely to be left out (forget to move) and this wouldn't work (buffer[5] is just a random value). The initial value of the buffer is also wasting 6 bytes of arduino SRAM, which is only 2K long.

Ok, thank you for clarifying that. It just seemed wrong for some reason, and I have no way to test your code for myself. (At work) I understand everything you want to do, its just, it looked odd to add a zero to buffer[5] and then compare it. I thought that when you got the last key, that is was adding on an extra 0.

Hi and a big thank you to liudr. Here is the code I am now using. I have got over the keypad press turning the alarm off. I have added another state called disarmed and the system stops at that point until the tactile button is pressed. This is fine but the motion sensor is a different story. I have tried instead to use a digital pin to read the sensor as it gives a clear 1 if motion detected and a 0 if not. I have tried using it in different places in the sketch but it is causing problems with the key presses(it was doing the same with an analog input) Also I can use a tactile button to simulate the motion sensor because it keeps going high with me moving my hands around.
It is getting there but not quite. I will keep trying to get the sensor working though.
Jeremy

 #include <phi_interfaces.h>

#define buttons_per_column 12 // Each analog pin has five buttons with resistors.
#define buttons_per_row 1 // There are two analog pins in use.

byte keypad_type=Analog_keypad;
char mapping[]={'1','2','3','4','5','6','7','8','9','*','0','#'}; // This is an analog keypad.
byte pins[]={0}; // The pin numbers are analog pin numbers.
int values[]={ 58, 96, 145, 226, 335, 447, 558, 680, 790, 890, 941, 970}; //These numbers need to increase monotonically.
phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column);
multiple_button_input* pad1=&panel_keypad;

#define alarm_pin 13
enum States {get_password, alarm, cleared,dissarmed};
States system_state=get_password;

unsigned long alarm_starting, cleared_starting;
char password[]="11111";// easy password for testing
char buffer[20];
int pointer=0;

int led=11;// led to simulate alarm
int PIR=A5;// motion sensor cannot get to work so not used
int tripped;// value to hold pir
int pirPin=5;/*I was using this pin as pir gives a digital 1 or 0 cannot get it to work 
in the sketch it just seems to stall the keypad
*/
int buttonPin=2;//small tactile button to turn system on
int buttonState;//state of the tactile button
void setup()
{
  Serial.begin(9600);
  pinMode(alarm_pin,OUTPUT);
  digitalWrite(alarm_pin,LOW);
 // digitalWrite(A0,HIGH); // DO this only if you are using phi-3 shield.
 pinMode(alarm_pin,OUTPUT);
  digitalWrite(alarm_pin,LOW);
  pinMode(led,OUTPUT);
  pinMode(pirPin,INPUT);
  pinMode(buttonPin,INPUT);
 
}

void loop()
{
  byte temp;
  switch (system_state)
  {
    case get_password:
     if  (millis()-alarm_starting>=10000)// if alarm is tripped this turns led off
     // I changed the time just for testing
        {
          digitalWrite(led,LOW);
        }
    // do get password stuff
    temp=panel_keypad.getKey(); // Use phi_keypads object to access the keypad
    if (temp!=NO_KEY)
    {
      Serial.write(temp);
      buffer[pointer++]=temp;
      if (pointer==5)
      {
        buffer[pointer]=0;
        pointer=0;
        if (!strcmp(buffer,password))
        {
          Serial.println("Authenticated!");
         system_state=dissarmed;//cleared;
         //dissarmed turns the system off
          cleared_starting=millis();
          digitalWrite(led,LOW);
          // Open a door or something
        }
        
        else
        {
          Serial.println("Unauthorized!");
          system_state=alarm;
          alarm_starting=millis();
          digitalWrite(alarm_pin,HIGH);
        }
      }
    }
    break;
    
    
    case dissarmed:
    digitalWrite(led,LOW);
    buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {    //system off until button pressed. 
     system_state=get_password;
  }
    break;
   
    
    case alarm:
     digitalWrite(led,HIGH);
    if ((panel_keypad.getKey()!=NO_KEY)||(millis()-alarm_starting>=10000))
    {
      system_state=get_password;
      digitalWrite(alarm_pin,LOW);
    }
    break;
    
    case cleared:
    if ((!panel_keypad.getKey())||(millis()-cleared_starting>=10000))
    {
      system_state=get_password;
      // Close the door or something.
    }
    break;
  }
}

Sorry I should have added that the pir stays high for 6 seconds after activation
Jeremy

I see that you declaired "pinMode(pirPin,INPUT);" but where in your code are you reading it, or have you not gotten to that part yet?

Hi HazardsMind. I did put the sensor in in various places in the get password case because i could only get a reading on it there. I found it caused problems with the keypad function.
The problem seems to be in the case get password part of the sketch where the program sits for the majority of the time waiting for a key press.I wherever the sensor is in the sketch the keypad is slow to respond and I noticed that when the alarm was triggered the led on pin 11 was very dim. I have tried giving the motion sensor its own power supply with the grounds connected but this makes no difference. I tried the led on a different pin with the same result. I was trying to work out how to have the sketch sit waiting in a different part lets call it case check_sensor but I am not able to do this. My programming skills have been learned over the last few months with some library books and the internet.
I used to drive a Bus and my hobby is electronics and now I am learning to program my arduino.
The trouble with me is I always think "How hard can it be?"
Learning to write code is like learning to speak Chinese with a Spanish phrase book. But I am picking it up slowly.
Jeremy

Jeremy,

You are welcome! You're making progress of your own. I recommend you to write a sketch just for PIR and test it out then integrate with my sample code. You can have as many state as you want with the state machine. A good idea is to draw a flow chart to indicate how you want the machine to transition between each state (eg. 30 seconds in the disarmed state puts it back to some alert state). If you decide on the flow chart, writing code is just transcribing it into C.

Hi liudr. I have already written a simple PIR sketch and will have a go at making another state. Thank you for the flow chart idea I will use it to develop the project. Hopefully I will post the finished code soon. If you want to have a laugh at what I am using for a Keypad have a look here.
Thank you for all of your help to make this project work for me
Jeremy

Hi all. I am still unable to get the sensor to work in the sketch. I have tried all sorts but to no avail. I have been playing with state machines until I almost used my Arduino for a Frisbee. I managed to stop myself though.
On another note
I got one of those 4x4 membrane keypads yesterday for £3 on that well known auction site. I have stuck a few resistors on a breadboard and thanks to Liudr's libraries and sketch have it displaying all of the symbols perfectly.
1 2 3 A
4 5 6 B
7 8 9 C

  • 0 # D
    I just thought you would like to know that some things I do work
    Jeremy

Hi I have now got it working but before I throw my hat in the air there is one slight problem. The PIR sensor takes 5 seconds to calibrate. When you power the system it works just fine but when you press the arming button on the keypad the alarm goes off because the sensor is giving a High signal.
Can anyone suggest anything that will stop it please.
Jeremy

/* This sketch uses a 16 key 4X4 analog keypad. The password is 1234 press #
 to check the password. if correct the Red LED goes out and the Green Led comes on
 to rearm the alarm press *
 If when the system is in the disarmed state the C key is pressed both LED's light
 and you can enter a new 4 digit password.
 The sensor part is still a work in progress.
 */



#include <phi_interfaces.h>

#define buttons_per_column 16 // Each analog pin has five buttons with resistors.
#define buttons_per_row 1 // There are two analog pins in use.

byte keypad_type=Analog_keypad;
char mapping[]={
  '1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'}; // This is an analog keypad.
byte pins[]={
  0}; // The pin numbers are analog pin numbers.
int values[]={ 
  204,370,480,559,146,333,455,541,78,292,428,521,0,245,397,499}; //These numbers need to increase monotonically.
phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column);
multiple_button_input* pad1=&panel_keypad;

// pin assignments
int speakerOut = 11; 
int redLedpin = 12;
int greenLedpin = 10;
int alarmPin=3;
int sensePin=A4;


// variables
char* inputString = "0000";  // holds the user input
char password[5] = "1234";  // holds the default correct password that can later be changed
int curpos = 0; // cursor position
int locked = 1; // status of the system: if locked = 1, if unlocked = 0
int motion;
long previousMillis = 0; 
long interval = 5000;
int alarmPinstate = LOW; 



void setup(){
  Serial.begin(9600);
  pinMode(sensePin,INPUT);// sensor
  pinMode(speakerOut, OUTPUT);//  keypad beeps and if passcode accepted tone
  pinMode(redLedpin, OUTPUT);// system armed
  pinMode(alarmPin,OUTPUT);
  pinMode(greenLedpin, OUTPUT);//system dissarmed

}
void scanning(){
  motion=analogRead(sensePin);
  //Serial.println(motion);// used for debugging
  unsigned long startTime = 0;
  unsigned long interval = 5000;

  if ((locked==1)&&(motion>=500)){// if the alarm is on read the sensor
    if (startTime + interval < millis()) {
      digitalWrite(alarmPin, HIGH);
    }//added
  }
  else
  {//added
    digitalWrite (alarmPin, LOW);

  }


}


void loop(){

  if(locked ==1)//if the alarm is on
  {
    scanning();
    digitalWrite(redLedpin, HIGH);

    digitalWrite(greenLedpin, LOW);

  }


  if(locked ==0)// if the alarm is off
  {

    digitalWrite(redLedpin, LOW);// if this pin is low the alarm will be off
    digitalWrite(greenLedpin, HIGH);
    scanning();
  }

  // receive input from keypad
  byte temp=panel_keypad.getKey();

  if (temp != NO_KEY){   //  a key is pressed
    Serial.write(temp);
    playKeyTone(); // play a beep to acknowledge that key pressed

    switch(temp) // look for the special keys to initiate an event
    {
    case '#':
      parseString(); // try unlock routine
      curpos = 0;
      break;
    case '*': // lock the system

      Serial.println("Armed");

      locked = 1;
      clearPassword(); // clear the password so that user needs to enter 4 digits again before unlocking
      curpos = 0; // set cursor back to start of 4 digits
      break;
    case 'C':
      changePassword(); // change password routine
      curpos = 0;
      break;
    }

    if(temp != '*' && temp != '#' && temp != 'C')
    {
      inputString[curpos] = temp; // if the key was none of the above three special ones, add the digit to the password string
      curpos = curpos + 1; // move cursor to next position
    }

    if(curpos > 3) // if the cursor has reached the end of 4 digits, return it to the start
    {
      curpos = 0;
    }


  }
}

void playKeyTone(){ // beep  key press
  int elapsedtime = 0;
  while (elapsedtime < 100)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(500);


    digitalWrite(speakerOut, LOW);
    delayMicroseconds(500);
    elapsedtime++;
  }
}

void playWarningTone(){ // long beep for wrong password
  int elapsedtime = 0;
  while (elapsedtime < 200)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);


    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);
    elapsedtime++;
  }
}

void playSuccessTone(){ // short beep for correct password
  int elapsedtime = 0;
  while (elapsedtime < 10)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);

    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);

    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);

    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);
    elapsedtime++;
  }
}


void parseString() // parse password to see if it matches
{
  Serial.println("Code Entered");
  Serial.println(inputString);
  if(matchString(password, inputString) == 1) // did they match?
  {
    Serial.println("SYSTEM IS OFF. PRESS * TO ARM");
    locked = 0; // correct code entered, unlock system
    playSuccessTone();
    return;
  }
  else
    playWarningTone(); // nope, wrong password
  Serial.println("Wrong Password");
}

void changePassword()
{
  Serial.println("PASSWORD CHANGE MODE");
  Serial.println("ENTER NEW PASSWPORD");
  if(locked == 0) // only get into this mode if unlocked! (otherwise anyone can change password without knowing correct one! that would be dumb!)
  {
    digitalWrite(redLedpin, HIGH); // turn on RED LED
    digitalWrite(greenLedpin, HIGH); // turn on GREEN LED
    char pkey = NO_KEY;
    int c = 0;
    while(c < 4)
    {

      pkey = panel_keypad.getKey(); // get new password 4 digits
      if(pkey != NO_KEY)
      {
        playKeyTone();
        password[c] = pkey; // store it in the password string
        Serial.println(pkey);
        c = c + 1;
      }

    }
    Serial.println("THANK YOU YOUR NEW PASSWORD IS:");
    Serial.println(password);

  }
}


int matchString(char* string1, char*string2) // function to match two strings, returns 1 if they match, 0 if they dont
{

  for(int i=0; i < 5; i++)
  {
    if(string1[i] != string2[i])
    {
      return 0;
    }
  }
  return 1;
}

void clearPassword() // clears the entered password after system is locked (so person can't just press # to unlock, needs to enter 4 digit code again!)
{
  for(int a=0; a < 4; a++)
  {
    inputString[a] = '0';
  }
}

I really don't know much about PIR sensors. If there is human activity, does it stay HIGH? If I can take that as true, I recommend this:

Maybe have a timer that counts 5 seconds. When the system is in armed state and high is sensed from PIR, start this timer and put the system in an additional state called alert. In the alert state, all it does is to wait for the timer to expire while reading PIR and confirming it's still high. After successfully passing 5 seconds with PIR high, go to alarm state? If system fails to see PIR stay HIGH for 5 seconds, go back to armed state. Will this work?

Hi Liudr. The PIR is basically just a switch which sends out a low when there is no movement and a High when movement is detected. It will stay high for about 5 seconds after it stops seeing motion. The time the PIR stays high can be adjusted using an on board trimmer pot. This I will eventually make it 30 seconds for the siren (alarm Pin) to sound. Obviously i will have to change the timing on this part of the sketch

void scanning(){
  motion=analogRead(sensePin);
  //Serial.println(motion);// used for debugging
  unsigned long startTime = 0;
  unsigned long interval = 6000;

  if ((locked==1)&&(motion>=500)){// if the alarm is on read the sensor
    if (startTime + interval < millis()) {
      digitalWrite(alarmPin, HIGH);
    }//added
  }
  else
  {//added
    digitalWrite (alarmPin, LOW);

  }


}

the unsigned long interval will be changed to accommodate the time needed for the PIR to go low. I have tried to add a timer state called alert as you suggested but have not been able to get it to work. I know I am missing something simple but I just cannot sort it out. I will keep trying though.
Jeremy

Jeremy,

Maybe I misread your last post. Did you mean if you start the system and immediately push arm then the alarm will sound due to the fact the PIR sensor calibrates at startup and outputs HIGH during the calibration? If this is the case, I think there could be a different state machine sequence:

Start up (run a timer of say 5 seconds, any button push is responded by a buzz, "I'm busy starting up!!") -(timer runs out)-> disarmed (waiting for button push to enter armed mode) -- etc.

So if you manually create start up state that transitions to disarmed state after 5 seconds, then you can avoid alarm. Just my 2 cents.

YES YES YES
It works. The answer was staring me in the face. It did not need any more states just 2 lines of code, a Capacitor and a resistor.
All I did was add a 220uf cap via 100k resistor to the yellow led. I then put a wire from the capacitor to A5. the current draw is so tiny but the cap does slowly charge. When you arm the system the reading on A5 drops over time to allow the PIR to settle down before the capval drops to 3.
I am aware that I owe you a massive thank you Liudr for your patience with a novice and for you spending your time to write some code for me. Also for pointing me in the right direction.
Again Thank you
Jeremy

void scanning(){
  capVal=analogRead(cap);//This Has Fixed It go down to the next if statement 
  //Serial.println (capVal);
  
  motion=analogRead(sensePin);
  //Serial.println(motion);// used for debugging
  unsigned long startTime = 0;
  unsigned long interval = 5000;

  if ((locked==1)&&(motion>=500)&&(capVal<3)){//HERE IS THE FIX
    if (startTime + interval < millis()) {
      digitalWrite(alarmPin, HIGH);
    }//added
  }
  else
  {//added
    digitalWrite (alarmPin, LOW);

  }


}

Here is the completed code although I have set the state to unlocked when the system starts now because I intend to have a rechargeable battery in the case the alarm will be housed in. If I were to run it without I would set the state to locked. I have added another pin for the capacitor charging but would stress the need for a large value resistor(I used 100k) for the capacitor.
Jeremy

/* This sketch uses a 16 key 4X4 analog keypad. The password is 1234 press #
 to check the password. if correct the Red LED goes out and the Green Led comes on
 to rearm the alarm press *
 If when the system is in the disarmed state the C key is pressed both LED's light
 and you can enter a new 4 digit password.
 The sensor was triggering the alarm when armed from the unlocked state but was solved by using a capacitor to hold a small charge
which decays slowly when the alarm is set allowing the PIR sensor time to settle down.
 */
//Thank you Liudr for your guidance and help with the code.
// Your phi interface is a valuable set of tools.

#include <phi_interfaces.h>

#define buttons_per_column 16 // Each analog pin has five buttons with resistors.
#define buttons_per_row 1 // There are two analog pins in use.

byte keypad_type=Analog_keypad;
char mapping[]={
  '1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'}; // This is an analog keypad.
byte pins[]={
  0}; // The pin numbers are analog pin numbers.
int values[]={ 
  204,370,480,559,146,333,455,541,78,292,428,521,0,245,397,499}; //These numbers need to increase monotonically.
phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column);
multiple_button_input* pad1=&panel_keypad;

// pin assignments
int speakerOut = 11; 
int redLedpin = 12;
int greenLedpin = 10;
int alarmPin=3;
int capCharger=2;
int sensePin=A4;
int cap=A5;
int capVal;

// variables
char* inputString = "0000";  // holds the user input
char password[5] = "1234";  // holds the default correct password that can later be changed
int curpos = 0; // cursor position
int locked = 0; // status of the system: if locked = 1, if unlocked = 0
int motion;
long previousMillis = 0; 
long interval = 10000;
int alarmPinstate = LOW; 



void setup(){
  Serial.begin(9600);
  pinMode(sensePin,INPUT);// sensor
  pinMode(speakerOut, OUTPUT);//  keypad beeps and if passcode accepted tone
  pinMode(redLedpin, OUTPUT);// system armed
  pinMode(alarmPin,OUTPUT);
  pinMode(greenLedpin, OUTPUT);//system dissarmed
  pinMode(capCharger,OUTPUT);
  /*
The cap charger will charge a capacitor that stops the PIR
   sensor from showing an alert when setting the alarm.
   The pir shows high when power is applied so the cap stops the
   alarm triggering as soon as the alarm is powered on.
   */
}
void scanning(){
  capVal=analogRead(cap);//This Has Fixed It
  Serial.println (capVal);

  motion=analogRead(sensePin);
  //Serial.println(motion);// used for debugging
  unsigned long startTime = 0;
  unsigned long interval = 5000;

  if ((locked==1)&&(motion>=500)&&(capVal<100)){// if the alarm is on read the sensor
    if (startTime + interval < millis()) {
      digitalWrite(alarmPin, HIGH);
    }
  }
  else
  {
    digitalWrite (alarmPin, LOW);

  }


}


void loop(){

  if(locked ==1)//if the alarm is on
  {
    scanning();
    digitalWrite(redLedpin, HIGH);
    digitalWrite(capCharger,LOW);
    digitalWrite(greenLedpin, LOW);

  }


  if(locked ==0)// if the alarm is off
  {

    digitalWrite(redLedpin, LOW);// if this pin is low the alarm will be off
    digitalWrite(greenLedpin, HIGH);
    digitalWrite(capCharger,HIGH);// this starts the capacitor charging
    scanning();
  }

  // receive input from keypad
  byte temp=panel_keypad.getKey();

  if (temp != NO_KEY){   //  a key is pressed
    Serial.write(temp);
    playKeyTone(); // play a beep to acknowledge that key pressed

    switch(temp) // look for the special keys to initiate an event
    {
    case '#':
      parseString(); // try unlock routine
      curpos = 0;
      break;
    case '*': // lock the system

      Serial.println("Armed");

      locked = 1;
      clearPassword(); // clear the password so that user needs to enter 4 digits again before unlocking
      curpos = 0; // set cursor back to start of 4 digits
      break;
    case 'C':
      changePassword(); // change password routine
      curpos = 0;
      break;
    }

    if(temp != '*' && temp != '#' && temp != 'C')
    {
      inputString[curpos] = temp; // if the key was none of the above three special ones, add the digit to the password string
      curpos = curpos + 1; // move cursor to next position
    }

    if(curpos > 3) // if the cursor has reached the end of 4 digits, return it to the start
    {
      curpos = 0;
    }


  }
}

void playKeyTone(){ // beep  key press
  int elapsedtime = 0;
  while (elapsedtime < 100)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(500);


    digitalWrite(speakerOut, LOW);
    delayMicroseconds(500);
    elapsedtime++;
  }
}

void playWarningTone(){ // long beep for wrong password
  int elapsedtime = 0;
  while (elapsedtime < 200)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);


    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);
    elapsedtime++;
  }
}

void playSuccessTone(){ // short beep for correct password
  int elapsedtime = 0;
  while (elapsedtime < 10)
  {
    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);

    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);

    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(1000);

    digitalWrite(speakerOut, LOW);
    delayMicroseconds(1000);
    elapsedtime++;
  }
}


void parseString() // parse password to see if it matches
{
  Serial.println("Code Entered");
  Serial.println(inputString);
  if(matchString(password, inputString) == 1) // did they match?
  {
    Serial.println("SYSTEM IS OFF. PRESS * TO ARM");
    locked = 0; // correct code entered, unlock system
    playSuccessTone();
    return;
  }
  else
    playWarningTone(); // nope, wrong password
  Serial.println("Wrong Password");
}

void changePassword()
{
  Serial.println("PASSWORD CHANGE MODE");
  Serial.println("ENTER NEW PASSWPORD");
  if(locked == 0) // only get into this mode if unlocked! (otherwise anyone can change password without knowing correct one! that would be dumb!)
  {
    digitalWrite(redLedpin, HIGH); // turn on RED LED
    digitalWrite(greenLedpin, HIGH); // turn on GREEN LED
    char pkey = NO_KEY;
    int c = 0;
    while(c < 4)
    {

      pkey = panel_keypad.getKey(); // get new password 4 digits
      if(pkey != NO_KEY)
      {
        playKeyTone();
        password[c] = pkey; // store it in the password string
        Serial.println(pkey);
        c = c + 1;
      }

    }
    Serial.println("THANK YOU YOUR NEW PASSWORD IS:");
    Serial.println(password);

  }
}


int matchString(char* string1, char*string2) // function to match two strings, returns 1 if they match, 0 if they dont
{

  for(int i=0; i < 5; i++)
  {
    if(string1[i] != string2[i])
    {
      return 0;
    }
  }
  return 1;
}

void clearPassword() // clears the entered password after system is locked (so person can't just press # to unlock, needs to enter 4 digit code again!)
{
  for(int a=0; a < 4; a++)
  {
    inputString[a] = '0';
  }
}

Thank you for posting the complete code Jeremy. I was glad to help you with some questions but you worked out the entire solution. I was just covering the capacitors in my electronics class. So I'll use what you did as an example to do hardware debouncing on buttons. Please post some pictures and/or videos when you're done, preferably on the Exhibition forum!