AWOL:
Think carefully about this section.
door_open_time = millis ();
lcd.print("dadas");
if ((magnetic0 == HIGH) && (millis () - door_open_time) >= 10000){
Please post your code - all of it.
#include <Wire.h>
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <SimpleTimer.h>
char* secretCode = "1234";
int position = 0;
//PIN CONTROL START
const int buzzer = 7; //BUZZER'S PIN
const int pir0 = A1; //MOTION DETECTOR 1
const int pir1 = 5; //MOTION DETECTOR 2
const int pir2 = 6; //MOTION DETECTOR 3
const int magnetic0 = 9; //MAGNETIC CONTACTS SET 1
const int magnetic1 = A0; //MAGNETIC CONTACTS SET 2
int relay = 8; //RELAY'S PIN FOR SIRIN AND STROBE
int setLocked;
//PIN CONTROL END
//LCD CODE START
#define lcdAddr 0x27
//LCD I2C ADDRESS
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY
//LCD CODE END
//KEYPAD CODE START
const byte ROWS = 3;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'9','6','3','#'},
{'8','5','2','0'},
{'7','4','1','*'},
};
byte rowPins[ROWS] = {3,2,1};
byte colPins[COLS] = {4,5,6,0};
int i2caddress = 0x20; // KEYPAD I2C ADDRESS
Keypad_I2C kpd = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, i2caddress );
//KEYPAD CODE END
#define C0 440
//BUZZER TONE CLASSIC
void setup(){
lcd.begin(16,2); //INITIALIZE LCD
lcd.setBacklight(1); // ENABLE LCD BACKLIGHT
Serial.begin(9600); // ENABLE SERIAL FOR DEBUG PURPOSES
kpd.begin(); //INITIALIZE KEYPAD
//pinMode(buzzer, OUTPUT);
//pinMode(pir0, INPUT);
//pinMode(pir1, INPUT);
//pinMode(pir2, INPUT);
pinMode(magnetic0, INPUT);
//pinMode(magnetic1, INPUT);
pinMode(relay, OUTPUT);
lcd.setCursor(0,0);
lcd.print("--INITIALIZING--");
lcd.setCursor(0,1);
lcd.print("Please Wait... ");
delay(5000);//GIVE MOTION SENSOR TO CALIBRATE
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" *ACTIVE* ");
delay(2000);
}
void indicator_pir0(){
lcd.setCursor(0,0);
lcd.print(" MOTION SENSOR 1");
lcd.setCursor(0,1);
lcd.print(" *ACTIVE* ");
delay(1000);
}
void indicator_pir1(){
lcd.setCursor(0,0);
lcd.print(" MOTION SENSOR 2");
lcd.setCursor(0,1);
lcd.print(" *ACTIVE* ");
delay(1000);
}
void indicator_pir2(){
lcd.setCursor(0,0);
lcd.print(" MOTION SENSOR 3");
lcd.setCursor(0,1);
lcd.print(" *ACTIVE* ");
delay(1000);
}
void indicator_magnetic0(){
lcd.setCursor(0,0);
lcd.print(" DOOR SENSOR 1 ");
lcd.setCursor(0,1);
lcd.print(" *ACTIVE* ");
delay(800);
tone(7,C0,100);
}
void indicator_magnetic1(){
lcd.setCursor(0,0);
lcd.print(" DOOR SENSOR 2 ");
lcd.setCursor(0,1);
lcd.print(" *ACTIVE* ");
delay(1000);
}
void trip_pir0(){
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" MOTION 1");
digitalWrite(relay, HIGH);
}
void trip_pir1(){
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" MOTION 2");
digitalWrite(relay, HIGH);
}
void trip_pir2(){
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" MOTION 3");
indicator_pir2();
}
void trip_magnetic0(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" BREACH DOOR 1");
digitalWrite(relay, HIGH);
indicator_magnetic1();
}
void trip_magnetic1(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" BREACH DOOR 2");
indicator_magnetic1();
}
long door_open_time = 0;
void sensorcheck(){
int magnetic0 = digitalRead(A0);
//int magnetic1 = digitalRead(A0);
int pir0 = digitalRead(A1);
//int pir1 = digitalRead(5);
//int pir2 = digitalRead(6);
if ( magnetic0 == HIGH){
trip_magnetic0();
}
else if ( magnetic1 == HIGH){
trip_magnetic1();
}
else if ( pir0 == HIGH){
trip_pir0();
}
else if ( pir1 == HIGH){
trip_pir1();
}
else if ( pir2 == HIGH){
trip_pir2();
}
}
int test=0;
int test2=0;
int lastpir0=LOW;
void(* resetFunc) (void) = 0;
void loop()
{
char key = kpd.getKey();
if (key == '*' || key == '#') {
position = 0;
//setLocked == true;
}
if (key == secretCode[position]) {
position++;
}
//if (position == 6) {
// setLocked == false;
//}
delay(100);
if (position == 0 && test == 0) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("ARMING");
test = 1;
}
else if (position == 4){
digitalWrite(relay, LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("DISSARMED");
test = 0;
//resetFunc();
}
if (magnetic0 == HIGH){
door_open_time = millis ();
lcd.print("dadas");
if ((magnetic0 == HIGH) && (millis () - door_open_time) >= 1000){
digitalWrite(relay,HIGH);
lcd.setCursor(0,0);
lcd.print("alarm... ");
lcd.setCursor(0,1);
lcd.print(" ");
trip_magnetic1();
}
}
sensorcheck();
}
/*if (position == 0 && pir0 == HIGH){
door_open_time = millis ();
if ((position == 0) && (millis () - door_open_time) >= 10000 ){
digitalWrite(relay,HIGH);
lcd.setCursor(0,0);
lcd.print("alarm... ");
lcd.setCursor(0,1);
lcd.print(" ");
}
}
}
void setLocked(int locked)
{
if (setlocked == true) {
//digitalWrite(relay, HIGH);
sensorcheck();
lcd.clear();
lcd.setCursor(0,1);
lcd.print("ARMED");
}
else if (setlocked == true) {
digitalWrite(relay, LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("DISSARMED");
}
}
*/