home alarm system problem in code

Check the semicolon

/*
This is a simple alarm system 
that is activated by pressing a button
and  deactivated when you press the correct code
*/
#include <Password.h>

#include <Keypad.h>

Password password = Password( "7777" );

const byte ROWS = 4; 
const byte COLS = 4; 
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3', 'A'  }
  ,
  {
    '4','5','6', 'B'  }
  ,
  {
    '7','8','9', 'C'  }
  ,
  {
    '*','0','#', 'D'  }
};

byte rowPins[ROWS] = {  
  8, 7, 6,5 };
byte colPins[COLS] = { 
  12, 11, 10,9 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 3, 2, 1, 0,14);

const int buttonPin_door =15;    // Magnetic door contact
const int buttonPin_on=17;       // Power system  button
const int ledPin_alarm= 18;      // Alarm Led
int run =0;

int buttonState_door = 1;         // Door initial state
int buttonState_on= 0;            // Power system  button initialstate 
long previousMillis = 0;
long interval = 10000;


void setup(){

  pinMode(buttonPin_door, INPUT);  
  pinMode(buttonPin_on,INPUT);
  pinMode(ledPin_alarm ,  OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);


  

  keypad.addEventListener(keypadEvent); 
  keypad.setDebounceTime(250);           //Keypad button time


}

void loop(){
  buttonState_door = digitalRead(buttonPin_door);  
  buttonState_on= digitalRead(buttonPin_on);

//conditions for  activation the  system

  if (buttonState_on == HIGH  && buttonState_door  == HIGH ) {
    lcd.setCursor(0,0);
    lcd.print("run         ");

    run = HIGH;
  }
  
  // conditions when you return home and open the door
   unsigned long currentMillis = millis();
  
  if (run == HIGH  &&buttonState_door == LOW){
    if(currentMillis - previousMillis > interval) 
    // save the last time you blinked the LED 
    previousMillis = currentMillis; 
      if (run == HIGH)
      digitalWrite(ledPin_alarm,HIGH);
    lcd.setCursor(0,0);
    lcd.print("alarm...          ");
    lcd.setCursor(0,1);
    lcd.print("                                  ");
  
}
    
  


  keypad.getKey();
}


void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:

    switch (eKey){
    case '#': 
      guessPassword(); 
      break;
    default:
      password.append(eKey);
    }
  }


}





void guessPassword(){

  if (password.evaluate()){
    digitalWrite(ledPin_alarm,LOW);
    (run = LOW);
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("CORRECT PASSWORD ");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("system          ");
    lcd.setCursor(0,1);
    lcd.print("off       ");



    password.reset(); 
  }
  else{




    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("WRONG PASSWORD ");
    password.reset(); 
  }

}

Click on 'modify', highlight the code, click on the # icon, click on 'save'

sorry i can understand you :frowning:

Please put your code inside [ code ] tags using the method described by AWOL.

sorry i can understand you

Look at how the program code looks in your original post and compare its appearance to the other code that you have posted in your recent replies. It is much easier to read because the moderator put it in a "Code Box" for you as mentioned in the edit that he added below the code (Moderator edit: Code put into code box. AWOL).

In reply #12 he gave you instructions on how to do this and in reply #22 he told you again.

In reply #24 you were again told how to find the instructions.

Don

/*
This is a simple alarm system 
that is activated by pressing a button
and  deactivated when you press the correct code
*/
#include <Password.h>

#include <Keypad.h>

Password password = Password( "7777" );

const byte ROWS = 4; 
const byte COLS = 4; 
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3', 'A'  }
  ,
  {
    '4','5','6', 'B'  }
  ,
  {
    '7','8','9', 'C'  }
  ,
  {
    '*','0','#', 'D'  }
};

byte rowPins[ROWS] = {  
  8, 7, 6,5 };
byte colPins[COLS] = { 
  12, 11, 10,9 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 3, 2, 1, 0,14);

const int buttonPin_door =15;    // Magnetic door contact
const int buttonPin_on=17;       // Power system  button
const int ledPin_alarm= 18;      // Alarm Led
int run =0;

int buttonState_door = 1;         // Door initial state
int buttonState_on= 0;            // Power system  button initialstate 
long previousMillis = 0;
long interval = 10000;


void setup(){

  pinMode(buttonPin_door, INPUT);  
  pinMode(buttonPin_on,INPUT);
  pinMode(ledPin_alarm ,  OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);


  

  keypad.addEventListener(keypadEvent); 
  keypad.setDebounceTime(250);           //Keypad button time


}

void loop(){
  buttonState_door = digitalRead(buttonPin_door);  
  buttonState_on= digitalRead(buttonPin_on);

//conditions for  activation the  system

  if (buttonState_on == HIGH  && buttonState_door  == HIGH ) {
    lcd.setCursor(0,0);
    lcd.print("run         ");

    run = HIGH;
  }
  
  // conditions when you return home and open the door
   unsigned long currentMillis = millis();
  
  if (run == HIGH  &&buttonState_door == LOW){
    if(currentMillis - previousMillis > interval) 
    // save the last time you blinked the LED 
    previousMillis = currentMillis; 
      if (run == HIGH)
      digitalWrite(ledPin_alarm,HIGH);
    lcd.setCursor(0,0);
    lcd.print("alarm...          ");
    lcd.setCursor(0,1);
    lcd.print("                                  ");
  
}
    
  


  keypad.getKey();
}


