PIR home security

Hello guys,
I’m a newbie into Arduino, and i’m deeply intrested in making a home security system with 4 PIR motion sensors and output on 16, 2 LCD screen.

I used the basic PIR code from arduino to get output on diferent LED’s for corresponding PIR’s; but the problem is at night, its hard for me to remember which LED is which zone! So i decided to hook it up to an LCD screen.

Im so depressed that my initial attempts with coding were an utter failure; but some how i got a sketch from codekaola.It works fine with one PIR, but i dont know how to modify the sketch to attach 3 more sensors!

This is the code that I got:

#include <LiquidCrystal.h>

int calibrationTime = 10; // seconds to calibrate PIR
long unsigned int pause = 5000; // timeout before we “all” motion has ceased
long unsigned int lowIn; // the time when the sensor outputs a low impulse

boolean lockLow = true;
boolean takeLowTime;

int flashCnt = 4; // number of times the LCD will flash when there’s motion
int flashDelay = 500; // number of ms to wait while flashing LCD
int pirPin = 7; // the digital pin connected to the PIR sensor’s output
int lcdPin = 13; // pin connected to LCD
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup() {
// Calibrates the PIR

pinMode(pirPin, INPUT);
pinMode(lcdPin, OUTPUT);

digitalWrite(pirPin, LOW);


// give the sensor some time to calibrate

for(int i = 0; i < calibrationTime; i++){


void clearLcd() {
// Clears the LCD, turns off the backlight
lcd.begin(20, 4);
digitalWrite(lcdPin, LOW);

void alertLcd() {
// Turns on the LCD backlight and notifies user of motion
lcd.setCursor(2, 1);
digitalWrite(lcdPin, HIGH);
lcd.print(“INTRUDER ALERT!!”);
lcd.setCursor(2, 2);

void loop() {
// Main execution loop

if(digitalRead(pirPin) == HIGH) {
// flash an alert a few times
for (int c = 0; c < flashCnt; c++) {

if(lockLow) {
// makes sure we wait for a transition to LOW before any further
// output is made:
lockLow = false;
takeLowTime = true;

if (digitalRead(pirPin) == LOW) {

if (takeLowTime) {
// save the time of the transition from high to LOW
// make sure this is only done at the start of a LOW phase
lowIn = millis();
takeLowTime = false;

// if the sensor is low for more than the given pause,
// we assume that no more motion is going to happen
if (!lockLow && millis() - lowIn > pause) {
// makes sure this block of code is only executed again after
// a new motion sequence has been detected
lockLow = true;


Thanking You

First suggestion: modify alertLcd() so that it takes a string as an argument eg alertLCD(“All is well”). Get that to work with your existing sketch. This will allow you to send a different message for each sensor later.

Next suggestion: learn about arrays. You will need arrays for each of the parameters such as pirPin, lockLow etc . Modify your sketch so that it uses for example pirPins[0] instead of pirPin.

Finally you can put a for loop just inside your main loop() that iterates over as many pir sensors as you have input pins- each one will have its own index into the arrays.

If you do all this you will have learnt a lot of valuable lessons about programming.

Heres a little hint as to what it might look like

int pirPins[] = {2, 4, 8, 3, 6};

void loop()
   for (int i=0; i <6; i++){
      if digitalRead(pirPins[i]) {
      // etc etc

Thanks a lot for dopping by..but u know the thing is, i am a total novice in arduino..jus a few months...the code that i put above too, i dont understand even a line...! Im totally depressed...beenbsitting with this project for over 3 months now...
Are there any simple codes ( ready made), which has to b altered only a bit to get it to work?
Please help