Pages: [1] 2 3 ... 5   Go Down
Author Topic: home alarm system problem in code  (Read 3143 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(i would if i'm in situation alarm on  in  alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)

this is the code


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 );

#define ledPin 13

#include <LiquidCrystal.h>

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

const int buttonPin_DOOR =15;    // the number of the pushbutton pin
const int buttonPin_WINDOWS=16;
const int buttonPin_ON_IN=17;
const int buttonPin_ON_OUT=19;
const int ledPin_ALARM= 18;
int ON_IN=0;
int ON_OUT=0;

int buttonState_DOOR = 1;         // variable for reading the pushbutton status
int buttonState_WINDOWS= 1;
int buttonState_ON_IN= 0;
int buttonState_ON_OUT= 0;

 

void setup(){
 
  pinMode(buttonPin_DOOR, INPUT); 
 pinMode(buttonPin_WINDOWS,INPUT);
pinMode(buttonPin_ON_IN,INPUT);
pinMode(buttonPin_ON_OUT ,INPUT);
  pinMode(ledPin_ALARM ,  OUTPUT);
      lcd.begin(16, 2);
  lcd.setCursor(0,0);

 
  digitalWrite(ledPin, LOW);   

  keypad.addEventListener(keypadEvent);
  keypad.setDebounceTime(250);
 
 
}

void loop(){
   buttonState_DOOR = digitalRead(buttonPin_DOOR);
   buttonState_WINDOWS = digitalRead(buttonPin_WINDOWS);
   buttonState_ON_IN= digitalRead(buttonPin_ON_IN);
   buttonState_ON_OUT= digitalRead(buttonPin_ON_OUT);
   
   
   
   if (buttonState_ON_IN == HIGH  &&buttonState_WINDOWS == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN WINDOWS     ");
    lcd.setCursor(0,1);
  lcd.print("                                  ");
   }
    if (buttonState_ON_IN == HIGH  &&buttonState_DOOR  == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN DOOR     ");
  lcd.setCursor(0,1);
  lcd.print("                                  ");
   }
   
    if (buttonState_ON_IN == HIGH  &&buttonState_WINDOWS == LOW && buttonState_DOOR  == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN WINDOWS AND ");
  lcd.setCursor(0,1);
  lcd.print("OPEN DOOR     ");
   }
   if (buttonState_ON_IN == HIGH  &&buttonState_DOOR  == HIGH &&buttonState_WINDOWS  == HIGH) {
      lcd.setCursor(0,0);
  lcd.print("ALARM ON        ");
  lcd.setCursor(0,1);
  lcd.print("ALARM      ");
(ON_IN = HIGH);
   }
    if (ON_IN == HIGH  &&buttonState_DOOR == LOW){
      digitalWrite(ledPin_ALARM,HIGH);
      lcd.setCursor(0,0);
  lcd.print("ALARM          ");
  lcd.setCursor(0,1);
  lcd.print("                                  ");
 
    }
      if (ON_IN == HIGH  && buttonState_WINDOWS  == LOW){
        digitalWrite(ledPin_ALARM,HIGH);
      lcd.setCursor(0,0);
  lcd.print("ALARM          ");
  lcd.setCursor(0,1);
  lcd.print("                                  ");
 
    }
      if (buttonState_ON_OUT == HIGH  &&buttonState_WINDOWS == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN WINDOWS     ");
    lcd.setCursor(0,1);
  lcd.print("                                  ");
   }
    if (buttonState_ON_OUT == HIGH  &&buttonState_DOOR  == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN DOOR     ");
  lcd.setCursor(0,1);
  lcd.print("                                  ");
   }
   
    if (buttonState_ON_OUT == HIGH  &&buttonState_WINDOWS == LOW && buttonState_DOOR  == LOW) {
   
  lcd.setCursor(0,0);
  lcd.print("OPEN WINDOWS AND ");
  lcd.setCursor(0,1);
  lcd.print("OPEN DOOR     ");
   }
   if (buttonState_ON_OUT == HIGH  &&buttonState_DOOR  == HIGH &&buttonState_WINDOWS  == HIGH) {
      lcd.setCursor(0,0);
  lcd.print("ALARM ON        ");
  lcd.setCursor(0,1);
  lcd.print("ALARM      ");
(ON_OUT = HIGH);
   }
    if (ON_OUT == HIGH  &&buttonState_DOOR == LOW){
(i would if i'm in situation alarm on  in  alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)

      digitalWrite(ledPin_ALARM,HIGH);
      lcd.setCursor(0,0);
  lcd.print("ALARM          ");
  lcd.setCursor(0,1);
  lcd.print("                                  ");
 
    }
      if (ON_OUT == HIGH  && buttonState_WINDOWS  == LOW){
        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);
       (ON_IN   = LOW);
       (ON_OUT = LOW);
       
       lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("CORRECT PASSWORD ");
  delay(1000);
       lcd.setCursor(0,0);
  lcd.print("ALARM                    ");
  lcd.setCursor(0,1);
  lcd.print("OFF                        ");
 
             
 
              password.reset();
     }else{
     


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

Moderator edit: Code put into code box. AWOL
« Last Edit: October 30, 2011, 07:00:15 am by AWOL » Logged

Finland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the question?
Logged

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

(i would if i'm in situation alarm on  in  alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)

how i can do it ?
it isn't a simple delay(10000)
Logged

Leeds, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 134
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(i would if i'm in situation alarm on  in  alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)

This does not make sense - rewrite it so that there is no chance of confusion.

A numbered list might work well.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You seem to have already written a whole lot of code. Please explain what you expect it to do and what it does instead. Point of where in the code you think the problem resides.

When you explain your problem, using proper sentences (capital letters and punctuation) adds readability.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is the code

Can you post code that actually compiles? This doesn't look as if it has a hope of compiling:

Quote
Code:
    if (ON_OUT == HIGH  &&buttonState_DOOR == LOW){
(i would if i'm in situation alarm on  in  alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)

      digitalWrite(ledPin_ALARM,HIGH);
      lcd.setCursor(0,0);

I am not familiar with this coding style:

Code:
 
       (ON_IN   = LOW);
       (ON_OUT = LOW);

Why are you putting things in brackets?
Logged

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

You have to break your project down into small steps and get each part working in sequence.

Use an LED to represent the alarm and a push button to represent the magnetic sensor (switch) on your door. 
(1)  LED on with door open and off with door closed.

Add push buttons to represent additional doors and windows.
(2)  LED OFF when all doors and windows are closed, LED goes on when any door and/or window is open.
(3)  LED OFF when all doors and windows are closed, LED goes on when any door and/or window is open, LED stays on even if all doors and windows are then closed.

Add a switch to arm / disarm the alarm.
(4)  LED works as in (3) when the alarm is armed, LED stays off even when doors and/or window is open when alarm is disarmed.

Add a keypad.
(5)  Correct sequence on keypad arms / disarms the alarm

Add an LCD display.
(6)  Alarm status indicated on LCD display

Don't forget to debounce your door and window switches and your keypad.


Don

Logged

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

I have tried these .I will try to describe exactly my problem

1) When the alarm is activated and the window  open.
start the  alarm siren
if I press the correct code stop the  alarm siren and  turn off the system  (this is ok )

2) When the alarm is activated and  door open.
Wait 10 sec  and if i dont press the correct code in 10 sec,  start the  alarm siren.
If I press the correct code in 10 sec . Stop the  alarm siren and  turn off the system.
After the  10 sec  if I press the correct code  stop the  alarm siren

The second piece is the my problem  i nead a delay  of 10 sec

« Last Edit: November 01, 2011, 02:12:10 pm by enterpc » Logged

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

Quote
The second piece is the my problem  i nead a delay  of 10 sec

Why didn't you ask that in the first place?

First figure out how many milliseconds you need to delay.  Then look at the 'Blink without Delay' Tutorial. 

By the way.... Two out of the three words in the title of this tutorial are misleading so you might initially think it is not of much use for your application.  They are blinking an LED but this is just representing that they are doing one thing and then later on they are doing something else.  They are NOT doing this without a delay, they are doing this without using the delay() routine - which is a lot different.  The tutorial should really be called something like 'Wait without using delay()'.


Don
Logged

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

if I understand you correctly . you're saying me to  use the function millis()
Logged

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

Quote
if I understand you correctly . you're saying me to  use the function millis()
Yes!

Don
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 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

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 initial state



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){
    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:24:37 am by enterpc » Logged

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

You're going to have to start posting your code correctly.
Use the # icon on the editors toolbar.
You can (and should) go back and edit your posts.
Highlight the code, then click on the # icon.
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.

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

Quote
My problem is that when I open the door I need delay 10 sec i tried the millis() but nothing this is my code
I didn't find millis() anywhere in your code.

Don
Logged

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

yes this code work ok. It's without millis()
if i use millis() i have problem
« Last Edit: November 04, 2011, 04:03:02 am by enterpc » Logged

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