Arduino uno as an oscilator

Has anyone built a 20000HZ oscilator with the aeduino uno ?
I'll happy to about it/
I am planning to use it for distirbing bats to fly around my home,

20kHz is simple, but it is often illegal to disturb bats.

1 Like

…and a bit of overkill if nothing else is being explored..

Next challenge is the amplifiers and transducers.

The tone() function will do it.

But you could use an LM555 or something similar. It's cheaper.

If you haven't do so already, try generating a high frequency tone with Audacity on your computer to make sure the concept works for you.

Simple code for a test:

byte triggerOut = 19;

unsigned long currentMicros;
unsigned long nextMicros;
unsigned long duration = 25UL; // flip every 50uS = 20KHz pulse
unsigned long elapsedMicros;

void setup() {
  pinMode (triggerOut, OUTPUT);
void loop() {
  while (1) {
    currentMicros = micros();
    elapsedMicros = currentMicros - nextMicros;
    if (elapsedMicros >= duration) {
      nextMicros = nextMicros + duration;
      PINC = 0b00100000; // toggle D19 output by writing it input port.

On a 'scope, will have a little jitter from the micros()/millis() interrput.

Yeah It works, simple and straightforward work

There are several issues with this notion;
1: many bats use ultrasound to echolocate; you MAY think that its a good idea to use ultrasound to influence their behaviour. However bats are LOUD. You would need a LOT of sound to have an effect.
2: producing that would require an amplifier and transducer capable of generating sound in that region; maybe a set of supertweeters, or a (VERY EXPENSIVE) ultrasound loudspeaker.
3: A fixed sound would not be enough - it would need to vary or the bats can just ignore it.
4: You would get complaints from . . neighbours with small children (I could hear 24kHZ well into my twenties) ; or with pets (dogs have good hearing).
5; you might attract rodents
6; only certain bats echolocate.

1 Like

Yes great information related to that...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.