X

Do-it-Yourself – Build A Smart Cat Laser Toy to Keep Your Cat Entertained For Hours

Today we are going to go over creating a “smart” cat toy with an Arduino board and some Servos.  You can build this yourself, regardless of your experience, especially if you don’t have a programming background.

Link To Video: https://youtu.be/-WkcTPKJrrg

Do you want to build your own automated laser toy for your cat?  How about one you can voice-control or setup with a timer?


A low-budget version of 3 parts needed to purchase: Click here to see the base parts.

What’s in this Guide?

In this guide, I’ll be showing you a list of things that you need, variations to that list depending on your budget- and the software you need to get it working and keep your cat entertained while you are away.   You get to learn something new, see how easy it is to build a mechanical device and put software on it, and you can show it off to your friends and family.  If you want to unwind your cat at certain times of the day, keep them preoccupied, or let them sharpen their natural instincts of hunting in a fun way, then read on!

Regardless if you are a programming ninja, or just an average joe or jane!  You’ll need a few things though – we need the mechanical components to turn the arm and create movement, the board to essentially serve as the central point and processing for our mechanical components, and lastly – the body that we will use and move around with these electronics.

What You Need: (Links below of what you need to buy)

1 x Laser Module (the laser light piece): https://amzn.to/2Qg8eqN

1 x Arduino Board & Power Supply (the brain and power): https://amzn.to/2UsTCTh

1 x Pan / Tilt Body with 2 Servos: https://amzn.to/2EhHAYl

or  1 x Robot Mechanical Arm with two Servos: https://amzn.to/2L5NrjG

1 x Resistor for the laser (to not blind your cat, or yourself… Comes with Arduino Kit or Bought Seperately): https://amzn.to/2rsglli

Optional:

1 x Breadboard (so much easier to draft it all up): https://amzn.to/2EjBUgb

1 x A Circuit Board Holder (see below toward the bottom of article): https://amzn.to/2EmHqyA

Last Requirement:  Have a good attitude and ready for fun with nothing stopping you!  You CAN do this.

Let’s Go Over These Parts – Laser Module:

Warning: This is a low power laser device, however as with all laser devices care should be taken when in use. You should never look directly in to its beam or point the laser at another person or animal. Doing so may cause permanent eye damage. This item is not suitable for children.  Please consult with a qualified electrical engineer for further information if necessary.

Robot arm (Arduino board not included – see pan/tilt accessory for a cheaper & viable alternative):

Note: If you do assemble a robot arm and adapt it, here’s a few things to keep in mind:  If you have instructions, it is very useful and helpful.  I went the route of buying a cheap kit that was about 10-15 dollars cheaper for a robot arm, and I do not recommend that, but sometimes you just have to work with what the manufacturer provides.  It looks much easier with the pan/tilt accessory, which I’ve included.  Also, there is a ton of resources and as you would have guessed – I went online and found a comparable product with a pdf download and used those instructions instead to assemble my mechanical arm.

Or You Can Buy One Of These Instead…

Buy one of these Pan/Tilt Sensors – you do NOT need both of them – I left options for your Budget:

Cheap Arduino Board Kit:

Here’s the standard Arduino Board, however I definetely recommend a kit for a variety of reasons – mainly due to the fact that you don’t want to forget some parts and better to have when not needed then to need when you don’t have a part!  You’ve been informed, as it’s the worst feeling… Ever.

I Bought Both Of These Kits Myself:

I cannot stress my recommendations of buying a kit.  You’ll start collecting these parts and they are a godsend at some point and time in your journey of becoming a maker & citizen engineer!  Honestly, I probably wouldn’t have developed this toy, if it wasn’t for the extra kits I bought for fun – later to find out all the components I needed were already in my possession.

Gotchyas & I-Wish-I-Woulda-Knowsies:

The hardest part-  is going to be assembling the body.  If you didn’t see my smart mirror post, check it out.  The hardest part on this project and others in the past, was the woodwork and craftsmanship. I’m not a craftsman, and sadly- it is the part that gets me a little dumbfounded.  However, make sure you realize this invention is limitless with possibility.  Whether you want to do it with a robot arm like I did, or with a pan/tilt sensor with servos.  I’ve shared the pan/tilt sensor- this will save you at least 30-60 mins of assembly time, no doubt.

To make it even easier and cheaper – I’ve included links for the pan/tilt sensor even though it isn’t what I used specifically for this post.  I just wanted to make it as easy and frictionless as possible, especially if you are brand-new to this DIY electronics space…  See the bottom of article for more information on the pan/tilt sensor and inspiration I got for this build.  I basically wanted to create a robot arm, and since the design wasn’t working out for me- I took the claw and joints off of it, and adapted it into my laser pointer in less than an hour’s time.  Such a good decision that I am very proud of…  It was frustrating prior to that moment I made that choice (as I chuckle looking back at it).

The Instructions are Very Simple: (All of the devices you need are below – just click the links and purchase)

  • 1)  Assemble the Robot arm or Pan/Tilt Sensor
  • 2)  Wire the Servos like the diagram below (Data Cable Goes to Pin 9 and Pin 6 for each Servo and the other two wires for each servo you use with the breadboard and run the power on one circuit and the ground on another circuit of the breadboard – then run that circuit’s wire to the ground and 5v power ports)
  • 3)  Wire the Laser to Pin 13 and the other wire to the ground with a resistor coupled in between pin 13 and the power wire on the laser.
  • 4)  Install Arduino drivers onto your computer to interact with the board with the Arduino IDE
  • 5)  Plug in the Arduino board to your computer with the usb/power supply cable provided
  • 7)  Grab the code, copy/paste or download it from the top right button in the github repository in the code link above or below.
  • 8)  Add the code using the Arduino IDE and upload it to the board.
  • 9)  Unplug the usb power from your computer, and plug it into a 5v power adapter (a plug-in adapter into the wall for your usb) to take it away from the computer and start using it.
    Use hot glue or something to bind the laser to the pan/tilt (or robot arm) assembly and you’re good to go!

Want to cut to the chase?  Here’s the Code for the Arduino Board and setup: https://github.com/thesmarthomeninja/Laser-cat/blob/master/laser_cat.ino

Wiring It All Up:  Option without Breadboard –

Option with Breadboard –

