i need help with this code

hy all, im new with arduino nd i hve project to make home securiti, im use sensor PIR and keypad,
i try to find and rebuild or combine the source but thil hve trouble,
there is my code

#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
enum { 
  Alarm_on,
  alarm_of,
} state;
int ledpin = 12;
int spkrpin = 10;
int pirpin = 11;
int pirstate = LOW;
int val = 0;
int calibrationTime = 5;
long unsigned int lowIn;
long unsigned int pause = 5000;
Password password = Password( "1234" );


const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = { 9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

  Serial.begin(9600);
  Serial.begin(9600);
 pinMode(ledpin, OUTPUT);// set up serial port
 pinMode(spkrpin,OUTPUT);
 pinMode(pirpin,INPUT);
 digitalWrite(ledpin, LOW);
 digitalWrite(pirpin,HIGH);
   Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);

  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
	Serial.print("Pressed: ");
	Serial.println(eKey);
	switch (eKey){
	  case '*': checkPassword(); break;
	  case '#': password.reset(); break;
	  default: password.append(eKey);
     }
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");
    state=Alarm_on;
    //Add code to run if it works
  
  }else{
    Serial.println("Wrong");
    //add code to run if it did not work
  }


switch (state){
  case Alarm_on: {
    val = digitalRead(pirpin);
    if ( val == HIGH) {
      delay(150);
      if (pirstate == LOW){
        digitalWrite(ledpin, HIGH);
        digitalWrite(spkrpin, HIGH);
        Serial.println("movement");
        pirstate = HIGH;
      }
    }
    else {
      if (pirstate == HIGH){
        digitalWrite(ledpin, LOW);
        digitalWrite(spkrpin, LOW);
        Serial.println("AMAN");
      }
    }
    break;
  }
  case alarm_of :{
    digitalWrite(ledpin,LOW);
      digitalWrite(spkrpin,LOW);
      break;
  }
}
}

ty before :d

What trouble do you have ? Does the code compile or do you get errors ? What should the code do and what does it actually do ?

UKHeliBob: What trouble do you have ? Does the code compile or do you get errors ? What should the code do and what does it actually do ?

no error with compile, but after i test, this program not work, password success but pir sensor always detect motions even no one near it

byte colPins[COLS] = { 5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

That line looks wrong to me.

I don't think so - the compiler allows hanging commas.

pir sensor always detect motions even no one near it

Does the PIR really always detect motion (in which case, you don't have a programming problem), or does the pin it is connected to appear to always trigger? Do you have a schematic?

I don't think so - the compiler allows hanging commas.

It may allow it, but it still looks wrong.

It's a useful feature when used in conjunction with the preprocessor - you can create simple macros to generate tables without caring about the last entry.

AWOL: It's a useful feature when used in conjunction with the preprocessor - you can create simple macros to generate tables without caring about the last entry.

thank for respon sir and all but can u give me a example, i really new with this arduino

UKHeliBob: byte colPins[COLS] = { 5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

That line looks wrong to me.

i think no mistake with keypad code, i just trouble with sensor(pir) code, i really dont know hoe to combine PIR and keypad :(

If there's no problem with the keypad code, write a simple sketch to help you figure out why you think the PIR is always triggering. Maybe it is, or maybe you just have a floating input.

Don't you need to set pirstate back to LOW in this piece of code? Otherwise it will print "AMAN" repeatedly while the PIR input remains low.

      if (pirstate == HIGH){
        digitalWrite(ledpin, LOW);
        digitalWrite(spkrpin, LOW);
        Serial.println("AMAN");
      }

By the way, I would hardly describe what you're doing in setup() as "calibrating sensor"! :)

PeterH: Don't you need to set pirstate back to LOW in this piece of code? Otherwise it will print "AMAN" repeatedly while the PIR input remains low.

      if (pirstate == HIGH){
        digitalWrite(ledpin, LOW);
        digitalWrite(spkrpin, LOW);
        Serial.println("AMAN");
      }

By the way, I would hardly describe what you're doing in setup() as "calibrating sensor"! :)

i will try, thanks bro, hahhaa calibrate sensor just for accesoris, not really calibrate, hehehhe

thank all my project was fixed :D