Things used in this project

Hardware components:
Photon new
Particle Photon
×2
RFID Module
×1
12002 04
Breadboard (generic)
×2
13285 01
PIR Motion Sensor (generic)
×2
Adafruit industries ada1536 image
Buzzer
×1
Software apps and online services:
Hackster
ThingSpeak API

Schematics

Tag reader and PIR sensor
Reads Tag when motion is sensed
Rfid2 mofjyzjiun
PIR Motion Sensor and Buzzer
PIR and buzzer
Pir buzzer sche rdr2jzkr9b

Code

PIR Motion Sensor and Tag reader(First Photon)Arduino
This is the sketch for the motion sensor and RFID Tag reader that triggers the second Motion Sensor.
// This #include statement was automatically added by the Particle IDE.
#include <SparkIntervalTimer.h>

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

#include "RFID.h"

/* Define the pins used for the SS (SDA) and RST (reset) pins for BOTH hardware and software SPI */
/* Change as required */
#define SS_PIN      A2      // Same pin used as hardware SPI (SS)
#define RST_PIN     D3

/* Define the pins used for the DATA OUT (MOSI), DATA IN (MISO) and CLOCK (SCK) pins for SOFTWARE SPI ONLY */
/* Change as required and may be same as hardware SPI as listed in comments */
#define MOSI_PIN    A5      // hardware SPI: A5
#define MISO_PIN    A4      //     "     " : A4
#define SCK_PIN     A3      //     "     " : A3

/* Create an instance of the RFID library */
#if defined(_USE_SOFT_SPI_)
    RFID RC522(SS_PIN, RST_PIN, MOSI_PIN, MISO_PIN, SCK_PIN);    // Software SPI
#else
    RFID RC522(SS_PIN, RST_PIN);                                 // Hardware SPI
#endif



int sensorValue=D0; //Declare PIR Sensors Input
int carddetected=false; //Declare Initial condition for state of Tag
int ledpin=D7; //Declare pin to indicate if motion is detected and Tag is read by reader 
unsigned long pirtimer=0; //Declare timer toscan Tag
int val=0;  //Value to store sensors input
int value=0;
unsigned long motioncount=millis();


void setup()
{ 
  Serial.begin(9600);
  
#if !defined(_USE_SOFT_SPI_)
  /* Enable the HW SPI interface */
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  SPI.begin();
#endif

  /* Initialise the RFID reader */
  RC522.init();
  pinMode(ledpin, OUTPUT);
  pinMode(sensorValue, INPUT); 
  
  
}



void loop()
{
   
   
    val= digitalRead(sensorValue); //Sensor value is stored in val
  if (val==1){                    //If motion is detected it D0 returns 1
      //Particle.publish("Motion detected", "motion"); //Photon publishes event when motion is detected 
      
       value++;
       Particle.publish("thingSpeakWrite_A0", "{ \"1\": \"" + String(value) + "\", \"k\": \"Put your Write API here from Thingspeak\" }", PRIVATE);
      pirtimer=millis(); //Initial time is stored in pirtimer
      while (pirtimer>(millis()-10000)){    //This mean the loop will run for 10secs. The user have 10secs to scan tag
            
         if (RC522.isCard()){   //This statement becomes true if RFID tag is detected
            // Particle.publish("photon_rfid_completed", "ON");
            carddetected=true; //This will be used later to decide what event to publish to the second photon
            digitalWrite(ledpin,HIGH); //The on board led turns on to indicate tag was scanned
         }
       }    
      if (carddetected==true){  
         
          Particle.publish("photon_rfid_completed", "Detected", PRIVATE); //Photon publishes this event if condition istrue
           carddetected=false;   //Returns state back to default
        }
        else
        {
         Particle.publish("photon_rfid_completed", "Not_Detected", PRIVATE);
         
        }
      
  
    digitalWrite(ledpin,LOW); //Returns on-board led to its initial state
   if (motioncount < (millis()-300000)){
       value=0;
       motioncount=millis();
      }
  
  }
  delay(1000);
  
}
PIR Motion Sensor and Buzzer (Second Photon)Arduino
This is the code for the second photon.
// Initialize some variables we'll need
int motionSensorPin = D0;
int boardLed = D7;
int buzzer=D1;
int val=0;
int sensorValue;
unsigned long pirtimer;

void setup() {

Serial.begin(230400);
pinMode(motionSensorPin, INPUT);
pinMode(buzzer, OUTPUT );

pinMode(boardLed,OUTPUT); // Our on-board LED output

Particle.subscribe("photon_rfid_completed", Buzz_Notifier, MY_DEVICES); //remove MY_DEVICES if you wish to receive events from other particle accounts.

}

void Buzz_Notifier(const char *event, const char *data)
{
    pirtimer=millis();
while (pirtimer>(millis()-10000)){  
  val= digitalRead(sensorValue); //Sensor value is stored in val
  if (val==1){    
    if ( strcmp ( data, "Not_Detected" ) == 0 ) {
        digitalWrite(buzzer,HIGH);
         delay(100);
         digitalWrite(buzzer, LOW);
         delay(9500);
    }
    if( strcmp ( data, "Detected" ) == 0 ) {
        digitalWrite(boardLed,HIGH);
        delay(500);
        digitalWrite(boardLed, LOW);
        
    }
  }
}



}
ThingspeakArduino
JSON code
{
    "event": "thingSpeakWrite_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}
PIR Motion Sensor and Tag reader Library(First Photon)
Library needed for the sketch. Copy only the ,cpp and .h file

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Particle Photon Based Security System with Alerting
Intermediate
  • 1,345
  • 20

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Happy Plant Notifier
Intermediate
  • 290
  • 5

Full instructions

Get a text or call if your plant is getting too dry, along with a nice LCD display giving information regarding your plant's health.

My Guardian for the Workshop
Intermediate
  • 202
  • 4

Full instructions

Device will send emails if the door or window has been opened, and will monitor the temperature and humidity of the place.

Smart and Safe Outdoor Plant Watering System
Intermediate
  • 2,526
  • 18

Monitors soil moisture and weather forecasts to give plants just the water they need. Safe garden hose hookup for season long watering.

Christmas Gift Box
Intermediate
  • 3,684
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Carbon Fiber Vacuum Chamber
Intermediate
  • 3,035
  • 94

Full instructions

Our project is a carbon fiber vacuum chamber that is monitored by multiple particle photons and various sensors.

Add projectSign up / Login