Emily Silva
Published © MIT

Cats Love Dogs Hate Toy

In a household of gnarled dog toys, this is a cat toy designed to keep away dogs and allow cats to enjoy a toy entirely of their own.

BeginnerWork in progress6 hours80
Cats Love Dogs Hate Toy

Things used in this project

Hardware components

Grove - OLED Display 1.12'' V2
Seeed Studio Grove - OLED Display 1.12'' V2
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Three input/ output: SIG, VCC, GND
×1
Photon 2
Particle Photon 2
×1
LED (generic)
LED (generic)
×1
Buzzer
Buzzer
×1
Button
×1
Philips hue
Philips hue
×1
Wemo Controlled Device
×1

Software apps and online services

Visual Studio Code Particle Workbench
Fritzing
OnShape

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Laser cutter (generic)
Laser cutter (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Custom parts and enclosures

CATS LOVE DOGS HATE TOY

3D OnShape model

CATS LOVE DOGS HATE TOY

2D CAD drawing

Schematics

CATS LOVE DOGS HATE TOY

Fritzing diagram
*ultrasonic sensor used has three pins (SIG, VCC, GND)

Code

CATS LOVE DOGS HATE TOY

C/C++
A movement detected alarm for preventing dogs from chewing cat toys.
Note: some code is commented and removed due to delay when setting multiple Hue lights off at once.
#include "Particle.h"
#include "IoTClassroom_CNM.h"
#include "Button.h"
#include "Adafruit_SSD1306.h"
#include "Grove-Ultrasonic-Ranger.h"

const int sigPin = D16;
const int HUEBULB = 2;
//const int HUEBULB[] = {1,2,3,4,5,6}; Six (6) Hue bulbs, commented out due to delay
const int BUZZER = D15; 
const int CATBUTTON = D10; 
const int MYWEMO=1;
//int numBulbs; Six (6) Hue bulbs, commented out due to delay
int ledPin = D6; 
int color;
int soundBuzzer = 1500;
int distanceInch;
float distance;
float inch;
bool onOff;
//bool hueOnOff; To operate six (6) Hue bulbs, commented out due to delay
String ONOFF;
Button catButton(CATBUTTON);
long duration;
long rangeInInches;
//unsigned long currentTime; To operate six (6) Hue bulbs, commented out due to delay
//unsigned long lastSecond; To operate six (6) Hue bulbs, commented out due to delay
//void hueFill(int startHue, int endHue, int color, bool onOff); To operate six (6) Hue bulbs, commented out due to delay

#define OLED_RESET D4
Adafruit_SSD1306 display(OLED_RESET);
Ultrasonic ultrasonic(sigPin);
SYSTEM_MODE(SEMI_AUTOMATIC);


void setup() {
pinMode (ledPin, OUTPUT);
pinMode (HUEBULB, OUTPUT);
pinMode (BUZZER, OUTPUT);
pinMode (CATBUTTON, INPUT); 
onOff = false; 

Serial.begin(9600);
waitFor(Serial.isConnected,15000);
onOff = false;
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.display(); 
delay(1000);

WiFi.on();
WiFi.setCredentials("IoTNetwork");
WiFi.connect();

while(WiFi.connecting()) {
  Serial.printf("Connecting, Please Wait.");
}
  Serial.printf("\n\n");
}

void loop() {
//currentTime=millis(); To operate six (6) Hue bulbs, commented out due to delay
rangeInInches = ultrasonic.MeasureInInches();
Serial.printf("Distance:%d\n", rangeInInches);
	
if ((rangeInInches<5)&&(rangeInInches>0)){
   Serial.printf ("dog detected");
   digitalWrite (ledPin, HIGH); //red LED eyes on the mouse
   tone(BUZZER, soundBuzzer);
   display.clearDisplay();
   display.setCursor(40,10);
   display.printf("BAD DOG \n \n <-- <-- <-- <-- <--\n \n CAT OVERRIDE BUTTON \n <-- <-- <-- <-- <--");
   display.display();
   Serial.printf("Turning on Wemo# %i\n",MYWEMO);//wemo turning fan on
   wemoWrite(MYWEMO, HIGH);
   setHue(HUEBULB, TRUE, HueRed, 55, 255);
   setHue(HUEBULB, TRUE, HueRed, 255);

}
   
   //if ((currentTime-lastSecond)>5000) { To operate six (6) Hue bulbs, commented out due to delay
     //lastSecond=millis();
     //hueOnOff = !hueOnOff;
     //hueFill(0,2,HueRed, hueOnOff);
     //hueFill(3,6, HueRed, !hueOnOff);
    //}
  

 if ((rangeInInches >5)||(rangeInInches==0)) {
   setHue(HUEBULB, true, HueBlue, 55,255);
   //hueFill(0,6,HueBlue, true); To operate six (6) Hue bulbs, commented out due to delay
   Serial.println ("no dog detected");
   noTone(BUZZER);
   digitalWrite (ledPin, LOW); //turn off red LED eyes on the mouse
   display.clearDisplay();
   display.setCursor(40,10);
   display.printf("GOOD DOG");
   display.display();
   Serial.printf("Turning off Wemo# %i\n",MYWEMO);
   wemoWrite(MYWEMO,LOW);
  
}

  if (catButton.isClicked()) { 
        onOff = !onOff; 
        ONOFF = String (onOff);
        Serial.println ("cat override");
        setHue(HUEBULB, true, HueBlue, 55, 255);
        //hueFill(0,6,HueBlue, true); To operate six (6) Hue bulbs, commented out due to delay
        noTone(BUZZER);
        digitalWrite (ledPin, LOW); //turn off red LED eyes on the mouse
        display.clearDisplay();
        display.setCursor(40,10);
        display.printf("CATS RULE");
        display.display();
        Serial.printf("Turning off Wemo# %i\n",MYWEMO);
        wemoWrite(MYWEMO,LOW);
        delay (10000);

      
  }
}

//void hueFill(int startHue, int endHue, int color, bool onOff){ To operate six (6) Hue bulbs, commented out due to delay
      //for(numBulbs=startHue; numBulbs<endHue; numBulbs++) { 
     //   setHue(HUEBULB[numBulbs], onOff, color, 55,255);
     // }

 
  //FUTURE ADD: while loop for vibrating component to be set on timer 
  //FUTURE ADD: vibrating componet to be manually turned on with movement
  //FUTURE ADD: dog collar to sense difference in "whom's" movement should be detected

Credits

Emily Silva
2 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.