Christmas Tree Defender Cat Diversion Laser Turret with Arduino

How are you supposed to defend your Christmas tree from curious and fiendish cats? Why not distract them with a Christmas Tree Defender Cat Diversion Laser Turret!

This project, submitted by John Hart, uses a motion detector to activate a turret mounted laser. When the cat trips the motion sensor, the servo and laser go to action, diverting the cat from playing in the tree. At the center of his project is an Arduino UNO.

This project was submitted by one of our members.  You can see more of our member's projects here.

Not a member yet?  Sign up here.

What sensor does it use?

The sensor is a PIR (passive infrared sensor) that uses the infrared spectrum of light to detect motion. When it senses motion it sends a HIGH signal to the Arduino UNO. When the UNO sees the HIGH signal from the sensor, the program sweeps the laser turret in programmable angles, speed, and duration for best tree protection and family entertainment. The laser turret is made up of two servos on two axes so that it can point the laser around the room.

After getting the project working to distract the cats, John was able to mount the Arduino and laser turret on a box with the battery and breadboard inside. For a future upgrade, John plans to use a wireless connection between the sensor and the laser, so the sensor and laser turret can each be ideally located around the tree.

John: “I have learned A LOT from you over the last few months, and do not plan on stopping any time soon. Am actually working on interrupts right now. Once again…hope you and yours have a most wonderful Holiday. Thanx, John”

John’s enthusiasm and passion for his project while learning about programming, and fun that came along with it are great things to see. He even shares this hobby with his son, who does projects of his own for school! Many thanks to John for submitting this project along with his code.

Christmas Tree Cat Diversion Laser Turret with Arduino

After some further iteration, the breadboard is now snug inside the enclosure.

Christmas Tree Cat Diversion Laser Turret

Arduino Code:

//UNO_Laser_Turret_Cats_Tree_Defender_v1_14Dec16
//Created by JohnnyFRX - 14Dec16
//Special Thanks to Michael James excellent training at https://www.programmingelectronics.com/home/
//BOM - 1X Arduino UNO, 2X TowerPro SG90 Servos, 1X PIR Sensor, 1X Laser, Jumpers, Hot Glue/Gun, Imagination, Patience 

 

#include <Servo.h>

Servo myservo_up;           //Servo Nods
Servo myservo_left;         //Servo Sweeps

int servoPos = 0;           //variable to store the servos servoPosition
int pirVal = LOW;         //Initialize PIR as low/off
int PirPin = 2;             //PIR Arduino Pin
int laser = 13;             //Laser Arduino Pin


void setup() {

  myservo_up.attach(9);     //attaches the Sweep servo on Arduino pin 9 to the servo object
  myservo_left.attach(10);  //attaches the Nod servo on Arduino pin 10 to the servo object
  pinMode(laser, OUTPUT);   //set Arduino pin 13 as Output for laser
  pinMode(PirPin, INPUT);   //set Arduino pin 2 as Input for signal from PIR

}

void turret() {             //this is where the fun begins...watch your cats lose their minds!

  digitalWrite(laser, HIGH);                                  	// Activate the Laser by writing HIGH voltage to pin13.

  for (servoPos = 90; servoPos <= 180; servoPos += 1) {       	// Counter servoPos variable increases from 90 degrees to 180 degrees incrementing by one degree to it's max value
    myservo_up.write(servoPos);                              	 // Servo Nods to angle position currently stored in variable 'servoPos'
    delay(15);                                               	 // waits 15ms for the servo to reach the servoPosition
  }
  for (servoPos = 180; servoPos >= 90; servoPos -= 1) {      	 // Counter servoPos variable decreases from 180 degrees to 90 degrees decrementing by one degree to it's min value
    myservo_up.write(servoPos);                               	// Servo Nods to servoPosition in variable 'servoPos'
    delay(15);                                                	// waits 15ms for the servo to reach the servoPosition
  }
  for (servoPos = 40; servoPos <= 180; servoPos += 1) {      	 // Counter servoPos variable increases from 40 degrees to 180 degrees incrementing by one degree to it's max value
    myservo_left.write(servoPos);                             	// Servo Sweeps to servoPosition in variable 'servoPos'
    delay(15);													// waits 15ms for the servo to reach the servoPosition
																
  }
  delay(2000);													//waits 2 seconds to allow the cat to ponder the situation
  for (servoPos = 180; servoPos >= 40; servoPos -= 1) {       // Counter servoPos variable decreases from 180 degrees to 40 degrees decrementing by one degree to it's min value
    myservo_left.write(servoPos);                             // Servo Sweeps to servoPosition in variable 'servoPos'
    delay(15);                                                // waits 15ms for the servo to reach the servoPosition
  }
  delay(2000);													//waits 2 seconds to allow the cat to ponder the situation
}

void loop() {			//The main 'loop' is handling the motion detection and calling the action function 'turret' above, based on pirVal value.

  pirVal = digitalRead(PirPin);             // Read input value of PIR sensor and store it to variable 'pirVal'.
  if (pirVal == HIGH) {                      // If the 'pirVal' equals HIGH/On, proceed to counter and turret in next lines. If it's value is LOW/Off, skip counter/turret lines.

    for (int i = 0; i <= 4; i++) {        //Counter (stored in dynamically assigned variable 'i') begins and is set to execute and increment the following function 'turret' for 4 loops
      turret();                           //Jump to turret function when above 'if' condition is met
    }
  }

  delay(150);

  if (pirVal == LOW) {                  //check the current value of pirVal variable...if it equals LOW, skip next line and proceed to 'else'.

    pirVal = HIGH;                      //if you're here, the pirPin's current value does equal HIGH/On, so set pirVal variable to HIGH 
  }
  else {
    digitalWrite(laser, LOW);             //turn Laser OFF and end

    delay(300);
    if (pirVal == HIGH) {               //if pirVal is set as HIGH/On...start 'loop' again

      pirVal = LOW;                       //change the pirVal back to LOW/Off...wait for the cats to trip it again!
    }
  }
}

Great project John, and again, thanks for sharing!

installing Arduino libraries

Installing Arduino Libraries | Beginners Guide

IoT sewage project

Pumping poo! An IoT sewage project

ESP32 webOTA updates

How to update ESP32 firmware using web OTA [Guide + Code]

error message Brackets Thumbnail V1

expected declaration before ‘}’ token [SOLVED]

Compilation SOLVED | 1

Compilation error: expected ‘;’ before [SOLVED]

Learn how to structure your code

1 Comment

  1. […] you heard that right. This third project is a tool for diverting cats from a Christmas tree. The project was made by member John Hart. It uses an Arduino Uno and a motion sensor which […]

Leave a Comment