Cat Sprayer

Problem - My elderly cat has suddenly decided that she doesn’t want to use the litter box and is instead peeing on the hardwood floor under the dining table. I’ve tried a bunch of things to dissuade her but nothing has worked. The only thing she hates worse than the spray bottle is the vacuum*. So, I built motion sensor spray bottle. Here’s how to build your own.

*If this doesn’t work, maybe I’ll have automate the vacuum next

Components -

Arduino Uno clone

Spray Bottle

MG996 Servo

PIR sensor

Hose clamp

100uF Capacitor

Steel Picture hanging wire

Assorted wires, heatshrink, solder, zip ties

Breadboard layout

Step 1 - Breadboard and Test

Connect the red wires to the power pin on your PIR and Servo.

Connect the black wires to the ground connections

Connect digital Pin 6 to the PIR and Pin 9 the servo control.

Connect the capacitor to the red and black wires as shown. The longer lead of the capacitor is the positive lead and this should be connected to 5V.

When running off a strong USB power source from my computer, I didn’t need the capacitor, but when running off any other source, the arduino would reset immediately when the servo powered up. Before I found the capacitor solution in the Adafruit tutorial, I tried upping the voltage and using stronger power supplies connected to the Vin pin and ended up frying an Arduino. Using a cap seems to work fine.

Load the following script into the arduino and test that the servo rotates when the motion sensor trips. Use the serial monitor to monitor what’s happening.

/*PIR Cat sprayer Peter Quinn 2018
  detect cat
  yes, there is a cat
     wait 10 sec. Is it still there?
        Yes, squirt it
        No, do nothing
  wait 15 sec
  end of loop
  squirt it
  fire squirter twice
#include <Servo.h>
Servo myservo;
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 500;
boolean takeLowTime;
int pirPin = 6;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

void setup() {
 pinMode(pirPin, INPUT);
 pinMode(ledPin, OUTPUT);
 digitalWrite(pirPin, LOW);
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 //give the sensor some time to calibrate
 Serial.print("calibrating sensor ");
 for (int i = 0; i < calibrationTime; i++) {
 Serial.println(" done");
 Serial.println("SENSOR ACTIVE");

void loop() {
 Serial.println("main loop");
 if (digitalRead(pirPin) == HIGH) {
   Serial.print("motion detected at ");
   Serial.print(millis() / 1000);
   Serial.println(" sec");
   digitalWrite(pirPin, LOW);
   delay(10000);//wait 10 sec to see if it's still there
   if (digitalRead(pirPin) == HIGH) {//still high. time to squirt
     Serial.println("still there");

void squirt_it() {
 for (int i = 0; i <= 1; i++) {//squirt twice
   delay(1000);                       // waits 15ms for the servo to reach the position
   delay(1000);                       // waits 15ms for the servo to reach the position

Step 2 - Assemble the Servo/Sprayer

Mount the servo using the hose clamp. Arrange it so the horn is directly pointing at the spray bottle trigger when it’s at 0 deg.

Feed the steel wire through the holes on the servo horn, around the trigger and around the back of the sprayer. Be careful not to impinge on the the servo control wires as you could cut them. You might need to pre-tension the sprayer trigger a little to get a good spray.

I tested it again at this stage with the rest of the circuit still on the breadboard.

Step 3 - Connect and solder the wires

Solder the four black ground wires together with a piece of heat shrink. Do the same with the red wires. Solder one of the red and one of the black to the appropriate leads of the capacitor.

It ends up being a bit of a spider’s web of wires. If it turns out that I need this for more than a few days, I’ll come up with a more elegant solution.

Step 4 - Final Assembly

I used zip ties to hang the PIR to the spray bottle. I also made a holder for the PIR out of a scrap piece of MDF that I had from a previous project. A piece of cardboard would work just as well. The PIR that I have has tiny mounting holes on the PCB that are too small for a zip tie. I put some small bolts through those holes and connected it to the mounting MDF.  I drilled some holes in the MDF to zip tie it to the bottle.

Powering the sprayer

I mentioned previously that I fried a UNO while trying various power options. The servo takes more power than your typical blinky light project. Powering from a USB connected to a laptop, it all worked fine, even without the capacitor. Powering via a USB wall socket worked poorly. Powering from a USB battery worked but sucked down the battery in an hour or so. I am now using a wall wart power supply from by vast collection. It’s listed at 9V and 2A. The servo pulls 650mA when operating, well within the 2A rating.

Video here: