Arduino based Security Project Using Cayenne Reviewed by Unknown on 11:11 Rating: 4.5

Arduino based Security Project Using Cayenne


 

Description

This is an Arduino based home security project that uses the power of "Cayenne" for extraordinary capabilities.

Cayenne Beta

Cayenne is a new IoT drag and drop platform originally released for the Raspberry Pi, but now available for Arduino. Cayenne makes the task of connecting your Arduino to the internet as simple as possible. All of the complexity of internet connectivity is hidden within the Cayenne library.

You can easily create a Network of Arduinos and build an IoT system which can be managed and operated within the Cayenne dashboard. This dashboard is accessible through your browser or via the Cayenne smart phone app (on IOS or Android).

The feature I liked the most, was the ability to change the position of sensors or actuators on the Arduino without having to re-upload Arduino code. I could manage the changed position from within the Cayenne platform. The other feature that I liked was the ability to setup actions based on custom triggers. You can use Cayenne to trigger a whole range of functions, for example: play a sound, move a motor, light up an LED, or to send alert notifications via email or SMS.

Cayenne is in Beta at the moment, so there are a few minor bugs here and there, but overall - I give it a thumbs up - it is definitely worth checking out.
 

Here is a link to the Cayenne Beta Program:
**Cayenne Beta Link**



              Source: myDevices Media Kit

 

Home Security Project Summary

In order to fully experience this new IoT platform, I decided to create a project to really put it through its paces. This is what my Security Project will need:

  1. It will use two Arduinos, one connected to the internet via an Ethernet shield, and the other via WIFI.
  2. Two detectors - a PIR sensor and a laser trip wire.
  3. If the sensors are tripped, the person has 10 seconds to present an RFID tag to the Grove RFID reader:
    • If a valid RFID tag is SUCCESSFULLY presented within the time limit, a nice personalised greeting will be played to that person using a Grove - Serial MP3 player
    • If a valid RFID FAILS to be presented within the time limit, an Alarm will sound, and I will be notified of the intrusion via an SMS alert.
  4. The Cayenne dashboard will show the status of the sensors, and I will have full control over my security system via the web interface (or smartphone app).
  5. The sensors will be attached to a different Arduino to that of the Grove MP3 player and the RFID tag reader, which means that there will have to be some level of communication between the two Arduinos. In fact, the cross communication will be vital to the success of this project.


 
 
 

Project Video



 
 
 
 

 

Flow Diagrams:

Main Flow Diagram

The following flow diagram shows the Security project process. It is a high level view of the decisions being made by each Arduino in response to various events.  


 

Triggers Flow Diagram

The following flow diagram aims to highlight the various triggers set up within Cayenne to get this Security system to work.  

 
 
 

Arduino IDE and Library Downloads

You will need an Arduino IDE to upload code to the Arduino and the Seeeduino Cloud.
Here is the link to the Arduino IDE: Arduino IDE - download location

The Cayenne service requires that you download and install the Cayenne Library into your Arduino IDE.
You can get the Cayenne Library from here: Cayenne Library File - Download


 

Cayenne Connectivity Setup

The Seeeduino Cloud needs to be prepared for use with Cayenne.
Normal operating/setup instructions can be found here: Seeeduino Cloud WIKI page
 
Once you have successfully connected Seeeduino Cloud to your WIFI network, you can add it to the Cayenne Dashboard by making the following selections from within the Cayenne Web application:

  1. Add New
  2. Device/Widget
  3. Microcontrollers
  4. Arduino
  5. Ensure Seeeduino Cloud is connected to WIFI network - the select the NEXT button
  6. Select - Arduino Yun: Built-in Ethernet - ticked
  7. Providing you have already installed the Cayenne library as described above - you should be able to copy and paste the code to the Arduino IDE and upload to the Seeeduino Cloud.
  8. If successful, you should see the Arduino Yun board appear within the Cayenne Dashboard. If not, then seek help within the Cayenne forum.


 

The Arduino UNO with WIZNET 5100 - Ethernet Shield
also needs to be prepared with Cayenne

  1. Add New
  2. Device/Widget
  3. Microcontrollers
  4. Arduino
  5. Ensure Arduino is powered, and Ethernet shield is connected to your internet router via an Ethernet cable
  6. Select - Arduino Uno: Ethernet Shield W5100 - ticked
  7. Copy and paste the code to the Arduino IDE and upload to the Arduino UNO.
  8. If successful, you should see the Arduino Uno board appear within the Cayenne Dashboard. If not, then seek help within the Cayenne forum.

 


 
