I'm looking for an arduino add-on to generate programmable ultrasonic transmission range of 20Khz to 35Khz (or more). I already own a HC-SR04 but not sure how/if I can change the Khz frequency via code.
Probably the best approach is to buy an AD9580 module
and inject its output into where the crystal on the HC-SR04 is currently provides the frequency
You'd need to figure out what frequency the crystal is and how to inject the signal i.e remove the crystal and inject via a suitable capacitor, I it would probably work.
There is code on the web to control the AD9850 and it has a 0Hz to 40Mhz output range in less than 1Hz steps, so I can't see how that would not be able to give you the sorts of frequencies that would be required for something that operates at 40kHz
BTW. If you don't have an oscilloscope, you may need to borrow one, it may be hard to do it without being able to measure the frequencies and voltages around the crystal
The HC-SR04 uses a MAX232 chip to boost the voltage going to the ultrasonic sender. It uses two pins of the little processor chip to send constant 40 kHz square waves that are 180° out of phase (one is HIGH while the other is LOW). There is also an ‘enable’ pin to turn the pinger on and off. See the upper-right part of the attached schematic.
Un-solder the processor and connect the Arduino in place of those three pins. Use the Output Compare Register pins of one timer (probably Timer1) and you should be able to easily cover the desired frequency range.
Note that the Murata-type transducers are mechanically resonant, and may not function efficiently at frequencies away from their specified ones.