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
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(lcdPin, OUTPUT);
digitalWrite(pirPin, LOW);
clearLcd();
// give the sensor some time to calibrate
lcd.setCursor(0,0);
lcd.print("Calibrating...");
for(int i = 0; i < calibrationTime; i++){
lcd.print(".");
delay(1000);
}
lcd.print("done");
delay(50);
}
void clearLcd() {
// Clears the LCD, turns off the backlight
lcd.begin(20, 4);
lcd.clear();
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);
lcd.print("================");
}
void loop() {
// Main execution loop
if(digitalRead(pirPin) == HIGH) {
// flash an alert a few times
for (int c = 0; c < flashCnt; c++) {
alertLcd();
delay(flashDelay);
lcd.clear();
delay(flashDelay);
}
if(lockLow) {
// makes sure we wait for a transition to LOW before any further
// output is made:
lockLow = false;
delay(50);
}
takeLowTime = true;
}
if (digitalRead(pirPin) == LOW) {
clearLcd();
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;
delay(50);
}
}
}
CAN ANYONE PLEASE HELP ME WITH SKETCH MODIFICATION?
Thanking You