If you have the Ethernet shield with the WIZNET 5200 chip, then you may need to download a specific Ethernet library in addition to the Cayenne library.
 
Just follow the instructions within the Automatically generated sketch provided - when you select your specific Arduino/Ethernet/WIFI shield combination. If you need further instructions on connecting your device to Cayenne - then please visit the myDevices website for the online documentation.


 


 
 
 
 

ARDUINO CODE (1)


Code for Arduino UNO with Ethernet Shield:

The following code will need to be uploaded to the Arduino UNO:

/*
Title: PIR and Photoresistor with Ethernet Shield connected to Cayenne
Author: ScottC
Date: 10th August 2016
Arduino IDE version: 1.6.9
Website: http://arduinobasics.blogspot.com.au/2016/08/arduino-based-security-project-using.html
Description: Using a PIR sensor to detect movement, and a Photoresistor as the trigger in a laser trip-wire setup.
When motion is detected, or when the laser beam is broken, the Arduino will notify Cayenne of these events.
There are two Arduino MCUs involved in this project. This arduino is used to detect the presence of an intruder.
Once an event is generated, the other Arduino is notified. The other Arduino then requests the person to identify themselves.
If the person identifies themselves successfully within 10 seconds, the alarm is deactivated,
otherwise an alarm is triggered, and an alert is sent via email/SMS (using the Cayenne service) to notify me of the intrusion.
Libraries required:
CayenneEthernet.h : is within the Cayenne-Arduino library download file: https://github.com/myDevicesIoT/Cayenne-Arduino-Library
Credits: Some of the code used in this sketch was adapted from code examples at this site:
http://www.cayenne-mydevices.com/docs/#introduction
------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#include <CayenneEthernet.h> //This library is required for an Arduino UNO using an Ethernet Shield with a WIZNET 5100 chip
char token[] = "INSERT YOUR TOKEN HERE"; // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
// Global variables
const int PIR_Pin = 6; //PIR sensor connected to Digital Pin 6
int PIRcurrentState = 0; //The current state of the PIR sensor (0/1)
int PIRprevState = 0; //The previous state of the PIR sensor (0/1)
int vPin0 = 0; //vPin0 is paired with Virtual Pin 0 in Cayenne, and is used as a "Master Control Button" to enable/disable Intruder monitoring
int vPin4 = 0; //vPin4 is paired with Virtual Pin 4 in Cayenne, and is used to manage the "Laser Trigger"
int photoR = 0; //photoR is used to get/store the photoresistor readings from Analog Pin A2 (Values range from 0 to 1023)
unsigned int laserThreshold = 500; //laserThreshold (default = 500), is used to control the level of light at which to laser is triggered. i.e. When reading drops below this level.
boolean masterJustTurnedOn = false; //masterJustTurnedOn: this variable was required to help tidy up some loose ends - when the "Master Control Button" was switched on.
boolean masterState = false; //masterState: is used to monitor the state (on/off) of the "Master Control Button"
/*
* =======================SETUP()==========================================================================================================================================
*/
void setup(){
//Serial.begin(9600); //Turn on Serial communication with the computer for debugging purposes.
Cayenne.begin(token); //Initialise the connection between this Arduino and Cayenne. The token must match the one in the Cayenne Dashboard.
pinMode(8, OUTPUT); //The photoresistor will be receiving 5V from digital pin 8
digitalWrite(8, HIGH); //Turn on the power to the photoresistor (connected to digital pin 8). Please note: The readings are obtained from Analog pin A2.
}
/*
* =======================LOOP()==========================================================================================================================================
*/
void loop(){
Cayenne.run(); //Synchronisation step with Cayenne service.
/*The following code will only run when the Master Control Switch is just turned on, and will be ignored thereafter.
* The masterState is changed to true, to show the Master Control Switch is NOW ON. The PIRcurrentState is set to zero, to prevent false positive intruder detections.
* Cayenne is notified of this change, to help synchronise the dashboard. vPin4 (Laser Trigger) is also reset to zero for the same reason.
* A delay is introduced to allow both sides sufficient time to update their respective sensor status.
*/
if(vPin0 && !masterJustTurnedOn){
masterJustTurnedOn = true;
masterState=true;
PIRcurrentState = 0;
Cayenne.virtualWrite(V1, PIRcurrentState);
delay(50);
vPin4 = 0;
Cayenne.virtualWrite(V4, vPin4);
delay(500);
}
/*vPin0 is attached to Virtual Pin 0 in Cayenne, and reflects the state of the Master Control Button in the Cayenne Dashboard.
* masterState reflects the state of the Master Control Button in the Arduino. Both have to match, and be ON, in order to activate the Security sensors.
* The current state of the PIR sensor is checked. Only when the PIR sensor state changes(from off to on or vice versa), does it update the Cayenne dashboard
*/
if(vPin0 && masterState){
PIRcurrentState = digitalRead(PIR_Pin);
if(compareState()){
Cayenne.virtualWrite(V1, PIRcurrentState); //Turn PIR indicator on the App ON/OFF depending on state of PIR sensor.
delay(20);
}
/* Only check the photoresistor when the Laser Trigger has not already been triggered.
* If the photoresistor reading drops below the threshold (eg. When someone blocks the laser light from hitting the sensor), then activate the
* Laser Trigger (change status from 0 to 1) - notify the Cayenne dashboard of this change.
* The light threshold can be modified/controlled from the Cayenne dashboard.
*/
if(!vPin4){
photoR = analogRead(A2);
if(photoR<laserThreshold){
vPin4 = 1;
Cayenne.virtualWrite(V4, vPin4);
}
}
}
}
/* =======================compareState()==========================================================================================================================================
* compareState() function: used to compare the current state of the PIR sensor from the previous state of the sensor.
* It allows the Cayenne dashboard to keep up to date with the status of the sensor.
*/
boolean compareState(){
if(PIRcurrentState != PIRprevState) {
PIRprevState=PIRcurrentState;
return true;
} else {
return false;
}
}
/* =======================CAYENNE_OUT(V2)==========================================================================================================================================
* CAYENNE_OUT(V2):
* Will update the Cayenne Dashboard (Virtual pin 2) with analog readings from the Arduino Analog Pin A2
*/
CAYENNE_OUT(V2){
Cayenne.virtualWrite(V2, analogRead(A2));
}
/* =======================CAYENNE_IN(V0)==========================================================================================================================================
* Will update Arduino's variable vPin0 to match Virtual Pin 0 in the Cayenne Dashboard.
* This has also been setup to reset a couple of variables, to ensure proper functionality.
*/
CAYENNE_IN(V0){
vPin0 = getValue.asInt();
if(!vPin0){
masterJustTurnedOn = false;
masterState=false;
}
}
/* =======================CAYENNE_IN(V4)==========================================================================================================================================
* Will update Arduino's variable vPin4 to match Virtual Pin 4 (Laser Trigger) in the Cayenne Dashboard.
* This allows you to set the status of vPin4 from the Cayenne Dashboard.
*/
CAYENNE_IN(V4){
vPin4 = getValue.asInt();
}
/* =======================CAYENNE_IN(V5)==========================================================================================================================================
* Will update Arduino's variable laserThreshold to match Virtual Pin 5 (Laser Threshold) in the Cayenne Dashboard.
* This allows you to set the value of the "Laser Threshold" from the Cayenne Dashboard.
*/
CAYENNE_IN(V5){
laserThreshold = getValue.asInt()/10; //Have to divide by 10 due to bug in the Cayenne dashboard
}


 
 
 
 
 

