Things used in this project

Hardware components:
13285 01
PIR Motion Sensor (generic)
×1
Photon new
Particle Photon
×1
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×1
Software apps and online services:
Ide web
Arduino IDE
Hand tools and fabrication machines:
Lasercutter
Laser cutter (generic)

Custom parts and enclosures

Enclosure Case Plans
Illustrator file for our enclosure which can be laser cut to create the enclosure that we used.
caseplans_(4)_7iQmRvnWbf.svg

Schematics

Fritzing Diagram
Fritzing diagram of our device. It includes the breadboard, the photon, the motion sensor and where each wires should go.
Image evklneukk4

Code

Code for PIR Motion SensorArduino
This is the code that we used for our project which is done in particle.io.
// This #include statement was automatically added by the Particle IDE.
#include <SparkFunPhant.h>
int ledPin = 7;                // choose the pin for the LED
int inputPin = 0;               // choose the input pin (for PIR sensor)
int pirState = HIGH;             // we start, assuming no  detected
int count = 0;
int val = 0;
int value1 = 0;
int value2 = 0;
const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "n14Zx31l5mtK19j4m97j"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "MoM7WxopDVCM8426Z472"; // Phant private key  - HAS TO BE CHANGED
Phant phant(server, publicKey, privateKey); // Create a Phant object
const int POST_RATE = 3000; // Time between posts, in ms.
unsigned long lastPost = 0;
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}
void loop(){
  value1++;
  value2++;   
  int val = digitalRead(inputPin);  // read input value
  if (val == HIGH) { 
      // check if the input is HIGH
    digitalWrite(ledPin, HIGH);// turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      count=count+1;
      Serial.println(count);
      postToPhant();
      
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

    }
  }
}




 // global variable to keep track of last post time
    //Replace the if statement below with whatever your trigger is

int postToPhant()
{    
    // Use phant.add(<field>, <value>) to add data to each field.
    // Phant requires you to update each and every field before posting,
    // make sure all fields defined in the stream are added here.
    phant.add("motion", val);
    phant.add("count", count);
        	
    TCPClient client;
    char response[512];
    int i = 0;
    int retVal = 0;
    
    if (client.connect(server, 80)) // Connect to the server
    {
		// Post message to indicate connect success
        Serial.println("Posting!"); 
		
		// phant.post() will return a string formatted as an HTTP POST.
		// It'll include all of the field/data values we added before.
		// Use client.print() to send that string to the server.
        client.print(phant.post());
        delay(1000);
		// Now we'll do some simple checking to see what (if any) response
		// the server gives us.
        while (client.available())
        {
            char c = client.read();
            Serial.print(c);	// Print the response for debugging help.
            if (i < 512)
                response[i++] = c; // Add character to response string
        }
		// Search the response string for "200 OK", if that's found the post
		// succeeded.
        if (strstr(response, "200 OK"))
        {
            Serial.println("Post success!");
            retVal = 1;
        }
        else if (strstr(response, "400 Bad Request"))
        {	// "400 Bad Request" means the Phant POST was formatted incorrectly.
			// This most commonly ocurrs because a field is either missing,
			// duplicated, or misspelled.
            Serial.println("Bad request");
            retVal = -1;
        }
        else
        {
			// Otherwise we got a response we weren't looking for.
            retVal = -2;
        }
    }
    else
    {	// If the connection failed, print a message:
        Serial.println("connection failed");
        retVal = -3;
    }
    client.stop();	// Close the connection to server.
    return retVal;	// Return error (or success) code.
}

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

Control Adafruit NeoPixels using Python and JQWidgets
Easy
  • 976
  • 8

Full instructions

In this tutorial, we'll see how to control an Adafruit NeoPixel ring via mobile using Python and JQWidgets.

I Keep My Cucumber Growing Conditions Moist - Part 3
Easy
  • 333
  • 3

Full instructions

This is the next step with an Particle Photon and softAP integration: cucumbers go online.

What's My I2C Address?
Easy
  • 274
  • 4

The story of how to make a clock through using a LCD 1602 or LCD 2004 over I2C.

Study Buddy
Easy
  • 2,867
  • 141

Full instructions

Know when an assignment is coming up!

Study Buddy

Team Alexa and Shannon

MyLCD20x4 clock with value-added information
Easy
  • 56
  • 0

Full instructions

Use a Particle Photon, a BME280 sensor and a cheap LCD20x4 to start your own clock-project.

MyHumidity Controlled by BME280 and Photon
Easy
  • 574
  • 6

Full instructions

Checks if humidity threshold is reached and informs the user by using Blynk/IFTTT-services with softAP integration.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog