Introduction: Ultra Sound Cat Repeller Based on ATTINY85

Let be clear : I like cats. But I prefer when they poop somewhere else that in my garden.

I made a very simple ultra-sound emitter because cats are supposed not to like high pitch. It is triggered by a motion sensor and emitts about 15kHz.

I made tests with 15kHz and then with 20kHz. 15kHz made the best results but I confess I am not 100% sure that it will works in any case. The purpose is to disturb the cat to make it understand to find a better place... but some are stuborn.

The project is based on a ATTINY85 programmed with Atmel Studio. Be aware that it is not an Arduino based, I like Arduino because it makes things simple but it is not adapted to the ATTINY processors.

As usualy If you have no PCB making and processors programming skills I can provide you the fully assembled board. Just contact me here.


For this project you will need :

  • Skills :
    • PCB components soldering
    • ATTINY85 programming
    • Eagle Autodesk basics for viewing the PCB
    • 3D printing
  • Specials Tools :
    • 3D printer
    • Iron solder
    • A glue gun
    • Velcro
    • A drill
    • M3 tap
    • For ATTiny programming
      • an USBasp programmer (found on aliexpress)
      • an ISP adapter

  • Parts (bought on :
    • A motion sensor HC-SR501
    • A ultra-sound speaker -> search for "51MM diameter Ultrasonic speaker waterproof" on aliexpress
    • 4 NiMH accumulators, AA type
    • A battery pack to hold the accumulators
    • 6 M3-10mm screws and nuts
    • A ON/OFF switch
  • Component for PCB making
    • 1 *C0805 100nF capacitor
    • 1 *Electro. capacitor 100uF, 2.54mm, max. 7mm diameter
    • 8 *Pinheaders
    • 1 *green LED 1206
    • 1 *SOT23 mosfet (A03400)
    • 2 *10k ohms resistors, 1/4W
    • 1 *2.2k resistor, 1/4W
    • 1 *momentary push switch
    • 1 *ATTINY85, DIP8
    • 3 *XH-2 connectors
    • 1 *XH-3 connector

Step 1: The 3D Printed Housing

Designed with Fusion 360.

Print in 3 times :

  1. First the main housing
  2. The bottom
  3. The speaker bracket

I've used :

  • White PLA, see note below
  • 0.4mm nozzle
  • 0.3mm layers

It took about 12 hours.

note : As the housing is designed to be outdoor, choose a clear color. Not dark because it will deform itself when the sun is hot.

Step 2: The Circuit

The circuit is powered by 4 NiMh accumulators, which provide about 4.8 V. It is a good voltage for the ATTiny and there is no need to use a regulator.

The reset PIN is quickly grounded when pressing the switch, through the capacitor : this effect is of course to reset the micro-controller.

PB3 is configured as OUPUT and binded directly to the speaker. Indeed the port can deliver up to 40mA, which is plenty enough for this kind of speaker.

PB4 is configured as INPUT and indirectly binded to the PIR sensor through the MOSFET Q1. Q1 acts as a level converter, because the PIR sensor delivers only 3V ouput.

The ISP port will be used to upload the code and I will show you how in a next step.

The LED is like the built-in LED on an Arduino, very convenient ;-)

Step 3: Make the PCB

I provide here Eagle files. I recommand OSH Park to make the PCB.

No difficulties for soldering, start with the smd resistors and led, then the push switch ... finish by the capacitor.

  • I've soldered a DIP 8 socket to make the ATTINY removable

Step 4: Prepare the ATtiny 85

The ATtiny needs to be configured before we use it. It is a processus that can be complicated but fortunatly Arduino has an option to help.

First of all let add ATtiny boards support to the Arduino IDE.

Tip : it maybe necessary to restart Arduino somewhere ... if it doesn't work.

Second :

  • plug the USBasp programmer to the cat reppeler board ISP, using the adapter (see photo)
  • on Arduino : select Tools -> Programmer and select USBasp
  • then Tools -> Boards -> ATtiny microcontrollers -> ATtiny 25/45/85 family
  • Tools -> Processor -> ATtiny85
  • Tools -> Clock -> internal 1Mhz
  • Tools -> Burn Booloader

