Pest Deterrent


I have an Arduino Uno which i've connected up a PIR sensor to. At the moment it triggers an LED upon detection of my movement.

Instead I want to output ultrasonic waves in an attempt to deter rodents. The range in which this is purported to be effective is 30-70kHz and I would like to be able to emit a variation of frequencies within this range. I have seen numerous distance measuring sensors (Ultrasonic Module HC-SR04 ) which consist of a transmitter and receiver in one piece. I believe this sends 8 square waves at 40kHz only.

Can you please recommend any other transmitters suitable for the Uno that may be of use to me?


The ready-built ultrasonic sensors use Murata transducers, which are available separately.
They're designed to resonate at 40kHz, but you may get some usable output at other frequencies.

This gives info:

Many ultrasonic repellent devices do not work very well. I bought one that was tested and known to work and I was able to keep away dogs and cats. After that I tried to make one using an Arduino, but I was not able to get a lot of energy into a piezo element at 25kHz.
It is not possible to use a amplified square wave for a piezo transducer, since the piezo transducer is like a capacitor. You need a sine wave.
As far as I know, all the ultrasonic transducers are piezo transducers.

A transducer resonates at a certain frequency. So you can use a transducer with a fixed frequency of 50kHz, or a transducer for 75kHz and use that at lower frequencies.

This one uses a dynamic speaker: New URL
I didn't know that a dynamic speaker could be used for that.

Many ultrasonic repellent devices do not work very well. I bought one that was tested and known to work and I was able to keep away dogs and cats.

But not rats. Noted in previous discussions, any effect appears to be temporary.

It is not possible to use a amplified square wave for a piezo transducer, since the piezo transducer is like a capacitor. You need a sine wave.

Actually, you need a current driver. As this is inefficient, the preferred way is to resonate the piezo with a series inductor.

Is there a tranducer (arduino compatible) that can vary within the 40-80kHz range?

Is the Uno capable of powering such an output?

You need at least a driver for the transducer.
I used a driver with 12V to drive the piezo. The driver was overheated and blown, because of the capacitance of the piezo, and because I used a digital signal from the Arduino.

As Paul__B wrote, an efficient way is to use an series inductor and let the circuit resonate. But the frequency would be fixed that way.

Like others who have posted here, I have read several articles about ultrasonic pest deterrents not working. They work initially, and then they get used to them and start to ignore them. Perhaps your varying sound will be different. It might even detect a pest nearby and only act when it does.

Of course, an Arduino can do more, such as moving an actuator Perhaps you can supplement it with a stuffed cat that can turn its head by using a simple servo. It can move in response to a sensor detecting a pest. Add bedding from a real cat, for the smell, and perhaps you will have a stronger deterrent. I suppose owls are another natural predator. Though, I don't know if the rodents know by instinct to avoid those creatures, or have to learn by observation.

But before taking any of the above ideas too seriously, the only way to know if they were to work is to do some scientific experiments. Set up a web cam to video all night. Then, with a motion sensor and Arduino that logs the time when it detects a pest, you know what time to fast-forward to see the actual behavior of the pest with your deterrent.

Next I have written more on a kill approach, which goes outside of the scope of the original posting, so please feel free to ignore it. But, I really have put a good amount of thought into this issue because of an ongoing local problem with rodents. The deterrent stuff is just speculation until it is proven to work. Kill methods are a proven method of dealing with rodents.

My own rodent problem comes up every year when the local farmers plow the fields. After many tests of different types of traps, I ended up with a Victor brand electronic mouse trap for under $20 USD. It kills them with electricity. The biggest advantage over traditional traps is that they never have to be re-set. However, I do have two problems with it. One is that the light that blinks when it has fired. It only flashes very slowly, so I have to stand and watch it for a while to know if it has actually caught something. More than once I realized I had caught one only because of the smell of the decaying mouse.

The 2nd issue, is that I wish it would catch more than one mouse. There is a wind-up trap made by Tomcat that catches multiple mice alive by flipping them into a separate chamber. I would love for that to be made into an electronic kill trap. In other words, zap the mouse and then flip the dead mouse into a separate chamber so it can catch more mice.

Both of the above issues can be solved with an Arduino. I would suggest modifying and existing electronic trap and let the trap do the work it was designed to do. That will also isolate the high-voltage stuff from your Arduino. Then the Arduino can sense when the trap has a mouse by detecting when the existing LED flashes. Then the Arduino can actuate a servo to empty the trap into a container. Finally, the Arduino would need to re-set the trap's electronics. This can be done by just interrupting the battery power to the device.

-Joe Dunfee

1 Like

Thanks for sharing your experiences. There are a lot of inventive ways to tackle the issue is guess. I did think of using a servo to pull the trigger on a spray repellent.

However, I am undertaking this small project for college and my instructor is insistent that a range of frequencies (30khz-60khz) can be produced as a deterrent (regardless of what the research says regarding its apparent inefficiency for the intended purpose).

From what i've searched, its seems near impossible to find a transducer capable of producing anything in this range with a 5v output from the Arduino UNO.

Is there a piezo speaker capable of working with the tone() to achieve this range?

I think you will find that speakers can produce sounds outside of their officially printed range. However, they will do so at less (perhaps significantly less) efficiency. Though, some speakers may have circuitry (a low-pass or high-pass filter, for instance) to deliberately block some frequency ranges.

Since you are probably not concerned that mice audiophiles will be critical of your tonal reproduction, you may be able to get away with a speaker not optimized for your range.

By the way, I will mention that a local school had a problem with a very large flock of crows that decided to nest in their trees. They had recordings of birds of prey playing very loudly at various intervals. This apparently worked, though it took several days of this. I wonder if an ultrasonic cat meow (or something very roughly similar) would be a deterrent to a rodent? The Arduino can vary the pitch and perhaps attempt this.


That meow is quite a nifty idea Joe.

I did wonder what the maximum frequency the tone library functions support (with the Uno as it is). Im not sure how much of the following is true though from the tone library documentation:

"After all is said and done, because play() only accepts unsigned integers for frequency, the maximum frequency that can be produced is 65535 Hz - which, after rounding, results in a 65573.77 Hz "tone" on a 16 MHz part. Even if play accepted larger values for frequency, you couldn't achieve better than around 80KHz with the Tone library because the pin toggling is done in software. Each toggle, in software, requires AT LEAST 50+ cycles."

65.5kHz is more than sufficient as an upper bound. I just wondered if its just a matter of choosing a suitable speaker and hooking it straight up to the pin you want to output sound from?

I was surprised to see you refer to directly connecting a speaker to an Arduino output pin, so I looked it up. This one does it with a only a simple resistor to reduce current,

And, of particular interest to you, this guy does it with only a piezospeaker, but he does not list a source.

I did a quick search at the web site, and found a number of piezo speakers that were rated above 20,000 hz. Note that their filter does a poor job of sorting the frequencies. The Hz and Khz are intermingled.

Be sure to keep track of the current requirements, and don't overload your Arduino. I am very surprised the other circuits didn't use any sort of amplifying circuit that used a transistor. But, perhaps they are not necessary. I have never used a speaker with a microprocessor, so I am quite unfamiliar with the design process.