problem about coding...

hello.. i would like to ask from all of you about my problem coding. The problem i got after im upload this coding is when i put the password.. all of sensor ( magnetic door 1,magnetic door 2, motion sensor) detect suddenly even there is no trigger when i put at
if (alarmActive == 1){
if (digitalRead(pirPin1) == HIGH)
zone = 0;
if (digitalRead(reedPin1) == HIGH)
zone = 1;
if (digitalRead(reedPin2) == HIGH)
zone = 2;

and my piezo does not on. when i put again my password its cant deactivate.
hope you all can share any information to me :slight_smile:

im using arduino mega 2560, piezo buzzer, lcd 16x2,keypad 4x4, RGB LED, Motion Sensor..

FinalProjectHomeSecurity.txt (9.99 KB)

i would like to ask from all of you about my problem coding.

The problem is more likely how you wired the hardware.

  //lcd.print(now.month(), DEC);
  //We print the day
  //lcd.print(, DEC);
  //We print the year
  //lcd.print(now.year(), DEC);
  //lcd.print(' ');

  //lcd.print(now.hour(), DEC);
  //lcd.print(now.minute(), DEC);
  //lcd.print(now.second(), DEC);

Might I respectfully suggest that you get your delete key fixed. We don't need to see all this commented out stuff.


Call a function whose only purpose is to return a value. Ignore the returned value. Why bother?

    if (digitalRead(pirPin1) == LOW)
      zone = 0;

The alarmTriggered() should only be triggered when the PIR pin changes state, not whenever it is in some state.

If the alarm ever is triggered, it will be a long time before you can reset it, since nothing happens while delay() is running.

So my coding just a bit problem and more at my wired hardware.. Thats what u mean sir? And im sorry about the command part.. Thanks for your advise sir.. Im appreciate your help


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your switched inputs wired, I see you do not have pullup resistors set in software.
If your digital inputs are simple open/close switches, do you have 10K resistors connected to the digital inputs.
If your switches connect input to 5V, do you have a 10K resistor from input to gnd.
If your switches connect input to gnd, do you have a 10K resistor from input to 5V.
You cannot leave an input that you are using open circuit, it will not assume 0V, but float, usually at near the last voltage that was connected to it.

Tom..... :slight_smile: