Things used in this project

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

Code

1st sensorC/C++
// 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);
  
}
2nd sensorC/C++
// 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);
        
    }
  }
}



}
ThingspeakJSON
{
    "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
}

Credits

F501dc8bed4b3d830c0c56560147d148
Abdulaziz Alrushayd
1 project • 0 followers
Contact
Fc5ffeb764ec7a6301bcbb4c748ab999
Ali Alsaihati
1 project • 0 followers
Contact

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

Add projectSign up / Login