Rachel GlendenningTristan Cromer
Published

Cat Motion Detection Device

Do you have an unruly pet who just will not stopping jumping on the countertop in attempt to get human food? We have the answer for you!

BeginnerFull instructions provided5 hours1,187
Cat Motion Detection Device

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

PIR Motion Sensor Photon Circuit Diagram

PIR Motion Sensor Photon Circuit Diagram

Speaker Photon Circuit Diagram

Speaker Photon Circuit Diagram

Code

Photon with PIR Motion Sensor

C/C++
This is the code for the first photon and motion sensor.
int PIRsensor = D2;
int ledPin = D7;
int PIRstatis = LOW;


void setup() {
    //this tells the photon if a pin is an input or output and subscribes to the function
    Particle.subscribe("gotem", confirm, "2a0024000d47363330353437");
    pinMode(PIRsensor, INPUT);
    pinMode(ledPin, OUTPUT);
    

}

void loop() {
    //this says that if the PIR sensor is high then the photon will publish the "CAT!!" function to the cloud.
  if (digitalRead(PIRsensor) == HIGH)
  {
      Particle.publish("CAT!!","Cat is on the counter!",PUBLIC);
  }
  delay(5000);
}

void confirm(const char *event, const char *data)
{
    //this subscibes to the "confirm" event meaning the other photon has received the "CAT!!" even and will flash the LED
   digitalWrite(ledPin, HIGH);
   delay(500);
   digitalWrite(ledPin, LOW);
   
}

Photon with Speaker

C/C++
This is the code for the second photon and speaker
int ledPin = D7;
int buzzer = D0;
void setup() {

    Particle.subscribe("CAT!!", alarm, "380020000947363339343638");
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);
    pinMode(buzzer, OUTPUT);
}

void alarm(const char *event, const char *data)
{
    //this subscribes to the "alarm" event and makes a sound and publishes
    //"got'em" when motion is detected to send to the other photon
    if (event)
{
    digitalWrite(ledPin, HIGH);
    tone(buzzer, 4000); //this sets the frequency to 4000 Hz and plays the tone for half a second
    delay(500);
    noTone(buzzer);
     tone(buzzer, 3000);
    delay(500);
    noTone(buzzer);
     tone(buzzer, 4000);
    delay(500);
    noTone(buzzer);
    tone(buzzer, 3000);
    delay(500);
    noTone(buzzer);
     tone(buzzer, 4000);
    delay(500);
    noTone(buzzer);
     tone(buzzer, 3000);
    delay(500);
    noTone(buzzer);
    digitalWrite(ledPin, LOW);
    Particle.publish("gotem", "The cat is off the counter", PUBLIC);
}
      delay(15000);
}

void loop() {   
}

Credits

Rachel Glendenning

Rachel Glendenning

1 project • 1 follower
Tristan Cromer

Tristan Cromer

1 project • 0 followers

Comments