Go Down

Topic: Personal Cat fitness trainer :-) (Read 209 times) previous topic - next topic

AndreasVan

Feb 08, 2015, 04:14 pm Last Edit: Feb 15, 2015, 10:48 am by AndreasVan
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 :-)

The toy stops automatically after 5 minutes.

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

Video on Youtube :Klick !



Code: [Select]

// 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   ;)

Simpson_Jr

#1
Feb 14, 2015, 01:02 am Last Edit: Feb 14, 2015, 01:03 am by Simpson_Jr
Poor cat  :smiley-twist:

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 ::)

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...


AndreasVan

Thanks for your comment.

Of course personal cat fitness trainer sounds much better  ;)

AndreasVan

#3
Feb 15, 2015, 12:05 am Last Edit: Feb 15, 2015, 10:47 am by AndreasVan




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

Code: [Select]

// 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)
{
}
}
}




Simpson_Jr

#4
Feb 15, 2015, 01:57 am Last Edit: Feb 15, 2015, 01:59 am by Simpson_Jr
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.

AndreasVan

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  ;)

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)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy