Ryan McFarlandTimothy Stokes
Published © GPL3+

Time To Take The Dog Out

Have you forgotten to take your pet outside until it's too late? This project alerts you when your dog is waiting to go out!

BeginnerShowcase (no instructions)5 hours906
Time To Take The Dog Out

Things used in this project

Story

Read more

Schematics

Publishing Particle

The primary particle that uses the motion sensor and publishes an event when the sensor is tripped.

Subscribing particle

The secondary particle with an LED that waits for an event to be triggered.

Code

Publishing Particle

C/C++
This is the code for the particle that publishes an event when the PIR motion detector is tripped.
int ledPin = D0;                 // choose the pin for the LED
int inputPin = D2;             // chose the receiver pin from sensor

    



void setup() {
  pinMode(ledPin, OUTPUT);       // set LED as output
  pinMode(inputPin, INPUT);     //set input as input



}



void loop() {
  if (digitalRead(inputPin) == HIGH) {  // check if the motion sensor output HIGH
    digitalWrite(ledPin, HIGH);         // turn LED ON if high
   Particle.publish("motion_detected", "Mason needs to go out" );    //Mason is the dog
    
   
   
    
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF if no input
  
    Particle.publish("no_motion", "Mason not at door");
  }
  delay(1000);                           // wait 1.0s
}

Subscribing particle

C/C++
This is the particle that subscribes to the first device and turn on an LED light and sends an email when an event is found online.
int led=D2;

int mason_moving;



void setup() {

     pinMode(led,OUTPUT);
     digitalWrite(led,LOW);                                              //sets D0 to LOW
    
     Particle.subscribe("motion_detected",led_on, "590034000a51353531343431");    //subscribes to motion sensor to see if motion is detected
    
     Particle.subscribe("no_motion",led_off, "590034000a51353531343431");  //subscribes to motion sensor to see if no motion is detected
    
     Particle.variable("Mason_door", mason_moving);                 // creates a variable for whether or not there is motion

}

void led_on(const char *event, const char *data) {
 digitalWrite(led,HIGH);                                                //if motion is detected, led is turned on
 
}

void led_off(const char *event, const char *data) {
 digitalWrite(led,LOW); 
}
 
void loop() {
    
    mason_moving=digitalRead(led);
}

Credits

Ryan McFarland

Ryan McFarland

1 project • 0 followers
Timothy Stokes

Timothy Stokes

1 project • 0 followers

Comments