Things used in this project

Hardware components:
Photon new
Particle Photon
×1
13285 01
PIR Motion Sensor (generic)
The particle maker kit sensor works great, however any generic PIR sensor could possibly
×1
Software apps and online services:
Google sheets
Google Sheets

Schematics

Photon to PIR sensor
Battery pack attachment is not shown.
Photon pir diagram mabtelnamz
Interior Construct
20170412 192208 6bvm1vjwjm
Exterior Construct
20170412 192347 iy7tzbnblm
Message
20170412 204039 jsefcpnhaz
This is the full video explanation
20170412_195840_ambrIBVaTp.mp4
Motion Sense Graph
This graph is a live feed of the motion sensor that gives a timestamp when it is activated.

Code

Motion SensorJSON
// This #include statement was automatically added by the Particle IDE.
#include "lib1.h"

int inputPin = D0;              // choose the input pin (for PIR sensor)
int ledPin = D1;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

int calibrateTime = 10000;      // wait for the thingy to calibrate

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(inputPin, INPUT);     // declare sensor as input

}

void loop()
{

  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();

    // report it out, if the state has changed
    reportTheData();
  }
}

void readTheSensor() {
  val = digitalRead(inputPin);
}

bool calibrated() {
  return millis() - calibrateTime > 0;
}

void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {
      
    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("Motion Detected", "Motion Detected", PRIVATE);
      // Update the current state
      pirState = HIGH;
      setLED( pirState );
    String tempMessage = "1";
    Particle.publish("googleDocs", "{\"my-name\":\"" + tempMessage + "\"}", 60, PRIVATE);
    Particle.publish("pushbullet", "Teacher Tracker: your teacher is back. RUN!", 60, PRIVATE);
    }
  } else {
    if (pirState == HIGH) 
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
 void setLED( int state )
{
  digitalWrite( ledPin, state );
}
void publish() {
// Get some data
String data = String(10);
// Trigger the integration
Particle.publish("Motion detected", data, PRIVATE);
// Wait 60 seconds
delay(60000);
}
AlertJSON
int inputPin = D0;              // choose the input pin (for PIR sensor)
int ledPin = D7;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup()
    {
        Particle.subscribe("Motion Detected", data, MY_DEVICES);
    }

void data (const char *event, const char *data){
    
        if(strcmp(data, "Motion Recieved")==0)
    {
            digitalWrite (ledPin, HIGH);
            Serial.println("Motion Recieved");
    }
}

Credits

Dd48f1f24a2815b2b9b6824659a63e2e
Jose Giacopini

It's always fine

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.

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.

Alerts via Pushbullet When Smoke is Detected
Intermediate
  • 312
  • 8

Full instructions

This project uses two Particle Photons and Pushbullet to notify a user when smoke is detected by a smoke detector.

Add projectSign up / Login
Respect project