Introduction: Cat Repellent
To start with, I do not hate cats but I love birds. In my garden we have some open cages where birds can enter and leave as they please. They can find food and water there. Unfortunately sometimes a cat from the neighborhood enters my garden and I do not want it to catch any birds.
I purchased a cat repellent some years ago but it did no longer work. When I purchased a new one, my daughter could hear the sound which was quite disturbing so I returned it. It seemed that it was operating at a frequency of around 20 kHz. I started looking for a version that worked on 40 kHz but then I had the idea to build one myself.
I was often surprised by the number of IC’s with external components that were used in these devices, also my previous version used two NE555 IC’s, one for the high frequency tone and one for blinking the LEDs on the device. I had no need for blinking LEDs, only the 40 kHz signal was sufficient for me.
My cat repellent is based on a PIC12F615 microcontroller that has on-board electronics to generate a Pulse Width Modulation (PWM) signal. Because of that hardware, hardly any external components are needed. Next to that I also used another feature of the PIC to enhance the functionality of my Cat repellent.
Step 1: The Cat Repellent Electronic Design
The schematic diagram shows the design of the cat repellent. It consists of one PIC12F615, two piezo buzzers and some capacitors. It is powered by three NiMH rechargeable batteries and it uses an external mini Passive Infrared (PIR) module to detect movement. Since my previous cat repellent had a solar panel, I reused it in this design as to recharge the batteries.
Initially I thought that I needed a driver IC like the HEF4049 to drive the piezo buzzers but that did not seem to be the case. The PIC was more than capable of driving the piezo buzzers directly. In the screenshots of my oscilloscope you see the signals of pin 2 and pin 3 of the PIC without and with the piezo buzzers connected to the PIC.
The PIC12F615 supports a PWM bridge mode which means that when one output goes high, the other output goes low. When connecting both outputs to a piezo buzzer, the voltage swing will be twice the battery voltage and so doubling the output signal of the piezo buzzers. I also included a screenshot of my oscilloscope of that signal.
The mini PIR module has all electronics integrated in the PIR detector and can operate on a supply voltage of 2.7 to 12 Volt. Its range is limited to about 3-5 meter which is sufficient for my purpose.
You need the following electronic components for this project:
- 1 PIC microcontroller 12F615
- 1 mini Passive Infrared Module (PIR)
- 1 shottkey diode, e.g. 1N5819
- 2 piezo buzzers, 40 kHz, e.g. Murata MA40S4S
- 4 ceramic capacitors of 100 nF
- 1 resistor of 1 kOhm
- 1 high brightness LED
- 1 battery holder for 3 AA batteries
- 3 NiMH AA rechargeable batteries
- 1 solar panel of 4.2 Volt, 100 mA. Could also be a panel with a higher voltage.
I did some measurements on the power consumption of the device. When in sleep mode the PIC hardly uses any power – at least I could not measure it – but the PIR is drawing a continuous current of 16 uA. When the PIC and buzzers are active, the average total current is about 4.4 mA. The power delivered by the solar panel should be sufficient to keep the batteries charged.
BTW. I only used 3 batteries because I had a solar panel laying around which was only capable of supplying around 4.2 Volt but you can also use 4 rechargeable batteries and a solar panel that can provide 6 Volt. If you do that the signal on the piezo buzzers will increase and so increasing the range of the cat repellent.
I used a breadboard to assemble the electronics. On the photo you can see the board during test.
Step 2: The Cat Repellent Housing
People that have a 3D printer could print the housing but since I do not have such a printer, I used white acrylic plastic with a thickness of 3 mm to create the housing. The pictures show the individual parts and the assembled version.
After gluing all the parts together – except for the bottom plate – I painted it with some gold spray paint that I had laying around.
Step 3: The Software
As mentioned earlier I used some additional on-board hardware of the PIC12F615 as to extend the feature set of the cat repellent.
The software performs the following main tasks:
- When the PIR detects movement, it generates a pulse on its output which is connected to the external interrupt pin of the PIC. This event will wake-up the PIC from sleep and will reset a timer. The timer will be reset with each detection of movement by the PIR.
- When the PIC is woken up and the timer is reset, a 40 kHz signal is generated for the piezo buzzers and the LED is turned on.
- When no movement is detected by the PIR for 60 seconds, the 40 kHz signal is stopped, the LED is turned off and the PIC enters a sleep mode to reduce power consumption.
- The extra feature is the following. The PIC has an Analog Digital Converter (ADC) on board which I used to measure the battery voltage. Two functions are implemented:
- When the battery voltage drops below 3.0 Volt and the device is active, the LED will blink to indicate that the battery voltage is low.
- When the battery voltage drops below 2.7 Volt and the device is active, the PIC will immediately go back to sleep after it was woken up. This feature is implemented to prevent that the batteries are fully drained which can harm the batteries.
As you may expect from all my PIC projects, the software is written in JAL, a Pascal-like high level programming language for PIC microcontrollers.
The JAL source file and the Intel Hex file for programming the PIC are attached.
If you are interested in using the PIC microcontroller with JAL visit the JAL website.
Step 4: The Cat Repellent in Action
This very short video shows the Cat Repellent in action. I am imitating a bit Cat by passing by the device from 3 meters away. As you can see - but not hear - the device is turned on as soon as I pass it.
To my surprise the PIR is quite sensitive, even more sensitive than the Cat Repellent device I had purchased many years ago. I also noticed that it switches on when big birds pass by but the sound does not seem to bother them.
Have fun making this Instructable and looking forward to you reactions and results.
38 Comments
Question 3 years ago on Step 4
I am just still trying to learn electronics. I saw this and my wife is having issues with the neighbors cats in her garden. I tried to build this and even had a board made to make it. How do you know the project is working. I tried to use the cheap oscilloscope I have to duplicate your scope pictures, but was unable to do it. I don't know if it is where or how I am connected to the circuit, or if something else has been done wrong. I found a phone app, but it did not seem to see the 40hKz signal. Bad solder joints- bad connections or.....! Any suggestions on how I can see if the signal is being produced? Do you need to use 2 buzzers on each build or can you just use one? Where did you find the ones you used. I found them Digikey for around 8.00 each plus shipping! My wife wants me to put them all around the house. I found the solar panel (6.2/198mw) for 7.00 plus shipping. Any help will be Greatly appreciated. Thanks for the build.
Answer 2 years ago
Hi,
I was wondering how this was progressing. Did you finish your project and did it work keeping the cats out?
Reply 2 years ago
Hi:
I made one to put out. I was unable to tell if it worked as I could not find an app or anyway to tell that the speaker was putting out a tone! I was going to tap a led into the buzzer line to tell if things were at least powering up, but I figured that might some how short out the buzzers or something. I put out an arduino with a buzzer and led that seems to annoy the cats but it annoys the wife too!!!. The solar panel I purchased did not seem to help things, as I purchased a 6 volt one and used 4 batteries and it did nothing to keep the batteries charged. I am sure the issues are due to the items I purchased not working and not your design. Thanks for your design and I hope you and your family stay safe and well.
Reply 2 years ago
Thanks for the update. What you can do for test is to temporay lower the frequency temporary to e.g. 10 kHz. This is a tone you can hear but it will not be that loud since it is not the resonance frequency of the resonator (see the datasheet on how much output it will produce at that frequency). For the solar panel: If you use 4 batteries you have to us a solar panel with a higher voltage. Also make sure you use rechargeable batteries that have low leakage current (always ready batteries). My version is already working for months without the need to recharge the batteries. You also stay safe and healthy!
Reply 2 years ago
Thanks for the information. I am going to buy a larger solar panel and see how that works. What ma rating on your panel or which one did you use? Could I ask you how to lower the frequency as you can teach me something👍? Thanks again. Don
Reply 2 years ago
About the 40 kHz --> 10 kHz. If you look in the source file you find this:
; The PWM must generate a frequency of 40 kHz = 25 us period time
; Register PR2 holds the PWM Timer Period using the following formula:
; PWM Period = (PR2 + 1) * 4 * Tosc * Timer2 prescale value where Tosc
; Tosc = 1/Fosc and Fosc = 4 MHz.Setting the prescaler to 1 and PR2 at 24:
; (24 + 1) * 4 * 1/4.000.000 * 1 = 25 us. Period Cycle = 40 kHz
T2CON_TOUTPS = 0b0000 ; Postscaler is 1:1 (no postscaling).
T2CON_T2CKPS = 0b00 ; Prescaler divide by 1
PR2 = 24 ; For this PIC this value brings it closer to 25 us.
By changing the PR2 value you change the frequency. 10 kHz equals 100 us (0.0001 seconds) which means:
0.0001 / (1/4.000.000) / 4 = 100 so PR2 must be 99 (PR2 + 1 must be 100).
For the Solar Panel I used something like this but I used 3 NiMH batteries so the maximum power supply is about 3.6 Volt so I ordered a panel that is able to produce 5 Volt (there is voltage drop over the schottky diode between the solar panel and the batteries that you need to take into account.
Diy Voor Batterij 5V Zonnepaneel Mini Zonnestelsel Telefoon Solar Cell 5.5V Laders Draagbare 70mA 80mA 100mA 110mA 160mA 180mA 291mA|Zonnecellen| - AliExpress
Answer 3 years ago
Hi Ampdb1. The board looks nice. I am not a fan of SMD but apparently you designed it for that. You can only detect the 40 kHz by using a piezo receiver (with electronics). With your scope you have to measure the signal over both pins of the piezo transmitter (so the ground of your scope to one pin and the probe of the scope to the other) this because the signal is doubled by the voltage on both pins changing at the same time (one pin from VCC to GND and the other from GND to VCC). So with a 5 Volt supply the voltage swing over the piezo buzzer should be 10 Volt. I only used 2 buzzers because I had them and wanted to produce more sound. It is not a scientific choice. If you have a 6.2 Volt Sonar panel I would recommend to use 4 NiMH batteries so that you have a higher voltage swing over the piezo buzzer. And then the question does it work? You only know if you have a cat walking by so I am not sure. The cat in my neighbourhood does not come that often. I am from The Netherlands and I purchased the piezo buzzer at a Dutch (it is actually German) company: https://www.conrad.nl/p/murata-ma40s4s-ultrasone-zender-1-stuks-reikwijdte-max-5-m-frequentie-max-40-khz-x-h-99-mm-x-71-mm-506195 The price is 5 Euro/piece. I saw you used a header for programing. Note that I connected pin 4 to VCC since I programmed the PIC not when it was installed on the board so make sure you disconnect pin 4 from VCC when you want to program the PIC. If you have more questions, let me know.
Question 2 years ago
Do you have any suggestion as alternative to Murata MA40S4S? I would really appreciate any suggestion from you or to our community. Nice project!
Answer 2 years ago
Hi Marcelo,
Thanks. I think you can use any other type as long as the resonance frequency is 40kHz and that the it can handle a voltage swing of twice the supply voltage (so around 2*3.6 Volt) which I think will not be a problem.
3 years ago
You don't need any kind of IC, not even a microcontroller, to build a variable frequency and amplitude oscillator. Two transistors are all that's needed, one for the actual oscillator and one for the amplification. (That's how I built a device to train myself in Morse, some 40 years ago.)
Plus, generating a square signal is bound to generate harmonics, most of them of frequencies that cats can no longer hear. That's wasted energy. Transistor-based oscillators generate something much closer to a sinus - hence less energy spent outside the cat-audible spectrum.
Combine that with a cheap photo cell and accumulator scavenged from a garden light and you have a device that will last as long as the charger and battery do and will be completely autonomous.
Reply 3 years ago
Obviously, this design is quite good, I like it a lot, especially because of its extra feature of power saving, which is difficult to achieve with analog circuits. Your suggested circuit wouldn't last at night, because of its power consumption.
On your second point: The ultrasonic devices (piezo operated) don't react properly to sine waves. To produce ultrasonic sound (16khz or more) you need something to act as an ultrasonic speaker. I agree, that theoretically sine waves have no incurred harmonics, and seem to be energy-saving. However, piezo elements react more like on-off. I am interested in your Morse device, and of course analog circuits have great value. Please share!!
Finally, to your cheap photo cell: A less than 1$ pic controller and few extra components will cost less than 5$, so analog electronics should stay in the past :-)
Reply 3 years ago
My Morse practicing device was about 35-40 years ago. I built it on a breadboard, by experimenting with a transistor and various passive components, then transferred it to a piece of pine with nails in it, where I soldered pieces of wire from one nail to another to build the circuit - at the age of 10 I wasn't allowed to work with strong acids to etch a circuit board. So obviously I don't remember the details. But it was something very simple. By far not a sine, though, that I can remember - sounded much like a duck's quack.
Reply 3 years ago
Hi Marcel, 👍
3 years ago
Just what I've been looking for! The neighborhood hoodlums, by that I mean stray and feral cats love to lounge in my front yard under a massive shade tree and taunt my dog, who has a full floor to ceiling window view of his tormentors. No amount of his barking seems to encourage their departure.
None of the commercial devices I've tried seem to do an effective job. Plus, being a collector of perfectly good parts salvaged from just about EVERYTHING over the decades. I greatly prefer to make the perfect device of my own.
I wanted something with a greater, more immediate and dramatic display. So... I put together a small air compressor and a 4 gallon tank with a line to the front yard. A solenoid valve, a remote RF switch, and a few short lengths of rubber tubing. When energized the hissing and flailing tubes has a tremendously exciting effect on the lounging felines. How a cat can go from lying flat out sleeping, to a 6 foot vertical leap in an instant is truly impressive. The only problem is - I have to be present to push the switch. Yes - I did try teaching the good boy to push it, but in the excitement of the moment, he always forgets.
Reply 3 years ago
I'd just let the dog roam the yard.
Reply 3 years ago
Front yard is not fenced in!
Reply 3 years ago
Haha, yes I think that water always works to get rid of cats. Instead of pushing the switch you could think of adding the PIR module.
3 years ago
Well done! They are fantastic devices for making your garden safe for birds, but the commercial ones do seem to have quite short lifespans. Thank you very much for sharing your work :-)
Reply 3 years ago
you're welcome!
Reply 3 years ago
You're welcome. Now lets see if it works but I need a Cat for that :-)