Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
BensonJoshua
Published

Remember Me?

Using two motion sensors and an RFID tag, this device will help you remember items that are important to you.

IntermediateFull instructions provided3 hours1,453
Remember Me?

Things used in this project

Hardware components

Photon
Particle Photon
×2
RFID Module
×1
Breadboard (generic)
Breadboard (generic)
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×2
Buzzer
Buzzer
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Tag reader and PIR sensor

Reads Tag when motion is sensed

PIR Motion Sensor and Buzzer

PIR and buzzer

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);
        
    }
  }
}



}

Thingspeak

Arduino
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

Benson

Benson

1 project • 0 followers
Joshua

Joshua

1 project • 0 followers

Comments