Arduino Laser Cat Toy

by 720083 in Circuits > Arduino

552 Views, 0 Favorites, 0 Comments

Arduino Laser Cat Toy

IMG_2522[1].JPG
IMG E25231
IMG E25111
IMG_2521[1].JPG

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

IMG_2524[1].JPG

Assembly

IMG_2527[1].JPG
IMG_2528[1].JPG

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!

IMG_2530[1].JPG
IMG_2531[1].JPG

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

0d423e03b1c36b7382299fcc11912265.png

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

  }

  }

--------------------------------------------------

Diagrams and TinkerCad

c96c14d2efbfac70e8f50323d0bfc676.png
7e12e39e90ac7a2a94fe364938617a9c.png
bab3f5e4bc39b5e35691963fe99d9730.png

Happy Cat

download.jpg
123cat_400x400.jpg
SadCat project video 1.0