Pages: 1 [2] 3 4 5   Go Down
Author Topic: home alarm system problem in code  (Read 4179 times)
0 Members and 1 Guest are viewing this topic.
Leeds, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 134
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So show us the code that doesn't work?
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem is that when I open the door I need delay 10 sec i tried the millis() but nothing this is my code

...

yes this code work ok. It's without millis()

Forgive me for saying it isn't clear if you have a problem, or not.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem is how to make the delay with milis() this is the code with millis()

Code:

/*
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
  
  if (run == HIGH  &&buttonState_door == LOW){
    if(currentMillis - previousMillis > interval) {
      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();
  }

}

« Last Edit: November 06, 2011, 03:25:27 am by enterpc » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (run == HIGH);

Why?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if run == low dont     digitalWrite(ledPin_alarm,HIGH);
only if run = high     digitalWrite(ledPin_alarm,HIGH);

is it wrong?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check the semicolon
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

/*
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();
  }

}

« Last Edit: November 06, 2011, 03:26:06 am by enterpc » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry i can understand you smiley-sad
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 4435
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
/*
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();
  }

}



« Last Edit: November 06, 2011, 03:26:47 am by enterpc » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

... yes this code work ok.

What problem?
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: 1 [2] 3 4 5   Go Up
Jump to: