#include <SoftwareSerial.h>
SoftwareSerial BT(0, 1); // RX | TX
int DOOR = 2; // Door Status Input
int DSP1 = 3; // Display White
int DSP2 = 4; // Display Red
int DSP3 = 5; // Display Green
int RLY = 6; // Relay
int KLED = 7; // KeyLed Display
int BZR = 8; // Buzzer output
int TLED = 13;// Test LED 13
int KEY =A0; // Hard Key Input DONE
int MSI =A1; // Motion Sensor Input DONE
int LSI =A2; // Light Sensor Input DONE
int EDOR; // Enable Door Status Input DONE
int EMSI; // Enable Motion Sensor Input DONE
int ELSI; // Enable Light Sensor Input DONE
int EHKI; // Enable Hard Key Input DONE
int EKLED; // Enable Key Light DONE
int EAID; // Action In Dark Enable DONE
int AIDA1; // Action In Dark Activation 1 DONE
int AIDA2; // Action In Dark Activation 2 DONE
int EMSS; // Enable Motion Sensor Sound DONE
int EMSL; // Enable Motion Sensor Light DONE
int MSDL; // Motion Sensor Define Ligh DONE
int EMST; // Enable Motion Sensor Trugger DONE
int MSDD; // Motion Sensor Define Delay DONE
int EDSL; // Enable Door Define Light DONE
int EDST; // Enable Door Status Timer DONE
int EDSA; // Enable Door Status Alarm DONE
int DSAW; // DOOR Status Alarm Wait DONE
int EDSAL; // Enable Door status Alarm Light DONE
int DSAL; // Door Signal Alarm Light
int HKAB; // Hard Key Action of Buzzer
int HKAL; // Hard Key Action of Light Define LIGHT (DEFULT ACTION)
int HKAT; // Hard Key Action of Trugger
int DDIA; // Digital Delay in Action DONE
int DRKA; // Delay of Relay when Key in Action DONE
int LSL; // Light Sensor Reading (To Adjust Trugger)
int HKL; // Hard Key Input Limit
int MSL; // Motion Sensor Input Limit
void setup()
{
Serial.begin(9600);
BT.begin(9600);
pinMode(DOOR, INPUT);
pinMode(DSP1, OUTPUT);
pinMode(DSP2, OUTPUT);
pinMode(DSP3, OUTPUT);
pinMode( RLY, OUTPUT);
pinMode(KLED, OUTPUT);
pinMode(BZR, OUTPUT);
pinMode(TLED, OUTPUT);
digitalWrite(DOOR, LOW);
digitalWrite(DSP1, LOW);
digitalWrite(DSP2, LOW);
digitalWrite(DSP3, LOW);
digitalWrite(RLY, LOW);
digitalWrite(KLED, LOW);
digitalWrite(BZR, LOW);
digitalWrite(TLED, LOW);
}
void loop()
{
/*
if(BT.available()>0)
{ Serial.write(BT.read());}
if(Serial.available()>0)
{BT.write(Serial.read());
delay(10);}
*/
// Light Sensor Configuration
ELSI = 1; // Enable Light Sensor Input
EAID = 1; // Enable Action in Dark
LSL = 800; // Light Sensor Reading (To Adjust Trugger)
AIDA1 = DSP3; // Action In Dark Activation 1
AIDA2 = DSP2; // Action In Dark Activation 2
// Hard Key Configuration
EHKI = 1; // Enable Hard Key Input
HKL = 900; // Hard Key Input Limit
HKAB = 1; // Hard key action buzzer enable
HKAT = 1; // Hard key action trugger enable
HKAL = DSP2; // Hard key action light enable
DRKA = 500; // Delay of Relay when Key IN Action
// Motion Sensor Configuration
EMSI = 1; // Enable Motion Sensor
MSL = 900; // Motion Sensor Input Limit
EMSS = 1; // Enable Motion Sensor Sound
EMSL = 1; // Enable Motion Sensor Light
EMST = 1; // Enable Motion Sensor Trugger
MSDD = 1000; // Motion Sensor Define Delay
MSDL = DSP1; // Motion Sensor Define Light
// Door Status Configuratoin
EDOR = 1; // Enable Door Status Input DONE
EDSL = DSP1; // Enable Door Define Light DONE
DSAL = DSP2; // DOOR SIGNAL Alarm Light DONE
EDST = 1; // Enable Door Status Timer DONE
EDSA = 1; // Enable Door Status Alarm DONE
DSAW = 9000; // DOOR Status Alarm Wait DONE
EDSAL= 1; // Enable Door status Alarm Light DONE
DDIA = 500; // Digital Delay in Action// A Global Delay in General Action
// Night Sensor Based Light, Kled will active on Dark
if (ELSI == true )
{ LSI = analogRead(A2);}
if (LSI > LSL)
{ digitalWrite(KLED, HIGH); delay(DDIA);}
else
{ digitalWrite(KLED, LOW) ; delay(DDIA);}
// Action In Dark
if (EAID == true && ELSI == true && LSI > LSL)
{ digitalWrite(AIDA1, HIGH); delay(DDIA);
digitalWrite(AIDA2, HIGH); delay(DDIA);}
else
{ digitalWrite(AIDA1, LOW) ; delay(DDIA);
digitalWrite(AIDA2, LOW) ; delay(DDIA);}
// Action Of Hard Key Activation
if ( EHKI == true)
{ KEY = analogRead(A0); }
if ( KEY > HKL)
{ digitalWrite(HKAL, HIGH);}
else
{ digitalWrite(HKAL, LOW); }
if (EHKI == true && KEY > HKL && HKAB != 0)
{ digitalWrite(BZR, HIGH); delay(DDIA);}
else
{ digitalWrite(BZR, LOW);}
if (EHKI == true && KEY > HKL && HKAT != 0)
{ digitalWrite(RLY, HIGH); delay(DRKA);}
else
{ digitalWrite(RLY, LOW);}
// Motion Sensor Actions
if (EMSI == true)
{ MSI = analogRead(A1); }
if (MSI > MSL && EMSS == true)
{ digitalWrite(BZR, HIGH);
delay(MSDD);
digitalWrite(BZR, LOW); }
if (MSI > MSL && EMSL == true)
{ digitalWrite(MSDL, HIGH);
delay(MSDD);
digitalWrite(MSDL, LOW); }
if (MSI > MSL && EMST == true)
{ digitalWrite(RLY, HIGH);
delay(MSDD);
digitalWrite(RLY, LOW); }
// Door Sensor Action
if (EDOR == true)
{ DOOR = digitalRead(2);}
if (DOOR == HIGH)
{ digitalWrite(EDSL, HIGH); delay(DDIA);}
else
{ digitalWrite(EDSL, LOW);}
if (EDOR == true && DOOR == HIGH && EDSA == true)
{ digitalWrite(DSAL, HIGH);}
if (DOOR == LOW)
{ digitalWrite(DSAL, LOW);
digitalWrite(EDSL, LOW);}
/*
int EDST; // Enable Door Status Timer DONE
int EDSA; // Enable Door Status Alarm DONE
int DSAW; // DOOR Status Alarm Wait DONE
int EDSAL; // Enable Door status Alarm Light DONE
*/
}