Now the ATtiny85 is ready to upload the code.

Step 5: Upload the Code

The purpose in this step is to push the provided hex file into the ATTiny memory. The hex file contains the micro-code to run the microcontroller.

The tool provided by atmel to upload code is avrdude.exe. A command line program, not convenient because of the many possible options.

I found a graphical interface to make it easier : avrdudess, and I recommand it.

Follow these steps :

  • Plug the programmer to your computer
  • Open AVRDUDESS :
    • choose USBasp as the Programmer, Port usb
    • in the MCU section, choose ATiny85 or click on 'Detect'
    • in the Flash section, browse your files and select cat_reppeler.hex
      • check 'Write'
  • Click on 'Program!', the code will be uploaded very quickly in the microcontroller.
  • That's it :-) !!

Step 6: Assemble the Housing

    Overview :

  1. Make a hole in the housing for the ON/OFF switch.
  2. Tap the 4 holes for the bottom cover
  3. Mount the switch.
  4. Mount the speaker using the bracket and M3 screws + nuts
  5. With the glue gun, paste the motion sensor.
  6. Plug the speaker, the sensor and the battery pack to the PCB.
  7. Glue the PCB
  8. Velcro the battery pack
  9. Screw the bottom cover

Alternative : you can use screws for wood to replace the M3 for the bottom cover. In this case don't tap the holes.

Step 7: Step 4.1 : Mount the Speaker

You need :

  1. XH-2 connectors (female)
  2. A special connector plier
  3. 4 M3-10mm screws/nuts

Connect to 2 wires to the XH connector, and solder the other end to the speaker.

Then use the bracket and the M3 screws/nuts to mount the speaker. The bottom nut is painfull to place, if you forget it never mind, it will be ok anyway and the speaker will be fixed hard enough.

Step 8: Step 4.2 : Mount the Motion Sensor

  • 2 XH-2 connectors
  • connector plier

Wire the XH connectors. Then place the motion sensor through the square hole, you need to force just a little bit to make it enter. No need to glue, it should hold itself.

Step 9: Step 4.3 : Mount the ON/OFF Switch

Make a 6mm hole at the back of the case.

Solder 2 wires on the switch and assemble a new XH-2 connector.

Screw the switch on the box.

Step 10: Step 4.4 : Mount the PCB and the Battery Holder

Wire a new XH-2 connector to the battery holder.

Use velcro to paste the battery holder inside the box.

Use glue gun to paste the PCB.

Step 11: Step 4.5 : Close the Bottom

You can tap the holes with M3 or use small wood screw.

The thin slit is made to let water pour in case it penetrates inside the box.

Step 12: The Code

I've started to develop this project with an atmega328 on an Arduino basis. Then I've wanted to reduce the size of my PCB and I've choosen an ATTiny85.

Unfortunately the ATTiny85 is not well integrated in the Arduino environment. So I had to write my code with ATMEL STUDIO.

Let me tell you basics explanations of how it works to give you an overview.

  • PB3 is configured as ouput -> it is wired to the speaker.
    PB4 as input -> it is the motion sensor input
  • An interrupt is set on PB4
  • We use timer1 to make the cat reppeling frequency
    • we know that timer1 counts at speed = 1 Mhz
    • if we reset timer1 each 67 counts we get 1Mhz/67 = 15 Khz -> OCR1C=67
    • let use PB3 as PWM with OCR1B=35 => when timer1 reaches 35, PB3 is toggled, and then toggled again when timer1 reaches OCR1C. This way we obtain a 15 Khz signal with a ratio that is about 50%.
  • To save batteries, the micro needs to be put in power-down mode

What happens when running :

  • Put the micro in power-down mode
  • A cat is coming near the motion sensor :
    • the sensor triggers PB4
    • micro wakes up
    • the interrupt routine is called :
      • PB3 is set to PWM mode with 15Khz during 10 seconds
      • stop that noise
  • Put the micro in power-down mode again ... until next trigger

To program a micro-controller is not an easy job, and the code is difficult to understand if you do not have the habit. So don't worry about that part, it is not necessary to finalize the project.


PCB Challenge

Participated in the
PCB Challenge