Originál :
Kód: Vybrat vše
https://www.youtube.com/watch?v=dRCnccv_dVE
- funkční na 3 PIR
- přes Relay se spíná klakson
- při Poplachu se odesílá zpráva do programu www.pushsafer.com, který je přístupný jak na iOS, tak Android.. nabití kreditu pro tyto zprávy stojí 0.99Eur pro 1000 zpráv
Další verze přinese
- použitá RFID čtečky
Použité součástky
Arduino - https://www.laskakit.cz/arduino-mega256 ... gLRo_D_BwE
Ethernet - https://www.santy.cz/moduly-c22/etherne ... mini-i146/
PIR - https://www.laskakit.cz/arduino-pir-det ... gIQZfD_BwE
RTC hodiny - https://www.laskakit.cz/arduino-rtc-hod ... u-pcf8563/
Display - https://www.laskakit.cz/20x4-lcd-disple ... prevodnik/
Klávesnice - https://www.laskakit.cz/arduino-4x3--ma ... -plastova/
RGB - https://www.laskakit.cz/rgb-led-5mm-dif ... na-katoda/
LED - https://www.laskakit.cz/led-dioda-5mm/
Odpor - https://www.laskakit.cz/1-4w-odpor-220r-5/
Siréna - https://www.bola.cz/kombinovana-sveteln ... gIOzfD_BwE
Kód: Vybrat vše
/*
Project Title: Home Security System
Author: Jan Konečný
Started Date: 8/16/2022
Due date: 8/18/2022
Version: 1.0
*/
/////////////////////////////////////////////////////////////////
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
#include "Rtc_Pcf8563.h"
#include <SPI.h>
#include <EthernetENC.h>
#include <Pushsafer.h>
int passwd_pos = 15; // the postition of the password input
//Real Time Clock
Rtc_Pcf8563 RTC;
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
IPAddress server(192,168,1,249);
IPAddress staticIp(192, 168, 2, 50);
IPAddress staticDnsServer(8, 8, 8, 8);
IPAddress staticGw(192, 168, 2, 1);
volatile boolean do_stuff = false;
define PushsaferKey "Token ze stranky www.pushsafer.com"
EthernetClient client;
Pushsafer pushsafer(PushsaferKey, client);
//Password
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Four columns
char keys[ROWS][COLS] = { // Define the Keymap
{
'1','2','3' }
,
{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};
byte rowPins[ROWS] = {
46, 47, 48, 49}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
40, 41, 42}; //connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 20, 4); // Assignign arduino pins to LCD display module 1
//Stroke LED Lights
int ledDelay = 50; // delay by 50ms
int redPin = 29;
int bluePin = 31;
//constants for LEDs, inputs and outputs
//int blueLED = 36;
int greenLED = 37;
int redLED = 38;
int pirPin1 = 39; //loznice PIR
int pirPin2 = 34; //kulna PIR
int pirPin3 = 36; //kuchyn PIR
int speakerPin = 35;
//int relay1 = 3; //
int relay2 = 4; // connected to 12V Blue LED strip
int relay3 = 5; // Cam
int relay4 = 6; //
int alarmStatus = 0;
int zone = 0;
int alarmActive = 0;
void setup(){
Serial.begin(9600);
lcd.begin();
//Adding time
Wire.begin();
// RTC.begin();
//If we remove the comment from the following line, we will set up the module time and date with the computer one
// RTC.adjust(DateTime(__DATE__, __TIME__));
Ethernet.init(53); // configure CS pin
do_stuff = true;
displayCodeEntryScreen();
Ethernet.begin(mymac, staticIp, staticDnsServer, staticGw);
delay(1000);
Serial.print("Connecting to: ");
Serial.print(server);
Serial.println("...");
//Police LED Lights
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(speakerPin, OUTPUT);
//pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT); //12V Blue LED lighting
pinMode(relay3, OUTPUT); //camera, 5V external DC supply
pinMode(relay4, OUTPUT); //
pinMode(pirPin1, INPUT); //Kuchyn
pinMode(pirPin2, INPUT); //loznice
pinMode(pirPin3, INPUT); //kulna
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(speakerPin, LOW);
//digitalWrite(relay1, LOW); //
digitalWrite(relay2, HIGH); // 12V Blue LED lighting
digitalWrite(relay3, HIGH); // camera, 5V external DC supply
digitalWrite(relay4, LOW); //
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void displayCodeEntryScreen() // Dispalying start screen for users to enter PIN
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Vlozte PIN:");
lcd.setCursor(0,2);
lcd.print("Home security system");
lcd.setCursor(0,3);
lcd.print(" Vyrobeno Kony.cz");
}
///////////////////////// Functions /////////////////////////////////
//take care of some special events
void invalidCode() // display meaasge when a invalid is entered
{
password.reset();
lcd.clear();
lcd.setCursor(1,0);
lcd.print(" SPATNY PIN! LOL!");
lcd.setCursor(5,2);
lcd.print(" ZNOVU!");
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
delay(2000);
digitalWrite(redLED, LOW);
delay(1000);
displayCodeEntryScreen();
}
void activate() // Activate the system if correct PIN entered and display message on the screen
{
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
digitalWrite(2, HIGH);
lcd.setCursor(0,0);
lcd.print("SYSTEM AKTIVNI!");
alarmActive = 1;
password.reset();
delay(2000);
// client.stop();
}
void deactivate()
{
//digitalWrite(camera, LOW);
alarmStatus = 0;
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" SYSTEM NEAKTIVNI!");
lcd.setCursor(0,3);
lcd.print(" VSTUP POVOLEN!");
digitalWrite(speakerPin, LOW);
alarmActive = 0;
password.reset();
delay(5000);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
displayCodeEntryScreen();
}
void checkPassword(){ // To check if PIN is corrected, if not, retry!
if (password.evaluate())
{
if(alarmActive == 0 && alarmStatus == 0)
{
activate();
}
else if( alarmActive == 1 || alarmStatus == 1) {
deactivate();
}
}
else {
invalidCode();
}
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
if (passwd_pos - 15 >= 5) {
return ;
}
lcd.setCursor((passwd_pos++),0);
switch (eKey){
case '#': //# is to validate password
passwd_pos = 15;
checkPassword();
break;
case '*': //* is to reset password attempt
password.reset();
passwd_pos = 15;
// TODO: clear the screen output
break;
default:
password.append(eKey);
lcd.print("*");
}
}
}
void alarmTriggered(){
int expected_pos;
int incr;
lcd.clear();
digitalWrite(speakerPin, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(redPin, HIGH);
// pushsafer.debug = true;
struct PushSaferInput input;
input.message = "POHYB NA ZAHRADĚ";
input.title = "POPLACH!";
input.sound = "8";
input.vibration = "1";
input.icon = "1";
input.iconcolor = "#FFCCCC";
input.priority = "1";
input.device = "a";
input.url = "https://www.pushsafer.com";
input.urlTitle = "Open Pushsafer.com";
input.picture = "";
input.picture2 = "";
input.picture3 = "";
input.time2live = "";
input.retry = "";
input.expire = "";
input.answer = "";
Serial.println(pushsafer.sendEvent(input));
Serial.println("Sent");
// client.stop();
password.reset();
alarmStatus = 1;
// alarmActive = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("!!!! P O Z O R !!!! ");
lcd.setCursor(0,2);
lcd.print(" SYSTEM OHROZEN ");
lcd.setCursor(0,3);
if (zone == 1)
{
lcd.print(" Kulna ");
delay(1000);
}
if(zone == 0){
lcd.print(" Loznice ");
delay(1000);
}
else if(zone == 2){
lcd.print(" Kuchyn");
delay(1000);
}
{
StrokeLight();
}
}
void StrokeLight(){ //Stroke LED Lights
digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light off
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light off
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light off
delay(ledDelay); // wait 50 ms
delay(10); // delay midpoint by 100ms
digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms
digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms
digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms
digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms
digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms
digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms
}
void loop(){
//display time and date
// DateTime now = RTC.now();
//DATE
lcd.setCursor(0,1);
lcd.print(RTC.getDay());
lcd.print('/');
//We print the day
lcd.print(RTC.getMonth());
lcd.print('/');
//We print the year
lcd.print("20");
lcd.print(RTC.getYear());
lcd.print(' ');
//TIME
lcd.setCursor(13,1);
lcd.print(RTC.getHour());
lcd.print(':');
lcd.setCursor(16,1);
if (RTC.getMinute() < 10) lcd.print("0");
lcd.print(RTC.getMinute());
//lcd.print(':');
//lcd.print(now.second(), DEC);
//delay(1000);
keypad.getKey();
//Serial.println(digitalRead(reedPin2));
//Serial.println(digitalRead(pirPin));
//Serial.println(digitalRead(pirPin2));
if (alarmActive == 1){
if (digitalRead(pirPin1) == HIGH)
{
zone = 0;
alarmTriggered();
}
if (digitalRead(pirPin2) == HIGH)
{
zone = 1;
alarmTriggered();
}
if (digitalRead(pirPin3) == HIGH)
{
zone = 2;
alarmTriggered();
}
}
}