Arduino Laser Cat Toy
This fun gadget is a fully automatic laser cat toy built with an Arduino created to satisfy the hunting/playing needs of all cats! This project is perfect if you're like me as you can leave it for any amount of time you want, letting your cat choose how much it wants to play.
Safety is very important thus I recommend always having the laser point downwards towards the ground and never directly at anyone's eyes. Also in my case, I placed a clear box over my laser toy so that my cat wouldn't be able to interfere with the gadget (optional)
considering you have an Arduino a small budget of $10-$15 is more than enough to get you started.
Supplies
Assembly
Before wiring and coding, I always lay out my components together to see how I would like to arrange them and assemble my build.
For this step, I combined both of my Servos together one accounting for the horizontal movement of the laser and the other accounting for the vertical movement (yaw/pitch)
Next, I laid my flip switch next to my Arduino and got my teacher to Sauder the switch to some wires.
And finally, I taped the laser diode to the pitch axis of the Servo.
With everything already assembled, it would be much easier to be organized with the build.
Wiring!
At first, wiring can seem very intimidating but it is actually very easy once you get a basic understanding of it.
Firstly I wired a 5v cable and GND cable to the positive and negative rail on my breadboard to power it
Next, I connected the servo motor cables to the appropriate pin locations again 5v and GND cable went to the breadboard rail, while the cable labeled (s) went to the Arduino as it is a signal cable.
The laser diode only came with 2 wires and doesn't even require any code to run it has one power cable and one ground cable that I connected to my breadboard rail.
and lastly, the flip switch has 3 cables attached to it one for power, one for GND, and the middle one labeled (s) used to connect to the Arduino (signal cable)
(additional information) typically the color red will be represented for power while the color black will be represented for ground. Also worth mentioning is that my signal cables were all orange.
Coding
creating the code is slightly complex when adding a flip switch as it needs to toggle on and off however most of the servo commands are very straightforward and can be learned quickly.
-------------------------
#include <Servo.h> //servo library
const int switchPin = 12; //declares pin 12 to flipswitch
int switchState = 13; //
Servo servo; //servo 1 declared
Servo servo2; //servo 2 declared
void setup()
{
pinMode(switchPin, INPUT); //Switch is assigned as an input
Serial.begin(9600); // serial communication which allows commands to be sent through USB
servo.attach(3); // Pin 3 on arduino set to servo 1
servo2.attach(4); //Pin 4 on arduino set to servo 2
}
void loop()
{
switchState = digitalRead(switchPin); //reads the status of the switch
if (switchState == HIGH ) //allows the state to be toggled (1 or 0)
{
int clock = random(-110,110); //range of angle set to 110 degrees left 110 degrees right with random movement
servo.write(clock); //activates speed of servo
clock = random(-45,75); //range of angle set to 45 degrees downwards 75 upwards with random movement
servo2.write(clock); //activates speed of servo
delay(200); //delay 200ms
}
else{
delay(10); //delay 10ms
}
}
--------------------------------------------------