int BZR1 = 2; // Buzzer output
int DSP1 = 3; // Display Blue
int DSP2 = 4; // Display Red
int DSP3 = 5; // Display Green
int KLD1 = 6; // KeyLed Display
int DOTR = 7; // Digital Trugger Output Relay
int Result = 8;
int KEY = A0; // HardKey Button
int DSS = A1; // Door Status Signal
int MSS = A2; // Motion Sensor Status
int LSS = A3; // Light Sensor Signal
int SVR = A4; // System Voltage Reader
int IRC = A5; // IR Receiver For Coded Data NOT IN USE FOR NOW
int DBU; // Define BuzzerBeep Up
int DBD; // Define BuzzerBeep Down
int DAW; // Define Alarm Wait
int LSL; // Light Sensor Limit
int DSL; // Door Signal Limit
int KSL; // Key Signal Limit
int MSL; // Motion Signal Limit
int DDL; // Define Display Light
int DLA; // Display light Acknownledgement
int DOL; // Define Open Light
int DAL; // Define Alarm Light
int SAK; // Sound Action Status Indicator On Key Press ENABLE/DISABLE
int SAM; // Sound Action Status Indicator On Movement ENABLE/DISABLE
int DSA; // Door Status Acknownledgement ENABLE/DISABLE
int MSA; // Motion Sensor Acknownledgement ENABLE/DISABLE
int LSA; // Light Sensor Acknownledgement ENABLE/DISABLE
int DAA; // Door Alarm Acknownledgement ENABLE/DISABLE
int HKA; // Hard Key Acknownledgement ENABLE/DISABLE
int CAS; // Current Alarm Status ENABLE/DISABLE
int MDT; // Motion Digital Trugger ENABLE/DISABLE
int HKT; // Hard KeyDigital Trugger ENABLE/DISABLE
int DDT; // Delay in Digital Trugger
int DSD; // Door Signal Delay
int DCB; // Delay In common Beep
int DLN; // Display Light In Night
int DCO = 0; // Door Current Open Time
int ODCO;
int SDCO;
int DOLE;
int DDLE;
int DALE;
void setup()
{
Serial.begin(9600);
pinMode(BZR1, OUTPUT);
pinMode(DSP1, OUTPUT);
pinMode(DSP2, OUTPUT);
pinMode(DSP3, OUTPUT);
pinMode(KLD1, OUTPUT);
pinMode(DOTR, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(DOTR, LOW);
digitalWrite(DSP1, HIGH);
digitalWrite(DSP2, HIGH);
digitalWrite(DSP3, HIGH);
digitalWrite(BZR1, LOW);
digitalWrite(KLD1, LOW);
pinMode(KEY, INPUT);
pinMode(DSS, INPUT);
pinMode(MSS, INPUT);
pinMode(LSS, INPUT);
pinMode(SVR, INPUT);
pinMode(IRC, INPUT);
}
void loop()
{
//working code of KEY Action, need to define form user input and add more action as required
SAK = true; // Sound on Action on Key
SAM = true; // Sound on Action on Movement
HKA = true; // Hard Key Acknownledgment
DSA = true; // Door Status Acknownledgment
/*MSA = true; // Motion Sensor Acknownledgment */
LSA = true; // Light Sensor Acknownledgment
DAA = true; // Door Alarm Acknownledgment
HKT = true; // Hard Key will trugger Relay Acknownledgment
MDT = true; // Motion Digital Trugger
DLA = true; // Display Light Acknownledgment On/Off Display Light
DLN = false; // Display Light In Night
DOLE = true; // Door Open light enable
DDLE = true; // Door Display light enable
DALE = true; // Door Alarm Light enable
DOL = DSP3; // Door Open Light GREEN COLOUR
DDL = DSP1; // Display Light BLUE COLOUR
DAL = DSP2; // Defined Alarm Light RED COLOUR
DBU = 450; //Define BuzzerBeep Up
DBD = 250; //Define BuzzerBeep Down
DAW = 9000; //Define Alarm Wait
DDT = 500; //Digital Delay Trugger
DSL = 900; //Door Signal Limit
KSL = 700; //Key Signal Limit
LSL = 500; //Light Sensor Limit
MSL = 800; //Motion Sensor Signal Limit
DSD = 150; //Door Status Delay
DCB = 150; //Delay in common beep
// Hard Key Reading and Response/COMPLETED
KEY = analogRead(A0);
if (HKA == true && KEY > KSL)
{
digitalWrite(DOL, LOW);
}
if (HKA == true && KEY > KSL && SAK == true)
{
digitalWrite(BZR1, HIGH);
delay(DCB);
digitalWrite(BZR1, LOW);
}
if (HKA == true && KEY > KSL && HKT == true)
{
digitalWrite(DOTR, HIGH);
delay(DDT);
digitalWrite(DOTR, LOW);
}
//Light Sensor with Enable Option
LSS = analogRead(A3);
if (LSA == true && LSS > LSL)
{ digitalWrite(KLD1, HIGH);
delay(1500); }
else
{digitalWrite(KLD1, LOW);}
//Reading Motion Sensor ON/OFF Door Light will Glow
MSS = analogRead(A2);
if (MSA == true && MSS > MSL )
{
digitalWrite(DOL, LOW);
delay(DDT);
digitalWrite(DOL, HIGH);
}
//Sound on Motion Sensor On/Off along Light
if (MSA == true && MSS > MSL && SAM == true)
{
digitalWrite(DOL, LOW);
digitalWrite(BZR1,HIGH);
delay(DDT);
digitalWrite(DOL, HIGH);
digitalWrite(BZR1,LOW);
}
//Digital Trugger ON/OFF over Motion Sensor
if (MSA == true && MSS > MSL && MDT == true)
{
digitalWrite(DOL, LOW);
digitalWrite(DOTR, HIGH);
delay(DDT);
digitalWrite(DOL, HIGH);
digitalWrite(DOTR, LOW);
}
//Defining Door Status functions
DSS = analogRead(A1);
if (DSA == true && DSS > DSL && DOLE == true )
{ MSA = false;
digitalWrite(DOL, LOW);
SDCO = millis();
delay(DSD); // Door Status Delay
}
else
{ MSA = true;
digitalWrite(DOL, HIGH);
ODCO = millis();
}
if (DSA == true && DSS > DSL && SDCO-ODCO > DAW)
{ DOLE = false;
digitalWrite(BZR1, HIGH);
digitalWrite(DOL, HIGH);
digitalWrite(DAL, LOW); }
else
{ digitalWrite(BZR1, LOW);
digitalWrite(DAL, HIGH);
}
}