Is it possible to create a set of ultrasonics frequencies using only the Arduino? What code to be used? And how am I going to do for it to work? For this project I need to focus in the emitter side; all resources on Google are only on sensor and distance detector. I just want to use ultrasonic on other field just like for example on repelling rats. Thanks!

  • I find a shotgun or a cat works best. The latter is greener, but the former is oh so much more fun ;)
    – Majenko
    Sep 22, 2015 at 21:00

2 Answers 2


There are three parts to this project, one of which you asked:

  1. I need to generate a frequency greater than 40 khz using arduino uno?

This one is easy: Yes. You can use the tone() library call. You can specify a frequency up to 8mhz. You can call this in the void setup{} part of your code, and (if you don't want to do anything else), leave the void loop() {} empty. You might want to generate an audible tone for a short period first, to show that it is working.

  1. You need something to actually make the sound.

Depending on the frequency, most speakers won't do the trick, or will do it at a very low volume. Speakers are made to work with audible frequencies. Even then, some speakers (larger ones) are better at low frequencies; others (smaller ones) are better at higher audible frequencies. I think piezoelectric buzzers would give you a better response at higher frequencies. In any case, whatever you buy find out the frequency response for the specific part, find the frequency you intend to use along the bottom, then see what the volume (db) is for that frequency - this will give you an indication of how loud it will be. Remember that you won't be able to hear it.

The circuit is pretty trivial. Google piezo arduino

  1. Efficacy:

From https://en.wikipedia.org/wiki/Electronic_pest_control#Effects_on_rodents

Rodents adjust to the ultrasound (or any new sound) and eventually ignore it. At best, ultrasonic waves have only a partial or temporary effect on rodents. Numerous studies have rejected ultrasonic sound as a practical means of rodent control.Tests of commercial ultrasonic devices have indicated that rodents may be repelled from the immediate area of the ultrasound device for a few minutes to a few days, but they will nearly always return and resume normal activities. Other tests have shown that the degree of repellance depends on the frequency, intensity, and pre-existing condition of the rodent infestation. The intensity of such sounds must be so great that damage to humans or domestic animals would also be likely; commercial ultrasonic pest control devices do not produce sounds of such intensity.

  • 1
    You can specify a frequency up to 8mhz. - that's quite low, right? (Just kidding). I am skeptical that you would reach 8 MHz because the library toggles the pin in an ISR, and an ISR would have an overhead of a couple of microseconds. I would guess that 250 kHz to 500 kHz would be the theoretical maximum. Of course, this is a lot more than the 40 kHz that the OP wants.
    – Nick Gammon
    Sep 22, 2015 at 23:23
  • You could and should maybe use a lot of transistors, and that might be whit you circuit and set the MHz overload higher then expected.
    – Michael
    Sep 23, 2015 at 5:25
  • What library on arduino should i use?
    – user13535
    Sep 24, 2015 at 15:52
  • You don't need a library. Tone() is built into the core. There are some example sketches that come with the environment - just click File -> Digital -> toneMultiple. Note that this example plays different tones on different speakers (connected to different pins); for your code, put one 8-ohm speaker between pin 6 and ground, then change the first parameter of the tone() to 6 for all of them. Sep 24, 2015 at 20:37
  • Is it possible to create an ultrasonic frequency by simply using it? And can i used 45678Hz as my desired frequency?
    – user13535
    Sep 28, 2015 at 15:20

Another answer to generating ultrasonic frequencies is to ditch the Arduino altogether - use a 555 timer circuit (for lower range frequency, probably up to low mHz), or a resonator. A quick search found a 2.4 gHz resonator for less than an Arduino. 555 timers can be tuned, resonators cannot. I think you could build a 555 square-wave generator for about $1-$2.

  • Hi, how can I strengthen the ultrasonic frequency produced by the arduino ic's?
    – user13535
    Sep 28, 2015 at 13:45
  • This should really be a separate question, but: louder sounds can be made with higher voltage (up to the voltage supported by your piezo, or it will blow), using a higher voltage piezo, or one with a frequency response more suited to your frequency. If you want to use a voltage higher than the Arduino can handle, use a transistor as a switch (google). Sep 29, 2015 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.