Intruder alarm.

Hi!

I am working on an intruder alarm using the PIR sensor. I was able to get the PIR sensor to work with with the Led and a buzzer( i.e LED flashes and buzzer buzzes when there is an intruder). Now, I am trying to include a keypad lock, so that the PIR sensor starts working when I enter a code, and stops working when I enter the code again. How do I incorporate that into my code? hanks

Thanks in advance for the help guys! :slight_smile:

You need to show us your code before we can tell you how to incorporate new code

I can use the keypad and the PIR sensor seperately, but i dont know how to combine the two codes and make it work.

PIR sensor code.

int val=0;
int ledPin=13;
int speakerPin=12;


void setup() {
  pinMode(13,OUTPUT);
  pinMode(11,INPUT);
  
}

void loop() {
  val=digitalRead(11);
  digitalWrite(13,val);
if (val==1)
{
  digitalWrite(ledPin,LOW);
  tone(speakerPin,2000,500);
  
}
}

keyPad Code.

// include Keypad library
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

//define the symbols on the buttons of the keypads
char keyMap[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
//              ROW   1, 2, 3, 4
byte rowPins[ROWS] = {2, 3, 4, 5}; // which Arduino pins to connect to
//              COL   1, 2, 3, 4
byte colPins[COLS] = {6, 7, 8, 9}; // which Arduino pins to connect to
//create instance of keypad
Keypad matrixKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, ROWS, COLS); 
void setup(){
  Serial.begin(9600);  // set up serial port
  pinMode (ledPin,OUTPUT);//set up led
}
void loop(){
  char keyPressed = matrixKeypad.getKey();  // read in key press
if (keyPressed != NO_KEY){  // if key has been pressed
    Serial.println(keyPressed);  // print key over serial port

  }
}

How do i combine the two so that the PIR sensor is activated when i enter a code.

Moderator edit: Code put into code boxes.

Help anyone?? Please!!! :slight_smile:

How do i combine the two so that the PIR sensor is activated when i enter a code.

If you declare a boolean flag called ‚ÄúPIRenabled‚ÄĚ, then set or reset this flag depending on whether the code has been entered correctly, then you can simply ignore any signals from the PIR if ‚ÄúPIRenabled‚ÄĚ is false.