//simple alarm system
int RipSensor1 = 12;
int RmkeyA = 3;
int RmkeyB = 5;
int RmkeyC = 6;
//--------------------------------------------------------------------------
void setup()
{
Serial.begin(9600);
pinMode(RipSensor1,INPUT);
pinMode(RmkeyA,INPUT);
pinMode(RmkeyB,INPUT);
pinMode(RmkeyC,INPUT);
pinMode(13,OUTPUT);
Serial.println(F("System Is Up & Running")); }
//----------------------------------------------------------------------
void loop()
{
Serial.println(F("Main Loop Start"));
digitalWrite(13,LOW); //for debugging
if (digitalRead(RmkeyA) == HIGH)
{
Rip1Status();
}
}
//----------------------------------------------------------------------
void AlarmSMS1()
{
//send sms to admin1
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Serial.println(F("SMS Sending to 1st ADMIN --->"));
Rip1Status(); // return to this void (monitoring)
}
//----------------------------------------------------------------------
void Rip1Status()
{
Serial.println(F("VOID Rip1 Start..."));
while (digitalRead(RmkeyB) == LOW) //Arm mode
{
digitalWrite(13,HIGH);
if (digitalRead(RipSensor1) == HIGH) //when Rip sensor sense motion
{
Serial.println(F("Movement ALARM --> PowerUP Relay 1 & 2"));
long RipTimer1 = 0;
long Rip01 = 0;
int z = 0;
int x = 0;
while (digitalRead(RmkeyC) == LOW)
{
RipTimer1++;
Serial.println(RipTimer1); //for debugging
if((z==0) && (RipTimer1 - Rip01 > 500)) //1st CheckPoint do something
{
z = 1;
Serial.println(F("1st CheckPoint OK"));
}
else if((x==0) && (RipTimer1 - Rip01 > 3000)) //2nd CheckPoint go on other void
{
x = 1;
AlarmSMS1();
}
}
Serial.println(F("C Key Pressed --> False Alarm")); //if button C pressed
RipTimer1 = 0;
z = 0;
x = 0;
Serial.println(F("Monitoring Loop ends --> GoTo Main Loop"));
break;
}
else Serial.println(F("Monitoring")); //for debugging
}
Serial.println(F("B Key Pressed --> Disarming")); //for debugging
Serial.println(F("Monitoring Loop ends --> GoTo Main Loop"));
loop();
}
I make this code & i have this problem:
Program start & wait for A key pressed to Arm mode. works ok
Press A key go to Arm mode (monitoring). works ok
When its on "monitoring", if i press B key, system disarming then go to void loop() and wait. works ok
When its on "monitoring" & Rip sensor sense movement, then alarm start and if i press C key then disarming as false alarm and go to void loop() and wait. works ok
When its on "monitoring" & Rip sensor sense movement, if i left alarm to complete, go to sms void send sms to admin and return to Rip void (monitoring).
But on this point if i press B button to disarm system this happen...
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
Monitoring
B Key Pressed --> Disarming
Monitoring Loop ends --> GoTo Main Loop
Main Loop Start
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012.............
Why this happen? What i am doing wrong?