Personal Cat fitness trainer :-)

As a beginner myself i like to try some little projects.

Here's a small taste of a simple Arduino project.

The CAPT - Computer aided pet toy :slight_smile:

The toy stops automatically after 5 minutes.

Using two servos, an Arduino Nano and a cheap "Cat-it Laser Mouse"

Video on Youtube :Klick !

// This code is designed for Nano V.3 
// this code is public domain, enjoy!

#include <Servo.h>


Servo ver; 
Servo hor;
boolean replay = true;

unsigned long time_since_last_reset = 0;


void setup() { 


  ver.attach(2);
  hor.attach(3); 
  pinMode(4, OUTPUT);
  pinMode(13, OUTPUT);
}

void migrate(Servo &myServo, int newPos) {
  int wait=random(30,60); //random (40,60) (10,30)
  int pos = myServo.read(); //Read servo position
  if (pos < newPos) { 
    for (int i=pos; i < newPos; i++) {
      myServo.write(i);
      delay(wait); 
    }
  } else { 
    for (int i=pos; i > newPos; i--) { 
      myServo.write(i);
      delay(wait);
    }
  }
}
    
  
void randomPosition() {
  int rand=random(20,100); //Horzontal range 80 deg 
  migrate(hor, rand);
  
  rand=random(85,110); //Vertical range around 25 deg
  migrate(ver, rand);
}
   
void loop() { 
    digitalWrite(4, HIGH);   // turn the Laser on
    digitalWrite(13, HIGH);   // turn onboard led on :-))
 
  randomPosition();
  delay(1500);

 
   
 digitalWrite(4, LOW);   // turn the Laser off
 digitalWrite(13, LOW);   // turn onboard led off
 ver.write(120);
 hor.write(70);
 
if(millis() >= 500000)
{
while(1)
{
}
}
}

Have fun :wink:

Poor cat :smiling_imp:

Like many... I've used a laser to fool my cats as well, but finally they got bored...
I probably have broken the 5-minutes limit too often ::slight_smile:

I like your project, people probably won't buy a pair of servos, loose board etc. though.
As a usb-gadget with funny/better looking enclosure, a name like "personal cat fitness trainer", quite a lot of people may be interested...

Thanks for your comment.

Of course personal cat fitness trainer sounds much better :wink:

Slightly modified and LED timer added. Shows how many minutes left, one LED for every minute.

// This code is designed for Nano V.3 by AndreasVan 2014-12-10
// this code is public domain, enjoy!

#include <Servo.h>


Servo ver; 
Servo hor;
boolean replay = true;

unsigned long time_since_last_reset = 0;

void setup() { 


  ver.attach(2);
  hor.attach(3); 
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(13, OUTPUT);
}

void migrate(Servo &myServo, int newPos) {
  int wait=random(30,60); //random (40,60) (10,30)
  int pos = myServo.read(); //Read servo position
  if (pos < newPos) { 
    for (int i=pos; i < newPos; i++) {
      myServo.write(i);
      delay(wait); 
    }
  } else { 
    for (int i=pos; i > newPos; i--) { 
      myServo.write(i);
      delay(wait);
    }
  }
}
      
void randomPosition() {
  int rand=random(20,100); //Horzontal range 80 deg 
  migrate(hor, rand);
  
  rand=random(85,110); //Vertical range around 25 deg
  migrate(ver, rand);
}
   
void loop() { 
    digitalWrite(4, HIGH);   // turn the Laser on
    digitalWrite(5, HIGH);   // turn 5min led on 
    digitalWrite(6, HIGH);   // turn 4min led on
    digitalWrite(7, HIGH);   // turn 3min led on
    digitalWrite(8, HIGH);   // turn 2min led on 
    digitalWrite(9, HIGH);   // turn 1min led on 
    digitalWrite(13, HIGH);  // turn onboard led on 

if(millis() >= 60000) // 5min
{
 digitalWrite(5, LOW);   // turn 5min led off
{
}}
if(millis() >= 120000) // 4min
{
 digitalWrite(6, LOW);   // turn 4min led off
{
}}
if(millis() >= 180000) // 3min
{
 digitalWrite(7, LOW);   // turn 3min led off
{
}}
if(millis() >= 240000) // 2min
{
 digitalWrite(8, LOW);   // turn 2min led off
{
}}
 
  randomPosition();
  delay(1500);
 
  digitalWrite(4, LOW);   // turn the Laser off
  digitalWrite(9, LOW);   // turn 1min led off
  digitalWrite(13, LOW);   // turn onboard led off
 
 ver.write(120);
 hor.write(70);
 

if(millis() >= 300000) // 300.000 mili = 5 minutes
{
while(1)
{
}
}
}

I notice you already have a cat trainer on the background of your first picture, isn't it functional ?

I was thinking, a PIR motion sensor will probably be triggered by a cat as well. If you place one on the floor and read it with your arduino, your cat could operate the trainer by itself.

Simpson_Jr:
I notice you already have a cat trainer on the background of your first picture, isn't it functional ?

Unfortunately this trainer doesn't always work reliably :wink:

Simpson_Jr:
I was thinking, a PIR motion sensor will probably be triggered by a cat as well. If you place one on the floor and read it with your arduino, your cat could operate the trainer by itself.

That's a good idea and will work with the dog too 8)

That's pretty cool :o

i dont see how you came up with "cat" o_O

AndreasVan:
Video on Youtube :Klick !