void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:

    switch (eKey){
    case '#': 
      guessPassword(); 
      break;
    default:
      password.append(eKey);
    }
  }


}





void guessPassword(){

  if (password.evaluate()){
    digitalWrite(ledPin_alarm,LOW);
    (run = LOW);
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("CORRECT PASSWORD ");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("system          ");
    lcd.setCursor(0,1);
    lcd.print("off       ");



    password.reset(); 
  }
  else{




    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("WRONG PASSWORD ");
    password.reset(); 
  }

}

I made it according to your instructions. can you help me now ? about my problem?

enterpc:
... yes this code work ok.

What problem?

when I use the code in #26 .The ledPin_alarm start after 10 sec automatically
i need the ledpin alarm will beginning if i didn't the correct password in time 10sec

noone can't help me? :frowning:

enterpc:
when I use the code in #26 .The ledPin_alarm start after 10 sec automatically
i need the ledpin alarm will beginning if i didn't the correct password in time 10sec

No-one is replying because we don't understand you. Perhaps translate back into your own language and see if what you are saying making makes sense.

Your code doesn't compile because we don't have the file Password.h. Please explain where you got it from or show what is in it.

What Arduino are you using? How is it wired up?

Your use of variable names here is confusing:

void keypadEvent(KeypadEvent eKey){

Is this some sort of homework?

enterpc:
sorry i can understand you :frowning:

...

enterpc:
noone can't help me? :frowning:

Personally I try hard to understand people who maybe don't speak English as their first language. But you seem to be repeatedly saying the opposite of what you mean. Do you have a friend that can help you translate what you are saying to help bridge the communication gap?

enterpc:
when I use the code in #26 .The ledPin_alarm start after 10 sec automatically

I don't see how - looks to me that once it is set, the alarm will go off as soon as you open the door.

Those statements you have concerning millis don't do anything useful = previousmillis gets set every 10 seconds, but you never do anything with it.

You need to capture the time when the door opens - keep previousDoorState and save millis when it changes from closed to open. Then you can check whether 10 seconds have passed since then to control when the alarm comes on. Entering the password in that time is supposed to cancel that alarm I believe.

Well go from the beginning, first of all I’m sorry for the upheaval caused.
The archives(Password. h , Keypad .h , LiquidCrystal .h) are from the official site of Arduino.
The wirings are all ok! I have got the Arduino Uno
i try to make a small alarm system. the system is activated when i press the "button Pin _on" and it is deactivated when i put the correct password.
Also i have got the "button State _door" which is a magnetic contact on the door .the magnetic contact shows if the door is opened or closed, this is a (NC) contact.
the "led Pin _alarm" which is the alarm siren. and the variable "RUN" is showing that the system is running.

How it works:
When i put the "button Pin _on" and the door is closed then do "RUN = HIGH" then the alarm system is running

if the sytem alarm is running,and the door is opening then wait 10 sec.
and if inside of these 10 sec. I do not put the correct password do the:
(ledPin_alarm = HIGH)
if i put the correct password after 10 sec. do the:
(ledPin_alarm = LOW)and the: (RUN = LOW)

thanks alot!!!!!!

/*
This is a simple alarm system 
that is activated by pressing a button
and  deactivated when you press the correct code
*/
#include <Password.h>

#include <Keypad.h>

Password password = Password( "7777" );

const byte ROWS = 4; 
const byte COLS = 4; 
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3', 'A'  }
  ,
  {
    '4','5','6', 'B'  }
  ,
  {
    '7','8','9', 'C'  }
  ,
  {
    '*','0','#', 'D'  }
};

byte rowPins[ROWS] = {  
  8, 7, 6,5 };
byte colPins[COLS] = { 
  12, 11, 10,9 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 3, 2, 1, 0,14);

const int buttonPin_door =15;    // Magnetic door contact
const int buttonPin_on=17;       // Power system  button
const int ledPin_alarm= 18;      // Alarm Led
int run =0;

int buttonState_door = 1;         // Door initial state
int buttonState_on= 0;            // Power system  button initialstate 
long previousMillis = 0;
long interval = 10000;


void setup(){

  pinMode(buttonPin_door, INPUT);  
  pinMode(buttonPin_on,INPUT);
  pinMode(ledPin_alarm ,  OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);


  

  keypad.addEventListener(keypadEvent); 
  keypad.setDebounceTime(250);           //Keypad button time


}

void loop(){
  buttonState_door = digitalRead(buttonPin_door);  
  buttonState_on= digitalRead(buttonPin_on);

//conditions for  activation the  system

  if (buttonState_on == HIGH  && buttonState_door  == HIGH ) {
    lcd.setCursor(0,0);
    lcd.print("run         ");

    run = HIGH;
  }
  
  // conditions when you return home and open the door
   unsigned long currentMillis = millis();
  
  if (run == HIGH  &&buttonState_door == LOW){
    if(currentMillis - previousMillis > interval) 
    // save the last time you blinked the LED 
    previousMillis = currentMillis; 
      if (run == HIGH)
      digitalWrite(ledPin_alarm,HIGH);
    lcd.setCursor(0,0);
    lcd.print("alarm...          ");
    lcd.setCursor(0,1);
    lcd.print("                                  ");
  
}
    
  


  keypad.getKey();
}


