Clay RobinsonMatthew Pridmore
Published © MIT

Toilet Water Protector

Particle Photon with PIR Motion sensor and peizo buzzer to keep your dog from drinking out of the toilet!

BeginnerProtip5 hours843
Toilet Water Protector

Things used in this project

Hardware components

Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Buzzer
Buzzer
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Philips hue
Philips hue
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Hue service
IFTTT Hue service

Story

Read more

Schematics

Motion Sensor and Buzzer Wiring Diagram

Code

Motion Sensor

Arduino
int ledPin = D7;                 // choose the pin for the LED
int inputPin = D0;             // chose the reciever pin from sensor
int outputPin = D6;            // choose the buzzer output pin
    



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



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", "dog is drinking" );
    
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
    digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50); digitalWrite(outputPin, HIGH); delay(50);  digitalWrite(outputPin, LOW); delay(50);
   
    
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF if no input
    digitalWrite(outputPin, LOW); // turn buzzer OFF if no input
    Particle.publish("no_motion", "no one in the can");
  }
  delay(500);                           // wait .5s
}

Light controller

Arduino
int led = D7; //name D7 "led"

int motionyes;   //sets up motiondetected variable


void setup() {
    
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);                                              //sets D7 to LOW
    
    Particle.subscribe("motion_detected",led_on, "24001d001147353138383138");    //subsribes to motion sensor to see if motion is detected
    
    Particle.subscribe("no_motion",led_off, "24001d001147353138383138");  //subsribes tp motion sensor to see if no motion is detected
    
    Particle.variable("Motion_Yes", motionyes);                 // creates a variable for wheter or not there is motion

}

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

void led_off(const char *event, const char *data)
{
 digitalWrite(led,LOW);                                                 //if no motion, led is turned off
 
}

void loop() {
    motionyes = digitalRead(led);     // value will be 0 if no motion, 1 if motion

}

Credits

Clay Robinson

Clay Robinson

1 project • 0 followers
Matthew Pridmore

Matthew Pridmore

1 project • 0 followers

Comments

Add projectSign up / Login