Hi, I'm trying to generate a ultrasonic tone ( > 20 khz) with that could be picked up by speakers .
I have tried just using the tone function, but I seem to be getting a lot of subharmonics also and the sound it makes is really annoying. Ideally, the sound will be inaudible for most people.
actually, I've also been buy piezo ultrasonic speaker with range 4 - 60 khz but the sound still annoying
So, (I know very little about all this) my questions are:
What is the best way to generate the ultrasonic sound with an arduino uno?
thanks if u want to help me
i can use the library toneAC with genereate tone with > 20 khz but when i want to generate random is so annoying please check my code if i hv a mistake
A square wave (or rectangle wave) contains harmonics but no subharmonics. If you are hearing low frequency noise, the piezo transducer might be over-driven so it's rattling/buzzing/resonating at a lower, more audible frequency.
Hi, I'm trying to generate a ultrasonic tone ( > 20 khz) with that could be picked up by speakers.
BE CAREFUL if you have a high-power amplifier..... i.e. You can usually fry the tweeter in a 100W speaker with a 20W constant test-tone. And, at around 20kHz, you might not hear it or it may not sound that loud.
You're probably getting subharmonics due to other interrupts interfering with the tone interrupt.
On AVR, you want to use hardware PWM with a library like TimerOne that lets you control the PWM carrier frequency. Then the hardware will generate the tone without gaps, even when interrupts like Serial and millis need CPU time.
On ARM, it's possible to set the priority level of interrupts, so if you make one higher priority, it can interrupt the others. But AVR chips don't have that feature.
You are most likely getting subtones due to Aliasing. Unless your output rate is over 40 kHz (Nyquist/Shannon sampling theorem), there is no way regardless of what interrupts you are using that you can create a 20 kHz audio waveform. Likely has nothing to do with squarewaves (which would create overtones, if sampled properly), interrupts, or anything else mentioned.