ARDUINO CODE (2)


Code for Seeeduino Cloud:

The following code will need to be uploaded to the Seeeduino Cloud:

/*
Title: Grove RFID and MP3 module with Seeeduino Cloud (Yun compatible) connected to Cayenne Dashboard
Author: ScottC
Date: 10th August 2016
Arduino IDE version: 1.6.9
Website: http://arduinobasics.blogspot.com.au/2016/08/arduino-based-security-project-using.html
Description: There are two Arduino MCUs involved in this project.
The Seeeduino Cloud (Arduino Yun compatible board) is used to transmit a laser beam, identify the detected person, and play a scripted dialogue in response to an event.
The other Arduino is responsible for detecting the presence of a person in the room. When a sensor is triggered, it will notify Cayenne, which
in turn will notify this Arduino of that event.
This Arduino is responsible for identifying the person in question.
If the person identifies themselves successfully within 10 seconds, the alarm is deactivated,
otherwise an alarm is triggered, and an alert is sent via email/SMS (using the Cayenne service) to notify me of the intrusion.
Libraries required:
SoftwareSerial.h : This library should already be installed in the latest Arduino IDE
CayenneYun.h : is within the Cayenne-Arduino library download file: https://github.com/myDevicesIoT/Cayenne-Arduino-Library
Credits: Some of the code used in this sketch was adapted or inspired from code examples at these sites:
http://www.cayenne-mydevices.com/docs/#introduction
http://www.seeedstudio.com/wiki/Grove_-_Serial_MP3_Player
http://www.seeedstudio.com/wiki/Grove_-_125KHz_RFID_Reader
------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#include <SoftwareSerial.h> //SoftwareSerial library required for Arduino communication with the Grove RFID reader and the Grove Serial MP3 player
#include <CayenneYun.h> //CayenneYun library is required for successful communication between the Seeeduino Cloud and the Cayenne Dashboard
char token[] = "INSERT YOUR TOKEN HERE"; //Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
SoftwareSerial mp3(2,3); //Grove Serial MP3 Player is connected to Digital Pins 2 and 3
SoftwareSerial rfid(10,11); //Grove 125kHz RFID reader is connected to Digital Pins 10 and 11 (Note: lower pins may not work with this board)
//Global Variables
int rfidValue = 0; //rfidValue: used to store the value obtained from the RFID tag
int vPin6 = 0; //vPin6: is associated with Virtual Pin 6 on the Cayenne Dashboard - activated when a person is detected by the sensors.
int vPin7 = 0; //vPin7: is associated with Virtual Pin 7 on the Cayenne Dashboard - activated when the person fails to identify themselves.
unsigned long start_Time; //start_Time: is used in various time related events (logs the start time)
unsigned long stop_Time; //stop_Time: is used in various time related events (logs the stop time)
unsigned long time_Diff = 0; //time_Diff: is used in various time related events (is used to record the time elapsed from start time to stop time)
boolean keyMessagePlayed=false; //keyMessagePlayed: helps to prevent a message from replaying repeatedly when a person is detected.
boolean waitingForKey = true; //waitingForKey: is used to identify if we are still waiting for a person to present a valid key or not
int songNumber = -1; //songNumber is a variable used to hold the song number to play (from the playlist on the SD card on the MP3 player)
/*===============================setup()============================================================================================================================= */
void setup(){
delay(2500); //Delay for 2.5 seconds to allow the Grove MP3 player to initialise
mp3.begin(9600); //Establish a communication link with the Grove MP3 player
rfid.begin(9600); //Establish a communication link with the Grove 125 kHz RFID reader
Serial.begin(9600); //Establish a communication link with my computer (via the Serial monitor) - for debugging purposes.
Cayenne.begin(token); //Establish a communication link with the Cayenne Server - the token must match that in the Cayenne Dashboard
setVolume(28); //Set the volume of the MP3 player to 28 (Range = 0 to 31, whereby 31 is maximum volume)
setPlayMode(0x00); //Configure the MP3 player to play the MP3 file ONCE only (per request).
}
/*===============================loop()============================================================================================================================= */
void loop(){
Cayenne.run(); //Synchronise with the Cayenne Server
if(vPin6&&!vPin7){ //Only progress if Virtual Pin 6 (Person detection) is ACTIVATED but ONLY when Virtual Pin 7 (Intruder alert) has NOT already been activated.
if(!keyMessagePlayed){ //This ensures that the message is played only ONCE when a person has been detected.
playSong(1); //Play the following message on the Grove MP3 player: "Place your keys on the mat"
keyMessagePlayed=true; //keyMessagePlayed is changed to TRUE once the message has been played.
}
/*This section requests the Arduino to look out for the person's keys, and returns TRUE when a successful identification is made.
* It returns FALSE if the person fails to put their keys on the Mat within 10 seconds , OR if the person cannot be identified by the Arduino (e.g. Wrong code)
* If a person has been successfully identified/verified, it will play a welcome message, and switch off the "Person Detection Trigger", which will then
* be used as a method to switch off the Security scanning process.
* If a person fails to be identified within 10 seconds, the person is notified that they have been detected, and an Alarm will sound.
* Virtual Pin 7 (Intruder Alert) will be ACTIVATED - which will be used as a Trigger within Cayenne to notify me of an Intruder (via Email or SMS).
*/
if(listenForKeys()){
//TRUE = Person Identified within 10 seconds
playSong(songNumber); //Play message "Welcome Home - Scott"
vPin6 = 0; //Deactivate the "Person Detection" virtual pin (6).
keyMessagePlayed=false; //Reset the keyMessagePlayed variable for future detections.
} else {
//FALSE = Person not identified within 10 seconds
playSong(2); //Play message on Grove MP3 player : "Your presence has been detected"
delay(4000); //A FOUR second delay is required to allow the message to play, before the alarm sounds.
playSong(3); //Sound the ALARM by playing song 2 on the Grove MP3 player. Song numbers are determined by the order they have been written to the SD card.
delay(8000); //An EIGHT second delay allows the alarm to sound for 8 seconds.
playSong(99); //Playing a non-existing track essentially STOPS the MP3 player.
vPin7=1; //ACTIVATE Virtual Pin 7 - Intruder Detected
keyMessagePlayed=false; //Reset the keyMessagePlayed variable for future detections.
}
upDateCayenne(); //Update the Cayenne Dashboard with any changes made to the virtual pins (6 or 7). This method can be found below.
}
}
/*=writeToMP3 function======================================================================================================================================================
* is used to simplify the process of sending commands to the Grove MP3 player
*/
void writeToMP3(byte MsgLEN, byte A, byte B, byte C, byte D, byte E, byte F){
byte codeMsg[] = {MsgLEN, A,B,C,D,E,F};
mp3.write(0x7E); //Start Code for every command = 0x7E
for(byte i = 0; i<MsgLEN+1; i++){
mp3.write(codeMsg[i]); //Send the rest of the command to the GROVE MP3 player
}
}
/*=setVolume function======================================================================================================================================================
* is used to simplify the process of setting the Volume on the Grove MP3 player
* Volume range = 00 (muted) to 31 (max volume)
*/
void setVolume(byte Volume){
byte tempVol = constrain(Volume, 0, 31); //Ensure the Volume does not extend beyond the MP3 player's limits
writeToMP3(0x03, 0xA7, tempVol, 0x7E, 0x00, 0x00, 0x00);
}
/*=setPlayMode function======================================================================================================================================================
* is used to simplify the process of setting up the play Mode on the Grove MP3 player
* playMode options:
* 0x00 = Single song - played only once ie. not repeated. (default)
* 0x01 = Single song - cycled ie. repeats over and over.
* 0x02 = All songs - cycled
* 0x03 = play songs randomly
*/
void setPlayMode(byte playMode){
writeToMP3(0x03, 0xA9, playMode, 0x7E, 0x00, 0x00, 0x00);
}
/*=playSong function======================================================================================================================================================
* is used to simplify the process of playing a specific track on the SD card of the Grove MP3 player.
* The track number is determined by the order in which the songs were written to the SD card.
* Best to name the tracks in sequence, e.g. 0000_Song0.mp3 , 0001_Song1.mp3 etc etc.
* And also best to copy them one by one to the SD card from Song 0 to Song x.
*/
void playSong(byte songNum){
writeToMP3(0x04, 0xA0, 0x00, songNum, 0x7E, 0x00, 0x00);
}
/*=listenForKeys function======================================================================================================================================================
* is used to identify the person detected.
* The Arduino will wait a maximum of 10 seconds for the person to place their RFID tag near the Grove RFID reader antenna.
* This example shows two RFID tag values that will be accepted.
* This method also prints the RFID tag value to the Serial monitor - for debugging purposes.
*/
boolean listenForKeys(){
//reset some variables every time this function is called.
songNumber = -1;
start_Time = millis();
time_Diff = 0;
waitingForKey = true;
rfidValue=0;
//Wait for a valid RFID tag for a maximum of 10 seconds
while(time_Diff<10000 && waitingForKey){
Cayenne.run(); //Make sure to stay in contact with the Cayenne Server while waiting for the RFID tag.
stop_Time = millis();
time_Diff = stop_Time - start_Time; //Measure the time elapsed.
//If an RFID tag is detected by the Grove RFID reader, it will transmit a series of numbers related to the Tag ID.
if(rfid.available()){
while(rfid.available()){ //Make sure to read all of the numbers transmitted by the Grove RFID reader
rfidValue += rfid.read(); //You could employ a method to extract the exact RFID Tag ID - however just adding each number received - produced a unique number that I could use to identify the person.
delay(1); //A small delay between reads - ensures you get all of the numbers from the RFID reader in one go.
}
Serial.println("RFID VALUE:");
Serial.println(rfidValue); //Print the Unique RFID Tag value to the Serial monitor - useful for debugging
//If a person has an RFID tag that can be identified in this list, then play a personalised message for that person.
switch(rfidValue){
case 628: //Person #1 has a Tag that generates an rfidValue of 628.
songNumber=4; //File#4 (or message number 4) on the Grove MP3 player will be played when this person is detected.
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 651: //Person #2 has a Tag that generates an rfidValue of 651.
songNumber=5; //File#5 (or message number 5) on the Grove MP3 player will be played when this person is detected.
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 694: //Person #3 has a Tag that generates an rfidValue of 694.
songNumber=6; //File#6 (or message number 6) on the Grove MP3 player will be played when this person is detected.
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 658: //Person #4 has a Tag that generates an rfidValue of 658.
songNumber=7; //File#7 (or message number 7) on the Grove MP3 player will be played when this person is detected.
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
case 677: //Person #5 has a Tag that generates an rfidValue of 677.
songNumber=8; //File#8 (or message number 8) on the Grove MP3 player will be played when this person is detected.
waitingForKey = false; //setting the "waitingForKey" variable to FALSE - will allow us to break out of the while loop (instead of waiting for a full 10 seconds).
break;
default:
waitingForKey = true; //If a person has not been identified, keep waiting for the key/tag until the times runs out.
break;
}
}
}
/* If we are still waiting for an RFID tag (key) at this point, then we were unsuccessful in identifying the person within 10 seconds.
* Returning FALSE - will sound the alarm, and will activate Virtual Pin 7 (Intruder Alert).
* Returning TRUE - means that we have identified the person who triggered the sensors, and can therefore relax, and turn OFF the Security sensors.
*/
if(waitingForKey){
return false;
} else {
return true;
}
}
/*=upDateCayenne function======================================================================================================================================================
* This function will transmit the values of vPin6 and vPin7 to the Cayenne Dashboard's Virtual Pin 6 and 7 (respectively).
* This will help the Cayenne Server to keep up to date with the status of each variable.
*/
void upDateCayenne() {
Cayenne.virtualWrite(V6, vPin6);
delay(50);
Cayenne.virtualWrite(V7, vPin7);
delay(50);
}
/*=CAYENNE_IN(V6) function======================================================================================================================================================
* This will update the Arduino's vPin6 variable to the same value as Virtual Pin 6 on the Cayenne Dashboard.
* Which means that you can control the value of vPin6 from the Cayenne app.
*/
CAYENNE_IN(V6){
vPin6 = getValue.asInt();
}
/*=CAYENNE_IN(V7) function======================================================================================================================================================
* This will update the Arduino's vPin7 variable to the same value as Virtual Pin 7 on the Cayenne Dashboard.
* Which means that you can control the value of vPin7 from the Cayenne app.
*/
CAYENNE_IN(V7){
vPin7 = getValue.asInt();
}


 
 
 
 

Fritzing diagram (1)


Fritzing diagram for Arduino UNO with Ethernet

Please click on the picture below for an enlarged version of this fritzing diagram


 
 
 
 

Fritzing diagram (2)


Fritzing diagram for Seeeduino Cloud

Please click on the picture below for an enlarged version of this fritzing diagram


 
 
 
 
 
 
 

Cayenne Dashboard Setup - GUI


The Arduino code only provides half of the functionality of this project. The Cayenne Dashboard needs to be setup to provide the rest of the functionality. The following instructions will show you how to add each of the widgets required for this Home Security project.


Arduino Ethernet - Master Switch

The master switch allows me to turn the security system on and off. When I turn the MASTER SWITCH ON, the laser beam will turn on, and the sensors will start monitoring the area for intruders. This widget is NOT associated with a physical switch/sensor on the Arduino - it uses virtual channel 0. We need to add the Master switch to the dashboard:


  1. Add New
  2. Device/Widget
  3. Actuators
  4. Generic
  5. Digital Output - Control a Digital Output
  6. Widget Name: Master On Off Switch
  7. Select Device: Arduino Ethernet
  8. Connectivity: Virtual
  9. Pin: V0
  10. Choose Widget: Button
  11. Choose Icon: Valve
  12. Step2: Add Actuator
We will add a trigger later to get this button to automatically turn the Laser beam on.


 
 
 

Arduino Ethernet - PIR Sensor

This sensor will be used to detect movement in the room. If a person walks into the room, this sensor will detect movement, and will trigger a message to be played on the Grove Serial MP3 player. The message will aim to get the person to identify themselves. They identify themselves by placing their RFID tag in close proximity to the Grove RFID reader. If the tag is valid, a "Welcome home" message is played on the Grove MP3 player. If a valid tag is not presented to the reader within 10 seconds, an Alarm will go off ("Alarm sound" played on Grove MP3 player.)

The PIR sensor is connected to digital Pin 6 of the Arduino, however, it is mapped to virtual pin 1 for better synchronisation with the Cayenne dashboard. This was done to capture ALL detections - as the PIR sensor could change from a LOW to HIGH and back to LOW state in between a Cayenne state check - and therefore, Cayenne could miss this motion detection.. Therefore we need to assign the PIR sensor to a virtual channel in the following way:
  1. Add New
  2. Device/Widget
  3. Sensors
  4. Motion
  5. Digital Motion Sensor - Motion Detector
  6. Widget Name: PIR sensor
  7. Select Device: Arduino Ethernet
  8. Connectivity: Virtual
  9. Pin: V1
  10. Choose Widget: 2-State Display
  11. Choose Icon: Light
  12. Step2: Add Sensor
  13. Select Settings from the PhotoResistor
  14. Choose Display: Value
  15. Save


 
 
 

