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

Whats My I2C Address?
Easy
  • 32
  • 1

Protip

The story of how a Brix will be a clock by using an LCD 1602 or LCD 2004 over I2C.

MyHumidity Controlled by BME280 and Photon
Easy
  • 104
  • 2

Full instructions

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

Tweeting Particle Photon
Easy
  • 16
  • 1

Full instructions

Tweet your friends with only the press of a button!

MyLight-Clock with NeoPixel Ring 12 Controlled by Photon
Easy
  • 244
  • 2

Full instructions

Read the time at night? Without glasses? Impossible? Focus on 2 light points, which will tell you the hour and the minute.

Map Your Particles!
Easy
  • 1,323
  • 20

Protip

Locate your Particle Photons, P1s and Electrons on a map without needing extra hardware. Use Ubidots or an offline map alternative

BME280 measures and displays on OLED controlled by Photon
Easy
  • 320
  • 2

Protip

I share my first steps with the sensor BME280 (temp / humi / pressure / altitude) and an OLED 128 * 64 px

Add projectSign up / Login