Things used in this project

Hardware components:
Photon new
Particle Photon
×2
13285 01
PIR Motion Sensor (generic)
×1
11026 02
Jumper wires (generic)
×7
Mfr 25frf52 1k sml
Resistor 1k ohm
×1
09590 01
LED (generic)
×1
Particle micro servo
×1

Schematics

PIR Configuration
Pir setup dq12tnoxf1
Servo Configuration
Servo setup e4k4dgzuaz

Code

PIR codeC/C++
const String key = "RWEL6M0ZC87IA980"; //write key
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
int rssival=0;
char publishString[40];
double motion = 70;
void setup()

{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     // declare sensor as input
  Particle.variable ("motion" &motion);
}

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 dopublish(){
    rssival = WiFi.RSSI();
    sprintf(publishString,"%d",rssival);
                
    Particle.publish("RSSI",publishString);
}
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("designingiot/s15/motion","Movement");
      // Update the current state
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}
bool updateThingspeak() 
{
    //delay (2000);
    static int count = 0;
    Serial.println(count++);
    int rssival = WiFi.RSSI();
    //sprintf(publishString,"%d",rssival);
    //bool success = Particle.publish("RSSI",publishString);
    
    //sprintf(publishString, "%1.4f", checkbattery());

      bool success = Particle.publish("thingSpeakWrite_All", +
     "{ \"1\": \"" + String(rssival) + "\"," +
       "\"2\": \"" + String(motion) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    return success; //if sent, then turn of the send flag, otherwise let it try again.
    
}
void setLED( int state )
{
  digitalWrite( ledPin, state );
}
Servo CodeC/C++
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created


int pos = 0;    // variable to store the servo position
int led = D7;


void setup( ) {
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
  // attaches the servo on the D0 pin to the servo object
  myservo.attach(D0);

  // register the Spark function

  Particle.subscribe("designingiot/s15/motion", anything, "270039001147353230333635");
}

void anything(const char *event, const char *data)
{
     digitalWrite(led,HIGH);
     if (strcmp(data, "Movement")==0)
     {
myservo.write(175);
delay(60000);
myservo.write(0);
     }
}

void loop()
{
  
}

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

E-Paper Weather Display with Photon and IFTTT
Easy
  • 4,029
  • 19

Full instructions

Create a beautiful medium for weather information using Particle's cloud services and IFTTT.

2-Way Particle Photon Communication
Easy
  • 194
  • 4

Make two Particle Photons "talk" via the usage of webhooks!

WiFi Strength Meter
Easy
  • 469
  • 6

A meter that indicates the Wi-Fi signal strength in an intuitive way, using the parts I had on hand.

IFTTT - Enabled Sensors with Particle Photon
Easy
  • 727
  • 12

Full instructions

Connect any sensor to Particle Photon and use it to trigger an IFTTT action with just a few lines of code.

Light Detecting Email Sender
Easy
  • 228
  • 4

Full instructions

Receive an email about when the light is too strong on your device; nobody wants a heated device left directly under the sun. Photon + IFTTT

Internet-Connected Popcorn Popper
Easy
  • 164
  • 1

Full instructions

A hot air popcorn popper triggered via the Internet! (Built for the Bellingham Codes May event.)

Add projectSign up / Login