Another illustration using PIR (Passive Infrared Sensor) with Numeric Pad and Arduino NANO, These project is based on Security System that’s detect human movement on the area and triggered the alarm. As you can see the diagram below it has 3 LED as our indicator as Alert, Enabled, and Disabled. The concept is if the PIR (Passive Infrared Sensor) detects movement then it will trigger the buzzer as our alarm, when you’re going to turn off the alarm you need to input the password as the security mechanism.
Required Components
- 1x Arduino UNO, NANO, PRO, MEGA, ETC…
- 1x PIR (Passive Infrared Sensor) Motion Detection Module
- 1x 3 LED (Yellow, Green, Red)
- 3x 220R Resistor
- 1x Buzzer
- 1x Matrix Numeric Pad
Wiring Diagram
Sketch Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
/* TEST CODE for SECURITY ALARM SYSTEM */ #include <Keypad.h> // library for keyboard #include <Password.h> // library for password Password password = Password( "1234" ); // password const byte rows = 4; // four rows const byte cols = 3; // three columns char keys[rows][cols] = { // keys on keypad {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; byte rowPins[rows] = {2, 7, 6, 4}; byte colPins[cols] = {3, 1, 5}; Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols); #define sensorz 14 // D14 is A0, pin for PIR sensor data //#define contact 15 // D2, pin for on/off alarm #define alrm 13 // D13, pin for syren, buzzer #define redLed 11 // D13, pin for red led #define greenLed 9 // D9, pin for green led #define yellowLed 10 // D10, pin for blue led int sensorzData; unsigned long ceas, timpmemorat; int intarziereactivare = 20; // To delay for standby to armed int intarzieredezactivare = 10; // To delay for triggered to alarm activated int timpurlat = 10; // Time of alarm is on // This is the variable for states "0" char caz = 0; int sistem = 0; // system is 0 for off and 1 for on /* States for 0. - off 1. - stand-by 2. - waitting 3. - countdown 4. - alarm */ void setup() { keypad.addEventListener(keypadEvent); // se creaza un obiect pentru urmarire apasare taste // Serial.begin(9600); // Serial.println("Secutiry Alarm System"); // Serial.println("www.14core.com"); pinMode(alrm, OUTPUT); pinMode(sensorz, INPUT); // pinMode(contact, INPUT); pinMode(redLed, OUTPUT); pinMode(yellowLed, OUTPUT); pinMode(greenLed, OUTPUT); // pinMode(contact, INPUT_PULLUP); } void loop() { ceas = millis(); // read the internal clock keypad.getKey(); // if(digitalRead(contact) == HIGH) if (sistem%2 == 0) { // alarm is off analogWrite(greenLed, 0); analogWrite(redLed, 0); analogWrite(yellowLed, 240); digitalWrite(alrm, LOW); caz = 0; // Serial.println("System is OFF !"); } else { // alarm is on if(caz == 0) { caz = 1; timpmemorat = ceas; analogWrite(yellowLed, 0); } if(caz == 1) // system waitting { /* analogWrite(greenLed, 240); delay(100); keypad.getKey(); analogWrite(greenLed, 0); delay(100); */ if ((ceas%1000)<500) analogWrite(greenLed, 240); else analogWrite(greenLed, 0); keypad.getKey(); if(ceas >= timpmemorat + intarziereactivare * 1000) {caz = 2;} // Serial.println("System is waitting !"); } if(caz == 2) // system is armed { analogWrite(greenLed, 240); keypad.getKey(); // sensorzData = analogRead(sensorz); sensorzData = digitalRead(sensorz); // Serial.print("sensorzdData = "); // Serial.println(sensorzData); // if(sensorzData > 600) {caz = 3; timpmemorat = ceas;} if(sensorzData == HIGH) { caz = 3; timpmemorat = ceas; analogWrite(greenLed, 0); } // Serial.println("System is armed !"); } if(caz == 3) // system is triggered and countdown { /* analogWrite(redLed, 240); delay(100); keypad.getKey(); analogWrite(redLed, 0); delay(100); */ if ((ceas%500)<100) analogWrite(redLed, 240); else analogWrite(redLed, 0); keypad.getKey(); if(ceas >= timpmemorat + intarzieredezactivare * 1000) {caz = 4; timpmemorat = ceas;} // Serial.println("System is triggered and countdown !"); } if(caz == 4) // syren (buzzer) is active { digitalWrite(alrm, HIGH); analogWrite(redLed, 240); // Serial.println("Syren is active !"); keypad.getKey(); if(ceas >= timpmemorat + timpurlat * 1000) {caz = 2; digitalWrite(alrm, LOW); analogWrite(redLed, 0);} } } } //take care of some special events void keypadEvent(KeypadEvent eKey){ switch (keypad.getState()){ case PRESSED: Serial.print("Pressed: "); Serial.println(eKey); switch (eKey){ case '*': checkPassword(); break; case '#': password.reset(); break; default: password.append(eKey); } } } void checkPassword(){ if (password.evaluate()){ // Serial.println("Success"); sistem++; password.reset(); //Add code to run if it works }else{ // Serial.println("Wrong"); //add code to run if it did not work password.reset(); } } |
Downloads
Download Password.h code library | Zip
Download Keypad.h code library | Zip
Security Alarm System on PIR Sensor and Keypad with Nano
Can it use arduino uno with speaker rather using NANO an buzzer?
Yes why not, however you need to use sound driver or WTV020SD which is hookup to your arduino board. :)
How to install library Password.h and keypad.h ? Please
#include // library for keyboard
#include
Goto your IDE installation folder and navigate to the library folder and copy the code library folder you want to use to into your project. :D