Creating an automatic laser cat toy

Building an automatic, programmable laser toy

My cat loves chasing laser lights. She loves them more than I like pointing them. So every night she stands in the usual spots and whines for me to play with her. Some (most) nights, I don’t have the energy. After buying an automatic laser toy for $40, which just goes in a circle and my cat doesn’t even chase, I decided I could do better. So I built my own.

This was my first Arduino project. I was surprised how easy it was.

You’ll need an arduino uno, 2 servos, an LED laser, and connecting wires/breadboard. You can save space by stripping the wires and directly connecting them, in which case you’ll need a utility knife and electrical tape.

Follow the links for the exact parts. The total cost was $42. Keep in mind that’s with me not knowing what I was doing. (I could have just bought 2 servos – the parts to connect them to each other come with each servo, and the only thing I really needed from the kit were the wires. This would have saved me over $10)

Step 1: Assembling the pan/tilt mount.

This took maybe a couple of hours. It should have taken 15 minutes because it’s maybe 6 pieces and some screws, but one of the plastic pieces didn’t line up and I had to cut it up a bit. Again, I didn’t know what I was doing.

Assembling the mount

Step 2: Figuring out this whole arduino thing.

I was new to arduinos but had heard good things. I found them very easy to use. It was a simple matter of downloading some software, connecting power, and connecting the 2 servos to pins 8 and 9. First I did it through a breadboard and then I connected them directly.

The program I used to test it was the simple arduino servo test program found anywhere.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Step 3: Wiring

This was just a matter of eliminating the breadbox and directly connecting the parts to power, and well as putting it all in a little box.

I found a small box and taped the mount to it, then taped the laser (and a motion detector – that white bulb thingy – which I ended up not using) to the mount.

I kept track of which wires went to the 5v, which went to Ground, and which went to pints 8 and 9. Then I stripped the wires and either used wire nuts or electrical tape to connect them. I stuffed the arduino and wires inside the box.

Putting it together

Step 4: programming

After messing around with coding servo movement myself, I decided to look for a library. Fortunately there is lots of code for doing exactly what I wanted already on the internet.

I found a nice one by Frank Appio. It has 12 different patterns. The complete code can be found here:

The only changes I had to make were to set the pins to the ones I was using (pins 8 and 9) and figure out the desired angles I wanted my toy to use (using the full range of 180 put the laser on the ceiling!). The code is well organized so a quick read-through told me where to make the changes (it was the first two lines in the code 🙂

COMPLETION!

And that’s it! I found a hook or two to hang my toy and let it rip! The results aren’t perfect – sometimes the laser moves towards the cat, and what cat wants to chase something that’s moving towards them – but it’s still a lot of fun for the cat and I don’t have to wave a laser pointer around forever!

(initial attempts with the motion detection failed – it keeps detecting *itself* moving!)