In principal you can add other sensors to the extra pins, copy & paste the code changing the pin number, like windows, excess heat sensors (not smoke detectors it'll be going off all the time), carbon monoxide, rig a stop cock up for flood alert, a low beer stock sensor! my theft deterrent works really well, I got nothing worth nicking.
I go to Morrisons every week to get the beer nowadays. :) A flood sensor is a good idea. We get loads of floods at work when we leave the tap on topping up the tank.
// alarm code is "1234"change c and cc to what you want. int n = 0; int t = 0; int y = 0; int u = 5000; int d = 100; int a = 0; int alarm = 0; int alarma = 0; int code = 0; int key = 0; int timein = 120; // coming in time int timeout = 0; int alarmtime = 40000; int buttonState = 0; int c[5] = {1, 2, 3, 4}; // CHANGE FOR WHAT CODE YOU WANT int cc[5] = {1, 2, 3, 4}; // CHANGE FOR WHAT CODE YOU WANT byte h = 0, v = 0; //variables used in for loops const unsigned long period = 50; //little period used to prevent error unsigned long kdelay = 0; // variable used in non-blocking delay const byte rows = 4; //number of rows of keypad const byte columns = 4; //number of columnss of keypad const byte Output[rows] = {9, 8, 7, 6}; //array of pins used as output for rows of keypad const byte Input[columns] = {5, 4, 3, 2}; //array of pins used as input for columnss of keypad byte keypad() // function used to detect which button is used { static bool no_press_flag = 0; //static flag used to ensure no button is pressed for (byte x = 0; x < columns; x++) // for loop used to read all inputs of keypad to ensure no button is pressed { if (digitalRead(Input[x]) == HIGH); //read evry input if high continue else break; else break; if (x == (columns - 1)) //if no button is pressed { no_press_flag = 1; h = 0; v = 0; } } if (no_press_flag == 1) //if no button is pressed { for (byte r = 0; r < rows; r++) //for loop used to make all output as low digitalWrite(Output[r], LOW); for (h = 0; h < columns; h++) // for loop to check if one of inputs is low { if (digitalRead(Input[h]) == HIGH) //if specific input is remain high (no press on it) continue continue; else //if one of inputs is low { for (v = 0; v < rows; v++) //for loop used to specify the number of row { digitalWrite(Output[v], HIGH); //make specified output as HIGH if (digitalRead(Input[h]) == HIGH) //if the input that selected from first sor loop is change to high { no_press_flag = 0; //reset the no press flag; for (byte w = 0; w < rows; w++) // make all outputs as low digitalWrite(Output[w], LOW); return v * 4 + h; //return number of button } } } } } return 50; } void setup() { pinMode(1, OUTPUT); // GREEN LED pinMode(13, INPUT); // door magnetic switch pinMode(10, OUTPUT); // RED LED pinMode(11, OUTPUT); // ALARM RELAY pinMode(12, OUTPUT); // BUZZER digitalWrite(1, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); delay(1000); for (byte i = 0; i < rows; i++) //for loop used to make pin mode of outputs as output { pinMode(Output[i], OUTPUT); } for (byte s = 0; s < columns; s++) //for loop used to makk pin mode of inputs as inputpullup { pinMode(Input[s], INPUT_PULLUP); } Serial.begin(9600); //to use serial monitor we set the buad rate
} void loop() { if (millis() - kdelay > period) //used to make non-blocking delay { kdelay = millis(); //capture time from millis function switch (keypad()) //switch used to specify which button { case 0: Serial.println(1); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 1; key = 1; break; case 1: Serial.println(2); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 2; key = 1; break; case 2: Serial.println(3); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 3; key = 1; break; case 3: Serial.println("A"); // BUTTON USED TO SET THE ALARM IN DETECT MODE. tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); if (alarm == 0){ alarm = 1; // TURNS ALARM ON timeout = 1; // VARIABLE TO LET THE DOOR TIMER SET FOR LEAVING THE HOUSE } break; case 4: Serial.println(4); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 4; key = 1; break; case 5: Serial.println(5); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 5; key = 1; break; case 6: Serial.println(6); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 6; key = 1; break; case 7: Serial.println("B"); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); break; case 8: Serial.println(7); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 7; key = 1; break; case 9: Serial.println(8); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 8; key = 1; break; case 10: Serial.println(9); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 9; key = 1; break; case 11: Serial.println("C"); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); break; case 12: Serial.println("*"); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 0; break; case 13: Serial.println(0); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); n = 0; key = 1; break; case 14: Serial.println("#"); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); break; case 15: Serial.println("D"); tone(12, (1000)); // Send 1KHz sound signal... delay(d); noTone(12); break; default: ; } } if (timeout == 1){ // TIMER TO WAIT TO EXIT HOUSE AND CLOSE THE DOOR for (int i=0; i = 3){ alarm = 2; } } }
if (buttonState == HIGH) { // THE DOOR SENSOR NEEDS 3 OPEN SIGNALS IN A ROW. THIS RESETS IT TO ZERO IF A CLOSED SIGNAL IS DETECTED // turn LED off: door closed // digitalWrite(1, LOW); alarma = 0; } if (alarm == 0){ digitalWrite(10, LOW); } if (alarm == 1){ digitalWrite(10, HIGH); } if (alarm == 2){ // digitalWrite(1, HIGH); timein = timein - 1; if (timein
In principal you can add other sensors to the extra pins, copy & paste the code changing the pin number, like windows, excess heat sensors (not smoke detectors it'll be going off all the time), carbon monoxide, rig a stop cock up for flood alert, a low beer stock sensor!
my theft deterrent works really well, I got nothing worth nicking.
I go to Morrisons every week to get the beer nowadays. :) A flood sensor is a good idea. We get loads of floods at work when we leave the tap on topping up the tank.
how about just putting the stop cock on the tap?@@damianbutterworth2434
hew already had tha automatic bar but took it down a while ago lol was pretty cool though
I`ve got some motion sensors coming to add to the alarm. :)
is it a silent alarm mate lol hope your well dez battery back up your alarm mate ot just cut the electric to kill it
// alarm code is "1234"change c and cc to what you want.
int n = 0;
int t = 0;
int y = 0;
int u = 5000;
int d = 100;
int a = 0;
int alarm = 0;
int alarma = 0;
int code = 0;
int key = 0;
int timein = 120; // coming in time
int timeout = 0;
int alarmtime = 40000;
int buttonState = 0;
int c[5] = {1, 2, 3, 4}; // CHANGE FOR WHAT CODE YOU WANT
int cc[5] = {1, 2, 3, 4}; // CHANGE FOR WHAT CODE YOU WANT
byte h = 0, v = 0; //variables used in for loops
const unsigned long period = 50; //little period used to prevent error
unsigned long kdelay = 0; // variable used in non-blocking delay
const byte rows = 4; //number of rows of keypad
const byte columns = 4; //number of columnss of keypad
const byte Output[rows] = {9, 8, 7, 6}; //array of pins used as output for rows of keypad
const byte Input[columns] = {5, 4, 3, 2}; //array of pins used as input for columnss of keypad
byte keypad() // function used to detect which button is used
{
static bool no_press_flag = 0; //static flag used to ensure no button is pressed
for (byte x = 0; x < columns; x++) // for loop used to read all inputs of keypad to ensure no button is pressed
{
if (digitalRead(Input[x]) == HIGH); //read evry input if high continue else break;
else
break;
if (x == (columns - 1)) //if no button is pressed
{
no_press_flag = 1;
h = 0;
v = 0;
}
}
if (no_press_flag == 1) //if no button is pressed
{
for (byte r = 0; r < rows; r++) //for loop used to make all output as low
digitalWrite(Output[r], LOW);
for (h = 0; h < columns; h++) // for loop to check if one of inputs is low
{
if (digitalRead(Input[h]) == HIGH) //if specific input is remain high (no press on it) continue
continue;
else //if one of inputs is low
{
for (v = 0; v < rows; v++) //for loop used to specify the number of row
{
digitalWrite(Output[v], HIGH); //make specified output as HIGH
if (digitalRead(Input[h]) == HIGH) //if the input that selected from first sor loop is change to high
{
no_press_flag = 0; //reset the no press flag;
for (byte w = 0; w < rows; w++) // make all outputs as low
digitalWrite(Output[w], LOW);
return v * 4 + h; //return number of button
}
}
}
}
}
return 50;
}
void setup()
{
pinMode(1, OUTPUT); // GREEN LED
pinMode(13, INPUT); // door magnetic switch
pinMode(10, OUTPUT); // RED LED
pinMode(11, OUTPUT); // ALARM RELAY
pinMode(12, OUTPUT); // BUZZER
digitalWrite(1, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(1000);
for (byte i = 0; i < rows; i++) //for loop used to make pin mode of outputs as output
{
pinMode(Output[i], OUTPUT);
}
for (byte s = 0; s < columns; s++) //for loop used to makk pin mode of inputs as inputpullup
{
pinMode(Input[s], INPUT_PULLUP);
}
Serial.begin(9600); //to use serial monitor we set the buad rate
}
void loop()
{
if (millis() - kdelay > period) //used to make non-blocking delay
{
kdelay = millis(); //capture time from millis function
switch (keypad()) //switch used to specify which button
{
case 0:
Serial.println(1);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 1; key = 1;
break;
case 1:
Serial.println(2);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 2; key = 1;
break;
case 2:
Serial.println(3);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 3; key = 1;
break;
case 3:
Serial.println("A"); // BUTTON USED TO SET THE ALARM IN DETECT MODE.
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
if (alarm == 0){
alarm = 1; // TURNS ALARM ON
timeout = 1; // VARIABLE TO LET THE DOOR TIMER SET FOR LEAVING THE HOUSE
}
break;
case 4:
Serial.println(4);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 4; key = 1;
break;
case 5:
Serial.println(5);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 5; key = 1;
break;
case 6:
Serial.println(6);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 6; key = 1;
break;
case 7:
Serial.println("B");
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
break;
case 8:
Serial.println(7);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 7; key = 1;
break;
case 9:
Serial.println(8);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 8; key = 1;
break;
case 10:
Serial.println(9);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 9; key = 1;
break;
case 11:
Serial.println("C");
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
break;
case 12:
Serial.println("*");
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 0;
break;
case 13:
Serial.println(0);
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
n = 0; key = 1;
break;
case 14:
Serial.println("#");
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
break;
case 15:
Serial.println("D");
tone(12, (1000)); // Send 1KHz sound signal...
delay(d);
noTone(12);
break;
default:
;
}
}
if (timeout == 1){ // TIMER TO WAIT TO EXIT HOUSE AND CLOSE THE DOOR
for (int i=0; i = 3){
alarm = 2;
}
}
}
if (buttonState == HIGH) { // THE DOOR SENSOR NEEDS 3 OPEN SIGNALS IN A ROW. THIS RESETS IT TO ZERO IF A CLOSED SIGNAL IS DETECTED
// turn LED off: door closed
// digitalWrite(1, LOW);
alarma = 0;
}
if (alarm == 0){
digitalWrite(10, LOW);
}
if (alarm == 1){
digitalWrite(10, HIGH);
}
if (alarm == 2){
// digitalWrite(1, HIGH);
timein = timein - 1;
if (timein