After you get all the parts and have it all wired up – you’re going to need to get the drivers (so your computer can recognize the Arduino.
Download here:  https://www.arduino.cc/en/Main/Software

Windows: https://www.arduino.cc/en/Guide/Windows

Mac: https://www.arduino.cc/en/Guide/MacOSX

Linux: https://www.arduino.cc/en/Guide/Linux

Next Steps After Installed Software & Drivers:

Plug in the Arduino and make sure your computer recognizes it.  There’s lots of guides using the IDE online to assist.  After you have done that – you want to unplug it and go ahead and start getting it setup, assembled and connected together.  Just remember, this is your first draft- you can adapt it and fix the plane as you fly, as they say.  As far as the schematics and wiring diagram – there’s a couple of ways to do it – with and without a breadboard.  It’s really easy to understand the circuits and how to wire ground from Arduino board to ground on servos by aligning them on the same circuit. Hence, why I mention a breadboard.  Check them out, very easy to position wires for your setup.  Eventually a breadboard is tentative until you solder to a circuit board or use some kind of a “hat” for the Arduino.  A hat is a component that rests on top of the board.  These are good things to know at some point, which is why I mention.

Code for Arduino IDE:
Here is the code as well for the Arduino IDE below.  Big shout out and thanks to the original developer of this module we are going to inject into our Arduino board.  Credit goes to Lucas Berbesson, as he saved me hours of research and time by providing a straightforward and practical video, pictures and guide to make this possible, just copy paste below code or go here: https://github.com/thesmarthomeninja/Laser-cat/blob/master/laser_cat.ino

Here’s the Code To Insert, Just In Case:


#include <Servo.h>

/* YOU CAN CUSTOM THESE VARIABLES IF YOU WANT TO ALTER THE TOWER BEHAVIOUR */

// X servo angle will stay in [min_x, max_x] range
// Y servo angle will stay in [min_y, max_y] range
// to be ajsuted to the size of your living room

float min_x = 5;
float max_x = 50;
float min_y = 5;
float max_y = 35;
int min_freeze = 200;
int max_freeze = 3000;
float minimal_movement = 5;

/* YOU SHOULD NOT HAVE TO MODIFY THE CODE BELOW THIS LINE */

// finding center of square for starting point
int random_delay;
float x_position = min_x + (max_x - min_x)/2;
float y_position = min_y + (max_y - min_y)/2;
float x_old_position = x_position;
float y_old_position = y_position;
float x_new_position;
float y_new_position;
float x_speed;
float y_speed;
int movement_time;

// Instantiating two servos
Servo x_servo;
Servo y_servo;
int pos = 0;

void setup() {
y_servo.attach(6);  // attaches the y servo on pin 6 to the servo object
x_servo.attach(9);  // attaches the x servo on pin 9 to the servo object
pinMode (13, OUTPUT);
digitalWrite (13, HIGH);  // switch on  the laser

//Place the servos in the center at the beginning
y_servo.write(y_position);
x_servo.write(x_position);

}

void loop() {
movement_time = random(10,40);
random_delay = random(min_freeze, max_freeze);
x_new_position = random(min_x+minimal_movement, max_x-minimal_movement);
y_new_position = random(min_y+minimal_movement, max_y-minimal_movement);

if( (y_new_position > y_old_position) && (abs(y_new_position - y_old_position) < 5 )) {
y_new_position = y_new_position + minimal_movement;
}  else if ( (y_new_position < y_old_position) && (abs(y_new_position - y_old_position) < 5 )) {
y_new_position = y_new_position - minimal_movement;
}

if( (x_new_position > x_old_position) && (abs(x_new_position - x_old_position) < 5 )) {
x_new_position = x_new_position + minimal_movement;
}  else if ( (x_new_position < x_old_position) && (abs(x_new_position - x_old_position) < 5 )) {
x_new_position = x_new_position - minimal_movement;
}

x_speed = (x_new_position - x_old_position)/movement_time;
y_speed = (y_new_position - y_old_position)/movement_time;
for (pos = 0; pos < movement_time; pos += 1) {
x_position = x_position + x_speed;
y_position = y_position + y_speed;
x_servo.write(x_position);
y_servo.write(y_position);
delay(10);
}
x_old_position = x_new_position;
y_old_position = y_new_position;
delay(random_delay);

}



Credit for code goes to Lucas Berbesson


Further Resources, Links and Content:

Inspiration: https://imgur.com/gallery/kbylT

Alternative Article (make sure to translate to English in Chrome): http://www.lafabriquediy.com/tutoriel/tour-laser-pour-chat-259/

To Wrap Things Up and Not Miss A Thing, As That’s The Worst- You Need:

  1. An assembly – robot arm or pan/tilt w/ two servos
  2. An Arduino Board AND power supply cable
  3. A Resistor & Wires (you’ll have to buy a set if you don’t get a kit) – for the Laser
  4. The Laser Module
  5. If you get the robot arm or pan/tilt without servos – don’t forget those!

Last Optional Recommendations:

9V Battery Power Supply: (Optional)

If you plan on using more features or servos – it is recommended to have an additional power supply as well either via battery or wall adapter – like one of these.

DC Wall Plug-In Adapter:

A Resistor Kit: (Optional)

And just in case – here’s a resistor set that will last you forever, likely as I’ve hardly put a dent in mine.

A Standard Breadboard for Wiring & A Cutesy Set of Little Breadboards: (Optional)

The small breadboards I used in my video, but you don’t even need one for this project – however, it will save you a lot of time and hassle later on.

Circuit Board Holders/Mounting Options: (Optional)

In Summary:
I hope you enjoyed my article.  Keep in mind, there are other kits you can buy and piece it together- that include infrared receivers, transmitters, remote controls, Arduino hats and other development boards.  Once you are done with this project, you will be full equipped to enter the testing grounds of limitless possibilities with Arduino.

" The SmartHome Ninja : Owner, creator, imagineer, smart home enthusiast, tester, practical applicator extraordinaire.."

This website uses cookies.