Simple alarm system with the Nano V3

Our today's blog contribution bases on a project which we only recently within the scope of a Workshops with a school class have provided.

Besides, it is a matter above all with available components and the available libraries and examples from different springs of building a functioning device and of programming.

For the realisation we need the following components:

AZ-Delivery Nano V3
AZ-Delivery Breadboard
AZ-Delivery Steckbrücken m/m
AZ-Delivery4x4 matrix Keypad
AZ-Delivery Buzzer module passive
AZ-Delivery movement dispatch rider module
AZ-Delivery 0.96 duty I2C OLED display

 

Pinbelegung:

Nano V3

Keypad module 4x4

Oled display

Buzzer

Movement dispatch rider

D2

1

 

 

 

D3

2

 

 

 

D4

3

 

 

 

D5

4

 

 

 

D6

5

 

 

 

D7

6

 

 

 

D8

7

 

 

 

D9

8

 

 

 

3V3

 

VCC

 

 

GND

 

GND

-

GND

A4

 

SDA

 

 

A5

 

SCL

 

 

D11

 

 

SEE

 

5 V

 

 

 

VCC

D10

 

 

 

middle

 

 

 

Step 1: Keypad furnish

Pins 1-8 from Keypad connect with Pins D2 - D9 in the Nano

Sketch -> library integrate -> libraries administer

After searching "keypad"
Keypad by Mark Stanley, Alexander Brevig

Intallieren

File -> examples -> Keypad -> HelloKeypad

Fitting: ROWS and COLS in each case 4
A, B, C and D add

Settings check under "tools":

Board: Arduino Nano
Processor: ATmega 328P (old bootloader)
Port: COM port select

Serial monitor open, Baudrate on 9600 put.

#include <Keypad.h>

const byte ROWS = 4;//four rows
const byte COLS = 4;//three columns
char keys [ROWS] [COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [ROWS] = {9, 8, 7, 6};//connect to the row pinouts of the keypad
byte colPins [COLS] = {5, 4, 3, 2};//connect to the column pinouts of the keypad

Keypad keypad = Keypad (makeKeymap (keys), rowPins, colPins, ROWS, COLS);

void set-up () {
Serial.begin (9600);
}

void loop () {
char key = keypad.getKey ();

if (key) {
Serial.println (key);
}
}



High-level store & test
File -> to memories under -> HelloKeypad


Step 2: Display furnish
Pins as follows connect:

Display Nano V3
GND GND
VCC 3V3
SCL A5
SDA A4


We take the library SSD1306Ascii and extend our code as follows:

#include < Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

#define I2C_ADDRESS 0x3C
#define RST_PIN-1

SSD1306AsciiWire oled;

in the void set-up ()

Wire.begin ();
Wire.setClock (400000L);

#if RST_PIN >= 0
oled.begin (&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else//RST_PIN >= 0
oled.begin (&Adafruit128x64, I2C_ADDRESS);
#endif//RST_PIN >= 0

oled.set2X ();//double size of the font



Now we provide a function them the sign on our display is economical:

void print2oled (char oledText) {
oled.setFont (System5x7);
oled.clear ();
oled.println (oledText);
delay (500);
}

And call this function in loop ():

if (key) {
Serial.println (key);
print2oled (key);
}


Result: With press to the key the low-spirited key appears in the display.


The next step: we select the Ir sensor

Connect:

IR Sensor Nano V3
VCC 5 V
Middle D10
GND GND


We add the following to the code:

pinmode (10, INPUT);//Pin D10 is used as an INPUT
bool detected = false;//was grasped movement?



and if they make a function the sensor questions:

void checkPIR () {
if digitalread (PIR) {
detected = true;
Serial.println ("movement grasps");
}
else {
detected = false;
Serial.println ("no movement");
}


We connect the Buzzer for the alarm tone as follows:

Buzzer Nano V3
- GND
SEE D11

We add following to the sketch:

int Speaker = 11;//Digitally Pin 11
pinMode (Speaker, OUTPUT);

and the following function to test on account of the Buzzer goes:

void Speaker's test () {
sounds (Speaker, 600, 500);
delay (100);
sounds (Speaker, 700, 100);
delay (100);
sounds (Speaker, 800, 750);
delay (200);
}

Now all required sensors and modules are functioning so far and are accessible / selected-cash.

We store the sketch by means of "file" -> "to memories under" as a burglar alarm

 

Here the complete source code of the burglar alarm with all functions:

 

 

#include <Keypad.H>
#include <Wire.H>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

#define I2C_ADDRESS 0x3C
#define RST_PIN -1

#define PIR 10

bool detected = false;  //was movement grasped?
bool armed = false; //is the alarm switched sharply?    SSD1306AsciiWire oled;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {   {'1','2','3','A'},   {'4','5','6','B'},   {'7','8','9','C'},   {'*','0','#','D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int Speaker = 11; //Digitally Pin 11

char* pinCode = "1337";      //Set the required code PIN.
int currentPosition = 0;     //Keeps track of the position of the code entered.

void set-up(){   Serial.begin(9600);   Wire.begin();   Wire.setClock(400000 L);   #if RST_PIN >= 0     oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);   #else //RST_PIN >= 0     oled.begin(&Adafruit128x64, I2C_ADDRESS);   #endif //RST_PIN >= 0   oled.set2X(); //double size of the font   pinMode(10, INPUT);   pinMode(Speaker, OUTPUT);   Speaker's test();
}    void loop(){   char key = keypad.getKey();   checkPIR();   int l;   if (key){     beep();     Serial.println(key);     print2oled(key);     if (int(key) != 0) {                    //Check to see if there is a value present.            for (l=0; l<=currentPosition; ++l)     { }          if (key == pinCode[currentPosition])        //If the value is correct, increase hey code position by one.       {         ++currentPosition;                  if (currentPosition == 4)                //If all four of part of the code ares correct, unlured the door.         {           oled.clear();           unlockDoor();           currentPosition = 0;         }       }             else {         disabled code();                           //If any of part of the code ares wrong, Th open the door.         currentPosition = 0;     }   }
}   if (armed){ //burglar alarm sharply?     if (detected){       playAlarm();     }   }
}


void print2oled(char oledText){     oled.setFont(fixed_bold10x15);          oled.print(oledText);     delay(500);
}

void checkPIR(){     if (digitalRead(PIR)){       detected = true;       Serial.println("Movement grasps");       delay(50);     }     else {       detected = false;       //Serial.println ("no movement");       delay(50);     }     }

void Speaker's test(){    sounds(Speaker, 600, 50);    delay(100);    sounds(Speaker, 700, 50);    delay(100);    sounds(Speaker, 800, 200);    delay(200);
}    void beep(){   sounds(Speaker, 2000, 100);
}

void beepOK(){   sounds(Speaker, 3000, 50);   delay(50);   sounds(Speaker, 3300, 50);
}

void disabled code()
{   oled.clear();   oled.println("Mistake");   sounds(Speaker, 300,150);   delay(250);   sounds(Speaker, 220, 300);   delay(1000);   oled.clear();
}


void unlockDoor()
{   if (armed){     armed=false;     Serial.println("Alarm deactivates");     oled.setFont(fixed_bold10x15);     oled.clear();     oled.println("From");     delay(1000);     oled.clear();   }   else{     armed=true;     Serial.println("Alarm activates!");     oled.setFont(fixed_bold10x15);     oled.clear();     oled.println("actively!");     delay(1000);     oled.clear();   }      sounds(Speaker, 1000, 50);   delay(50);   sounds(Speaker, 1200, 50);   delay(60);   sounds(Speaker, 1300, 50);   delay(50);   sounds(Speaker, 1000, 50);   delay(60);   sounds(Speaker, 1200, 50);   delay(50);   sounds(Speaker, 1300, 50);   delay(60);   sounds(Speaker, 1000, 50);   delay(50);   sounds(Speaker, 1200, 50);   delay(60);   sounds(Speaker, 1300, 100);   delay(50);
}
void playAlarm(){   Serial.println("Alarm! Alarm! Alarm!");   tone(speaker, 2000, 400);   delay(500);   tone(speaker, 2000, 400);   delay(500);   tone(speaker, 2000, 400);   delay(500);   tone(speaker, 2000, 400);   delay(500);   oled.setFont(fixed_bold10x15);     oled.clear();     oled.println(" Alarm!!!");
}

 

 

For arduinoProjects for beginnersSensors

1 comment

Rolando

Rolando

Le istruzioni del programma si scrivono in inglese: per esempio #include , non Filo.h. Tralascio tutti gli altri errori ; ci sarebbe da scriverci un romanzo,
Die Programmanweisungen sind in englischer Sprache verfasst: Zum Beispiel #include , nicht Filo.h. Ich lasse alle anderen Fehler weg; Es würde einen Roman geben, über den man schreiben könnte.
Scusami se nella traduzione in tedesco ci sono degli errori…
Entschuldigung, wenn die deutsche Übersetzung fehlerhaft ist …
Firmato: un principiante

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN