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

AquaNiner Pet Hydration Monitor
Intermediate
  • 382
  • 14

Full instructions

Using two Photons, IFTTT and ThingSpeak, get notifications for when your furry friend needs water and monitor how much they're drinking.

Hot Shot Hoops
Intermediate
  • 530
  • 13

Full instructions

No need to keep track of the number of baskets you make when shooting hoops. Hot Shot Hoops does the work for you.

Hot Shot Hoops

Team IOT Basketball

Temperature Mirror
Intermediate
  • 381
  • 8

Full instructions

The Temperature Mirror incorporates a digital display to allow its user to readily view time, temperature, humidity, and light.

Temperature Mirror

MEGR3171 Team 49

Pet Feeder
Intermediate
  • 414
  • 7

Full instructions

Automated pet food dispenser to feed our pets when we are not at home by using an IoT device.

Teacher Tracker
Intermediate
  • 176
  • 4

Full instructions

If you want to know when a professor comes back to his/her office so you can ask annoying questions then this an option

LightAlert
Intermediate
  • 138
  • 4

Full instructions

As the great Terry Crews once said "that's 49 cents of milk spilt over the table! Somebody's gonna drink that!" But instead... electricity.

Add projectSign up / Login
Respect project