Arduino Ethernet - Photoresistor

This sensor will be used with the laser beam to create a laser tripwire. If the sensor detects a change in light levels (drops below the threshold), it will activate the laser trigger button on the dashboard. The person will then be required to identify themselves etc etc (similar to the motion detection by the PIR sensor). The photoresistor widget will display the raw analog reading from the sensor (connected to A2), but is associated with virtual channel 2. I used a virtual channel for more control over this sensor. To add the Photoresistor to the dashboard:

  1. Add New
  2. Device/Widget
  3. Sensors
  4. Luminosity
  5. Photoresistor - Luminosity sensor
  6. Widget Name: PhotoResistor
  7. Select Device: Arduino Ethernet
  8. Connectivity: Virtual
  9. Pin: V2
  10. Choose Widget: Value
  11. Choose Icon: Light
  12. Step2: Add Sensor


 
 
 

Arduino Ethernet - Laser Trigger

The laser trigger is just an indicator that someone tripped the laser beam. The state of this widget is used to notify the Seeeduino that a presence has been detected. This widget is associated with virtual pin 4 on the Arduino UNO with Ethernet.

  1. Add New
  2. Device/Widget
  3. Actuators
  4. Generic
  5. Digital Output - Control a Digital Output
  6. Widget Name: Laser Trigger
  7. Select Device: Arduino Ethernet
  8. Connectivity: Virtual
  9. Pin: V4
  10. Choose Widget: Button
  11. Choose Icon: Lock
  12. Step2: Add Actuator


 
 
 

Arduino Ethernet - Laser Threshold

The laser threshold is used to manually configure the light level at which the laser trigger will trip. When the photoresistor value drops below the threshold value, the laser trigger icon will activate. This allows the threshold value to be updated from the Cayenne dashboard, rather than having to manually adjust the value in the Arduino code. Also, this threshold can be set remotely, in that you don't have to be near the Arduino to change this value. A very useful feature of this Security system. This widget is associated with virtual pin 5 on the Arduino UNO with Ethernet.

  1. Add New
  2. Device/Widget
  3. Actuators
  4. Generic
  5. PWM Output - Control a PWM Output
  6. Widget Name: Laser Threshold
  7. Select Device: Arduino Ethernet
  8. Connectivity: Virtual
  9. Pin: V5
  10. Choose Widget: Slider
  11. Slider Min Value: 0
  12. Slider Max Value: 10
  13. Step2: Add Actuator
The max value of the slider is 10 - due to a current bug in the Cayenne software. Once resolved, this value (as well as the relevant Arduino code) will need to be updated.


 
 
 

Seeeduino Cloud - Presence Detected

The presence detected widget is there to notify the Seeeduino Cloud that a presence has been detected on the Arduino Uno with Ethernet shield. When the PIR sensor detects movement or if the laser tripwire is tripped, Cayenne will change the state of the Presence Detected widget from LOW to HIGH. This is used within the Seeeduino Cloud to trigger the message "Place your keys on the Mat"
. If a valid RFID tag is read by the Grove RFID reader, then this widget's state will change back from HIGH to LOW, and the MasterSwitch will be deactivated - turning the Security system off. This widget is associated with Virtual pin 6 on the Seeeduino Cloud.

  1. Add New
  2. Device/Widget
  3. Actuators
  4. Generic
  5. Digital Output - Control a Digital Output
  6. Widget Name: Presence Detected
  7. Select Device: Seeeduino Cloud
  8. Connectivity: Virtual
  9. Pin: V6
  10. Choose Widget: Button
  11. Choose Icon: Lock
  12. Step2: Add Actuator


 
 
 

Seeeduino Cloud - Intruder Alert

If a valid RFID tag is not read by the Grove RFID reader within 10 seconds of a presence detection event, an alarm will sound, and this widget will be activated. This will trigger a notification event - to notify me of the unauthorised intrusion - via SMS or email. I will also have a visual indicator on the Cayenne dashboard that an intrusion has taken place. This widget is associated with Virtual pin 7 on the Seeeduino Cloud.

  1. Add New
  2. Device/Widget
  3. Actuators
  4. Generic
  5. Digital Output - Control a Digital Output
  6. Widget Name: Laser Trigger
  7. Select Device: Seeeduino Cloud
  8. Connectivity: Virtual
  9. Pin: V7
  10. Choose Widget: Button
  11. Choose Icon: Thermometer
  12. Step2: Add Actuator


 
 
 

Seeeduino Cloud - Laser Beam

The laser beam widget was created to allow for full control over the laser beam. The laser beam can be turned on or off from the Cayenne dashboard, and a connected to digital pin 7 on the Seeeduino Cloud.


  1. Add New
  2. Device/Widget
  3. Actuators
  4. Light
  5. Light Switch - Turn On/Off a Light
  6. Widget Name: xLaser Beam
  7. Select Device: Seeeduino Cloud
  8. Connectivity: Digital
  9. Pin: D7
  10. Choose Widget: Button
  11. Choose Icon: Light
  12. Step2: Add Actuator


 
 
 
 

Cayenne Triggers

Now that all of the widgets have been added to the Dashboard, there is just one more step to complete the Security System. We need to setup the triggers. These triggers provide a level of automation that is easy to create within Cayenne, but would be very complicated otherwise. I set my triggers up as per the table below. Each row represents one of the triggers within my Cayenne dashboard. If you would like to see an example of how to add a trigger - please have a look at the video at the top of this tutorial.  


 
 
 
 
 
 

Concluding comments

I used many different elements to put this home/office security project together - Multiple Arduinos were connected to the internet, both controlled by a web/smart phone app, cross-communication/synchronisation between the Arduinos, and the use of multiple sensors and modules including a laser beam !
 
This was way more than just a simple PIR sense and alarm project. I now have a personalised greeting and reminder system when I walk in the door. Everyone else has their own personalised greeting. I can enable my Security System remotely, from two blocks away, and if I wanted to - I could enable it from the other side of the world. I know instantly when someone has entered my house/office.... with an SMS alert straight to my phone.
 
This project could easily be extended:

  1. Press a button on my phone to manually trigger/play a specific message/sound/song
  2. Take a picture of the intruder
  3. Introduce fire or leak detection aswell
  4. Add other environmental sensors - Temperature / Humidity
  5. Connect it to lamp/light - creating a security light
I am sure you can think of more things I could do with this system. In fact, why don't you mention your ideas in the comments below.
 
Cayenne was instrumental in getting this project to work. I don't think I would know where to start if I had to do this project without this cool IoT platform. I think I will definitely be trying out a few more projects using Cayenne, and should you want to do the same, then please make sure to join Cayenne Beta:
 
Here is the link you need to get to the right place: Cayenne Beta Link

 

If you like this page, please do me a favour and show your appreciation :

 
Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
I can also be found on Pinterest and Instagram.
Have a look at my videos on my YouTube channel.

Description: Arduino based Security Project Using Cayenne Rating: 3.5 Reviewer: Unknown ItemReviewed: Arduino based Security Project Using Cayenne

writed by : Unknown

Ikmalil birri you are reading post about Arduino based Security Project Using Cayenne which writed by malikmal with about : and sorry, you haven't permittion to copy paste this post and upload back my file !.

If you like the article on this blog, please subscribe free via email, that way you will get a shipment every article there is an article that appeared in malikmal

0 comments:

Post a Comment

Back to top