Jacob Tucker
Published © GPL3+

Cat Caddie

Entertain your felines for hours without the wrist pain using this sensor-activated bird wand.

BeginnerWork in progress2 hours729
Cat Caddie

Things used in this project

Hardware components

Photon
Particle Photon
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Photo resistor
Photo resistor
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Pan and Tilt Kit w/ MG 995 Servos
×1
Cat Wand
×1
Laptop or Powerbrick
×2
Misc Structural Components
×1

Software apps and online services

Particle Dev

Hand tools and fabrication machines

Screwdriver
Pliers

Story

Read more

Schematics

Original Schematic

Code

Motion Sensor

C/C++
The motion sensor detects when a cat enters an area - it can be placed either by a doorway or near the Cat Caddie itself. The photoresistor is calibrated for average indoor lighting.
int photoresistor = A0;
int power = A5;
int intactValue;
int brokenValue;
int beamThreshold;
bool beamBroken = false;

void setup() {
  pinMode(photoresistor,INPUT);
  pinMode(power,OUTPUT);
  digitalWrite(power,HIGH);
  beamThreshold = 70;
}
void loop()
{
      if (analogRead(photoresistor)>beamThreshold) {
        if (beamBroken==true) {
          Particle.publish("beamStatus","intact");

          beamBroken=false;
          }
        else {
            }
          }
      else {
        if (beamBroken==false) {
          Particle.publish("beamStatus","broken");

          beamBroken=true;
          delay(10000);
          }
      else {}
      }
    }

Wand Routine

C/C++
The wand photon listens for the event published by the motion sensor and goes into its servo routine.
int vertpin = A4;
Servo vertservo;
int vertpos = 0;
int horzpin = A5;
Servo horzservo;
int horzpos = 0;


void setup() {
  pinMode(vertpin,OUTPUT);
  pinMode(horzpin,OUTPUT);
  Particle.subscribe("beamStatus", catroutine);
  vertservo.attach( A4 );
}
int horzcontrol() {

}
void catroutine(const char *event, const char *data) {
  if (strcmp(data,"intact")==0) {
   }
   else if (strcmp(data,"broken")==0) {
     vertpos=0;
     vertservo.write(vertpos);
     delay(2000);
     vertpos=20;
     vertservo.write(vertpos);
     delay(2000);
     vertpos=10;
     vertservo.write(vertpos);
     delay(2000);
     vertpos=50;
     vertservo.write(vertpos);
     delay(2000);
     vertpos=10;
     vertservo.write(vertpos);
     delay(2000);
     vertpos=0;
     vertservo.write(vertpos);
     delay(2000);
   }
  else {
   }
}

Dual Axis Test

C/C++
Use this code with the servo-side Photon in order to develop desired routines and test structural integrity.
int horzpin = A5;
Servo horzservo;
int horzpos = 0;
int vertpin = A4;
Servo vertservo;
int vertpos = 0;
void setup() {
  horzservo.attach( A5 );
  Particle.function("servo", horzcontrol);
  Particle.variable("horzposition", &horzpos , INT );
  vertservo.attach( A4 );
  Particle.function("servo2", vertcontrol);
  Particle.variable("vertposition", &vertpos , INT );
}
void loop() {
}
int horzcontrol(String command)
{
   int newhorzpos = command.toInt();
   horzpos = constrain( newhorzpos, 0 , 180);
   horzservo.write( horzpos );
   return 1;
}
int vertcontrol(String command)
{
   int newvertpos = command.toInt();
   vertpos = constrain( newvertpos, 0 , 180);
   vertservo.write( vertpos );
   return 1;
}

Credits

Jacob Tucker

Jacob Tucker

1 project • 0 followers

Comments