void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:

    switch (eKey){
    case '#': 
      guessPassword(); 
      break;
    default:
      password.append(eKey);
    }
  }


}





void guessPassword(){

  if (password.evaluate()){
    digitalWrite(ledPin_alarm,LOW);
    (run = LOW);
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("CORRECT PASSWORD ");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("system          ");
    lcd.setCursor(0,1);
    lcd.print("off       ");



    password.reset(); 
  }
  else{




    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("WRONG PASSWORD ");
    password.reset(); 
  }

}

Here:

  if (run == HIGH  &&buttonState_door == LOW){
    if(currentMillis - previousMillis > interval) 
      // save the last time you blinked the LED 
      previousMillis = currentMillis; 
    if (run == HIGH)
      digitalWrite(ledPin_alarm,HIGH);
  ...

  }

If the system is running, and the door is opened you turn on the alarm. There is no test there, "is 10 seconds up?", before doing this line:

      digitalWrite(ledPin_alarm,HIGH);

how can i insert 10 sec than control time ?
can you understand what i need to do . after by my last replay ?

When the door is opened you need to remember the time. eg.

if (run == HIGH  && buttonState_door == LOW && previousButtonState_door == HIGH)
  {
  door_open_time = millis ();
  }

Then later on you can check if it has been open for 10 seconds, eg.

 if ((run == HIGH) && (millis () - door_open_time) >= 10000 )
      digitalWrite(ledPin_alarm,HIGH);

I must to i state the previous "ButtonState_door"
like this?

int buttonState_door = 1;         // Door initial state
int buttonState_on= 0;            // Power system  button initialstate 
long previousMillis = 0;
long interval = 10000;
previousButtonState_door=0;

Does that compile?

http://einstein.drexel.edu/courses/Comp_Phys/General/C_basics/

(previousButtonState_door == HIGH) why ?

  if (buttonState_on == HIGH  && buttonState_door  == HIGH ) {
    lcd.setCursor(0,0);
    lcd.print("run         ");

    run = HIGH;
  }

I try this code but nothing

/*
This is a simple alarm system 
that is activated by pressing a button
and  deactivated when you press the correct code
*/
#include <Password.h>

#include <Keypad.h>

Password password = Password( "7777" );

const byte ROWS = 4; 
const byte COLS = 4; 
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3', 'A'  }
  ,
  {
    '4','5','6', 'B'  }
  ,
  {
    '7','8','9', 'C'  }
  ,
  {
    '*','0','#', 'D'  }
};

byte rowPins[ROWS] = {  
  8, 7, 6,5 };
byte colPins[COLS] = { 
  12, 11, 10,9 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 3, 2, 1, 0,14);

const int buttonPin_door =15;    // Magnetic door contact
const int buttonPin_on=17;       // Power system  button
const int ledPin_alarm= 18;      // Alarm Led
int run =0;
int door_open_time =0;
int buttonState_door = 1;         // Door initial state
int buttonState_on= 0;            // Power system  button initialstate 



void setup(){

  pinMode(buttonPin_door, INPUT);  
  pinMode(buttonPin_on,INPUT);
  pinMode(ledPin_alarm ,  OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);


  

  keypad.addEventListener(keypadEvent); 
  keypad.setDebounceTime(250);           //Keypad button time


}

void loop(){
  buttonState_door = digitalRead(buttonPin_door);  
  buttonState_on= digitalRead(buttonPin_on);

//conditions for  activation the  system

  if (buttonState_on == HIGH  && buttonState_door  == HIGH ) {
    lcd.setCursor(0,0);
    lcd.print("run         ");
     lcd.setCursor(0,1);
    lcd.print("                                  ");

    run = HIGH;
  }
  
  // conditions when you return home and open the door
  
  
  if (run == HIGH  &&buttonState_door == LOW){

  {
  door_open_time = millis ();
  } 
    // save the last time you blinked the LED 
    if ((run == HIGH) && (millis () - door_open_time) >= 10000 )
      digitalWrite(ledPin_alarm,HIGH);
     
    lcd.setCursor(0,0);
    lcd.print("alarm...          ");
    lcd.setCursor(0,1);
    lcd.print("                                  ");
  
}
    
  


  keypad.getKey();
}


void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:

    switch (eKey){
    case '#': 
      guessPassword(); 
      break;
    default:
      password.append(eKey);
    }
  }


}





void guessPassword(){

  if (password.evaluate()){
    digitalWrite(ledPin_alarm,LOW);
    (run = LOW);
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("CORRECT PASSWORD ");
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("system          ");
    lcd.setCursor(0,1);
    lcd.print("off       ");



    password.reset(); 
  }
  else{




    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("WRONG PASSWORD ");
    password.reset(); 
  }

}