diff --git a/README.md b/README.md new file mode 100644 index 0000000..70984e3 --- /dev/null +++ b/README.md @@ -0,0 +1,95 @@ +# arduino-alarm + +A stupid-simple alarm system that can run on even an Arduino Nano. + +It features support for simple binary "security points" (aka their condition can either be "open" or "closed"), the most common being door and window reed switches. The connected speaker will beep (from slow to fast) if armed and a security point is triggered. It can be armed and unarmed to disable/enable aforementioned beeping like any other alarm system, but you must supply the password through Serial. + +Right now it is in its pretty basic, early stages, but it will be improved. + +# Documentation + +## How do I add more "security points"? + +Right now, it's a bit complicated but possible. + +First, add an integer variable to the `Security points` variable section. The value assigned is the digital pin the switch (be it a button, reed switch, sensor) is connected to. It must not be an already used pin. For example: + +``` +int window1 = 6; +``` + +Means the security point "window1" is connected to digital pin 6 `D6` and ground `GND`. + +
+ +Then, icrement `securityPoints`. Make sure it corresponds to the number of security points you have. For example: + +``` +securityPoints = 3; +``` + +...since we have 3 security points. + +
+ +After that, add an array element to `isOpen`. Make sure that it is set to `false`. For example: + +``` +int isOpen[securityPoints] = { + false, false, false +}; +``` + +Notice how there are now three array elements since we have 3 security points. + +
+ +Then, assign a `pinMode()` to your new security point by adding one under the `Security points` section under `void setup()`. For example: + +``` +pinMode(window1, INPUT_PULLUP); +``` + +Finally, create a code block for the logic of your security point under the `Security points` section under `void loop()`. Follow this template: + +``` +// +if(digitalRead( ) == && isOpen[ ] == false) { + Serial.println( ); + isOpen[ ] = true; + if(isArmed == true) soundAlarm = 1; +} else if(digitalRead( ) == && isOpen[ ] == true) { + isOpen[ ] = false; + soundAlarm = 0; + Serial.println( ); +}; +``` + +Ok, let's break this down; + + * **** is the name of your security point. *In this case it is "window1".* + * **** is the position of the switch that is **not normal**. For example, if you have a normally CLOSED switch, set it to HIGH, meaning it is triggered when the switch is OPEN. *In this case, it is "HIGH" because our window reed switch is normally CLOSED.* + * **** is the **normal** position of the switch. *In this case, it is "LOW".* + * **** is the element of the array that corresponds to your security point. *In this case, it is 2, the third element of the array, since "window1" is our third security point.* + * **** is the message to print through Serial when the switch is triggered. *In this case we'll make it "Window1 is now opened."* + * **** is the message to print through Serial when the switch is un-triggered or returns to its normal position. *In this case we'll make it "Window1 is now closed."* + +Here is an example using all the choices we made: + +``` +// window1 +if(digitalRead( window1 ) == HIGH && isOpen[ 2 ] == false) { + Serial.println( "Window1 is now open." ); + isOpen[ 2 ] = true; + if(isArmed == true) soundAlarm = 1; +} else if(digitalRead( window1 ) == LOW && isOpen[ 2 ] == true) { + isOpen[ 2 ] = false; + soundAlarm = 0; + Serial.println( "Window1 is now closed." ); +}; +``` + +# TODO: + +* Add a separate "until unarmed" alarm that fires after a warnLevel reaches maxWarnLevel +* Use a class-and-config based system for easier adding and editing security points. \ No newline at end of file diff --git a/main/main.ino b/main/main.ino index 7d04ce6..453a3c2 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1,26 +1,34 @@ #include "Tone.h"; +// Security points const int door1 = 4; const int door2 = 5; -const int unarmedLed = 2; -const int armUnarm = 3; -const int spkr = 12; -const int armedLed = 13; +// Miscallaneous inputs/outputs +const int unarmedLed = 2; // LED to light up when unarmed +const int armUnarm = 3; // button used to arm/unarm +const int spkr = 12; +const int armedLed = 13; // LED to light up when armed -const int pass = 113; -const int securityPoints = 2; +// Configuration parameters +const int pass = 113; // passkey, or PIN +const int securityPoints = 2; // number of security points -bool isArmed = 1; -bool soundAlarm = 0; +const int maxWarnLevel = 250; // maximum warnLevel +const int warnDelayRef = 300; // the number to subtract warnLevel from +const int warnIncrement = 10; // increment maxLevel by this number -int maxWarnLevel = 250; -int warnDelayRef = 300; -int warnIncrement = 10; +// Program booleans +bool isArmed = 1; // armed status. set to initialize as armed or unarmed +bool soundAlarm = 0; // should the program sound the alarm? -int warnLevel = 0; -int isOpen[securityPoints] = {false, false}; +// Program variables +int warnLevel = 0; +int isOpen[securityPoints] = { // status of security points. each array element + false, false // refers to a security point +}; +// Melodies (they only play two notes for some reason?) int initMelody[] = {C4, E4, G4, E4, G4, C5}; int initDurations[] = {200, 100, 100, 100, 100, 100}; @@ -35,8 +43,11 @@ int alarmNote = CS5; void setup() { Serial.begin(9600); + // Security points pinMode(door1, INPUT_PULLUP); pinMode(door2, INPUT_PULLUP); + + // Misc. inputs/outputs pinMode(armUnarm, INPUT_PULLUP); pinMode(unarmedLed, OUTPUT); pinMode(armedLed, OUTPUT);